Convert to GKE; add Honeycomb.

This commit is contained in:
Joshua Wise 2020-03-07 23:08:04 -05:00
parent 772c9b405b
commit 4b94455678
4 changed files with 31 additions and 2 deletions

8
Dockerfile.cloudrun Normal file
View file

@ -0,0 +1,8 @@
FROM python:3.6-alpine
RUN apk add --update build-base libffi-dev
RUN apk add --update postgresql-dev
RUN pip install gunicorn gevent
ADD . /code
WORKDIR /code
RUN pip install -r requirements.txt
CMD exec gunicorn --bind :$PORT -k gevent --workers 2 weather:app

9
cloudbuild.yaml Normal file
View file

@ -0,0 +1,9 @@
steps:
- name: 'gcr.io/cloud-builders/docker'
args:
- build
- "--tag=gcr.io/pebble-rebirth/timeline-sync:$TAG_NAME"
- "--file=./Dockerfile.cloudrun"
- .
images:
- "gcr.io/pebble-rebirth/timeline-sync"

View file

@ -9,3 +9,4 @@ MarkupSafe==1.0
requests==2.19.1
urllib3==1.23
Werkzeug==0.14.1
honeycomb-beeline==2.11.4

View file

@ -2,14 +2,21 @@ import datetime
import os
import time
import beeline
from beeline.middleware.flask import HoneyMiddleware
from beeline.patch import requests
import requests
from flask import Flask, request, jsonify, abort
from werkzeug.exceptions import HTTPException
from werkzeug.routing import FloatConverter
app = Flask(__name__)
if config['HONEYCOMB_KEY']:
beeline.init(writekey=config['HONEYCOMB_KEY'], dataset='rws', service_name='auth')
HoneyMiddleware(app, db_events = True)
domain_root = os.environ['DOMAIN_ROOT']
auth_internal = os.environ['REBBLE_AUTH_URL_INT']
ibm_root = os.environ['IBM_API_ROOT']
http_protocol = os.environ.get('HTTP_PROTOCOL', 'https')
@ -40,14 +47,18 @@ def heartbeat():
def geocode(latitude, longitude):
if not request.args.get('access_token'):
abort(401)
user_req = requests.get(f"{http_protocol}://auth.{domain_root}/api/v1/me",
user_req = requests.get(f"{auth_internal}/api/v1/me",
headers={'Authorization': f"Bearer {request.args['access_token']}"})
user_req.raise_for_status()
if not user_req.json()['is_subscribed']:
raise HTTPPaymentRequired()
beeline.add_context_field("user", user_req.json()['id'])
units = request.args.get('units', 'h')
language = request.args.get('language', 'en-US')
beeline.add_context_field("weather.language", language)
beeline.add_context_field("weather.units", units)
forecast_req = requests.get(f"{ibm_root}/geocode/{latitude}/{longitude}/forecast/daily/7day.json?language={language}&units={units}")
forecast_req.raise_for_status()