From af0d7387318219f759ca0148ac1f62d91d00cf1d Mon Sep 17 00:00:00 2001 From: mike wakerly Date: Sat, 18 Apr 2020 14:29:09 -0400 Subject: [PATCH 1/2] Add postgres driver --- Dockerfile | 4 ++-- Pipfile | 1 + Pipfile.lock | 33 ++++++++++++++++++++++++++------- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index 58fbb7331..3f7878a00 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,9 +19,9 @@ RUN apk update && \ pip install pipenv ADD Pipfile Pipfile.lock ./ -RUN apk add --no-cache mariadb-connector-c-dev && \ +RUN apk add --no-cache mariadb-connector-c-dev libpq && \ apk add --no-cache --virtual _build-deps \ - build-base mariadb-dev libjpeg-turbo-dev zlib-dev py-gevent libffi-dev && \ + build-base mariadb-dev postgresql-dev libjpeg-turbo-dev zlib-dev py-gevent libffi-dev && \ pipenv install --deploy --system && \ apk del _build-deps diff --git a/Pipfile b/Pipfile index f243691d9..db2dd6256 100644 --- a/Pipfile +++ b/Pipfile @@ -46,6 +46,7 @@ future = "*" addict = "*" kegbot-api = "*" gevent = "*" +psycopg2 = "*" [scripts] kegbot = "python bin/kegbot" diff --git a/Pipfile.lock b/Pipfile.lock index ed2626094..faff93f1d 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "83138133ee040bf21e029d428be3a8511246f711e002dc8a58b2dbb12139199d" + "sha256": "5cc77b526346ec2f2deeb8240b07c502041875de90bca1cd7185b79034b8bc91" }, "pipfile-spec": 6, "requires": { @@ -354,6 +354,25 @@ "index": "pypi", "version": "==3.11.3" }, + "psycopg2": { + "hashes": [ + "sha256:132efc7ee46a763e68a815f4d26223d9c679953cd190f1f218187cb60decf535", + "sha256:2327bf42c1744a434ed8ed0bbaa9168cac7ee5a22a9001f6fc85c33b8a4a14b7", + "sha256:27c633f2d5db0fc27b51f1b08f410715b59fa3802987aec91aeb8f562724e95c", + "sha256:2c0afb40cfb4d53487ee2ebe128649028c9a78d2476d14a67781e45dc287f080", + "sha256:2df2bf1b87305bd95eb3ac666ee1f00a9c83d10927b8144e8e39644218f4cf81", + "sha256:440a3ea2c955e89321a138eb7582aa1d22fe286c7d65e26a2c5411af0a88ae72", + "sha256:6a471d4d2a6f14c97a882e8d3124869bc623f3df6177eefe02994ea41fd45b52", + "sha256:6b306dae53ec7f4f67a10942cf8ac85de930ea90e9903e2df4001f69b7833f7e", + "sha256:a0984ff49e176062fcdc8a5a2a670c9bb1704a2f69548bce8f8a7bad41c661bf", + "sha256:ac5b23d0199c012ad91ed1bbb971b7666da651c6371529b1be8cbe2a7bf3c3a9", + "sha256:acf56d564e443e3dea152efe972b1434058244298a94348fc518d6dd6a9fb0bb", + "sha256:d3b29d717d39d3580efd760a9a46a7418408acebbb784717c90d708c9ed5f055", + "sha256:f7d46240f7a1ae1dd95aab38bd74f7428d46531f69219954266d669da60c0818" + ], + "index": "pypi", + "version": "==2.8.5" + }, "pysocks": { "hashes": [ "sha256:08e69f092cc6dbe92a0fdd16eeb9b9ffbc13cadfe5ca4c7bd92ffb078b293299", @@ -442,10 +461,10 @@ }, "urllib3": { "hashes": [ - "sha256:2f3db8b19923a873b3e5256dc9c2dedfa883e33d87c690d9c7913e1f40673cdc", - "sha256:87716c2d2a7121198ebcb7ce7cccf6ce5e9ba539041cfbaeecfb641dc0bf6acc" + "sha256:3018294ebefce6572a474f0604c2021e33b3fd8006ecd11d62107a5d2a963527", + "sha256:88206b0eb87e6d677d424843ac5209e3fb9d0190d0ee169599165ec25e9d9115" ], - "version": "==1.25.8" + "version": "==1.25.9" }, "vine": { "hashes": [ @@ -892,10 +911,10 @@ }, "urllib3": { "hashes": [ - "sha256:2f3db8b19923a873b3e5256dc9c2dedfa883e33d87c690d9c7913e1f40673cdc", - "sha256:87716c2d2a7121198ebcb7ce7cccf6ce5e9ba539041cfbaeecfb641dc0bf6acc" + "sha256:3018294ebefce6572a474f0604c2021e33b3fd8006ecd11d62107a5d2a963527", + "sha256:88206b0eb87e6d677d424843ac5209e3fb9d0190d0ee169599165ec25e9d9115" ], - "version": "==1.25.8" + "version": "==1.25.9" }, "vcrpy": { "hashes": [ From 26b7ffa72904da71741c6d0631955b6c5fe00966 Mon Sep 17 00:00:00 2001 From: mike wakerly Date: Sat, 18 Apr 2020 14:24:44 -0400 Subject: [PATCH 2/2] Heroku compatibility hacks. --- pykeg/config.py | 4 ++-- pykeg/web/gunicorn_conf.py | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/pykeg/config.py b/pykeg/config.py index 8490a9de3..85d243056 100644 --- a/pykeg/config.py +++ b/pykeg/config.py @@ -102,5 +102,5 @@ def is_setup(): Setting('KEGBOT_IN_DOCKER', False, typefn=boolstr) Setting('KEGBOT_SECRET_KEY', 'not-configured') Setting('KEGBOT_SETUP_ENABLED', False, typefn=boolstr) -Setting('KEGBOT_DATABASE_URL', 'mysql://root@localhost/kegbot') -Setting('KEGBOT_REDIS_URL', 'redis://localhost:6379/0') +Setting('KEGBOT_DATABASE_URL', os.getenv('DATABASE_URL', 'mysql://root@localhost/kegbot')) +Setting('KEGBOT_REDIS_URL', os.getenv('REDIS_URL', 'redis://localhost:6379/0')) diff --git a/pykeg/web/gunicorn_conf.py b/pykeg/web/gunicorn_conf.py index dc3ea9d6a..b2959e3bb 100644 --- a/pykeg/web/gunicorn_conf.py +++ b/pykeg/web/gunicorn_conf.py @@ -1,6 +1,7 @@ import multiprocessing import pkg_resources import sys +import os BANNER = """ ██╗ ██╗███████╗ ██████╗ ██████╗ ██████╗ ████████╗ @@ -17,7 +18,12 @@ def get_version(): except pkg_resources.DistributionNotFound: return '0.0.0' -bind = "0.0.0.0:8000" +if os.getenv('KEGBOT_IN_HEROKU') and os.getenv('PORT'): + # Necessary on Heroku, which doesn't respect EXPOSE :-\ + bind = "0.0.0.0:{}".format(int(os.getenv('PORT'))) +else: + bind = "0.0.0.0:8000" + worker_class = "gevent" workers = multiprocessing.cpu_count() * 2 + 1