Convert to GKE; add Honeycomb.
This commit is contained in:
parent
772c9b405b
commit
4b94455678
4 changed files with 31 additions and 2 deletions
8
Dockerfile.cloudrun
Normal file
8
Dockerfile.cloudrun
Normal 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
9
cloudbuild.yaml
Normal 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"
|
|
@ -9,3 +9,4 @@ MarkupSafe==1.0
|
||||||
requests==2.19.1
|
requests==2.19.1
|
||||||
urllib3==1.23
|
urllib3==1.23
|
||||||
Werkzeug==0.14.1
|
Werkzeug==0.14.1
|
||||||
|
honeycomb-beeline==2.11.4
|
||||||
|
|
|
@ -2,14 +2,21 @@ import datetime
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
import beeline
|
||||||
|
from beeline.middleware.flask import HoneyMiddleware
|
||||||
|
from beeline.patch import requests
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from flask import Flask, request, jsonify, abort
|
from flask import Flask, request, jsonify, abort
|
||||||
from werkzeug.exceptions import HTTPException
|
from werkzeug.exceptions import HTTPException
|
||||||
from werkzeug.routing import FloatConverter
|
from werkzeug.routing import FloatConverter
|
||||||
|
|
||||||
app = Flask(__name__)
|
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']
|
ibm_root = os.environ['IBM_API_ROOT']
|
||||||
http_protocol = os.environ.get('HTTP_PROTOCOL', 'https')
|
http_protocol = os.environ.get('HTTP_PROTOCOL', 'https')
|
||||||
|
|
||||||
|
@ -40,15 +47,19 @@ def heartbeat():
|
||||||
def geocode(latitude, longitude):
|
def geocode(latitude, longitude):
|
||||||
if not request.args.get('access_token'):
|
if not request.args.get('access_token'):
|
||||||
abort(401)
|
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']}"})
|
headers={'Authorization': f"Bearer {request.args['access_token']}"})
|
||||||
user_req.raise_for_status()
|
user_req.raise_for_status()
|
||||||
if not user_req.json()['is_subscribed']:
|
if not user_req.json()['is_subscribed']:
|
||||||
raise HTTPPaymentRequired()
|
raise HTTPPaymentRequired()
|
||||||
|
beeline.add_context_field("user", user_req.json()['id'])
|
||||||
|
|
||||||
units = request.args.get('units', 'h')
|
units = request.args.get('units', 'h')
|
||||||
language = request.args.get('language', 'en-US')
|
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 = requests.get(f"{ibm_root}/geocode/{latitude}/{longitude}/forecast/daily/7day.json?language={language}&units={units}")
|
||||||
forecast_req.raise_for_status()
|
forecast_req.raise_for_status()
|
||||||
forecast = forecast_req.json()
|
forecast = forecast_req.json()
|
||||||
|
|
Reference in a new issue