Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP for dockerizing #35

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM python:3.6-slim-buster

ENV DEBIAN_FRONTEND=noninteractive \
PYTHONFAULTHANDLER=1 \
PYTHONUNBUFFERED=1 \
PYTHONHASHSEED=random \
PIP_NO_CACHE_DIR=false \
PIP_DISABLE_PIP_VERSION_CHECK=false

RUN apt update \
&& apt install --assume-yes --no-install-recommends \
libpq-dev

RUN pip install --upgrade pipenv

WORKDIR /app

COPY ./Pipfile /app
COPY ./Pipfile.lock /app

RUN pipenv install --system

COPY . /app
4 changes: 2 additions & 2 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ celery = "*"
dj-database-url = "*"
django = "*"
gunicorn = "*"
"psycopg2" = "*"
"psycopg2-binary" = "*"
requests = "*"
whitenoise = "*"
python-social-auth = "*"
Expand All @@ -18,7 +18,7 @@ vcrpy = "*"
pyyaml = "==4.2b4"
redis = "*"
iptools = "*"
pyjq = "*"
# pyjq = "*"
open-humans-api = "*"

[dev-packages]
Expand Down
1,089 changes: 830 additions & 259 deletions Pipfile.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion datauploader/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@

@app.task(bind=True)
def debug_task(self):
print('Request: {0!r}'.format(self.request))
print('Request: {0!r}'.format(self.request))
51 changes: 51 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
version: '3.6'

services:
web:
build: .
command: gunicorn fitbit.wsgi --log-file=-
container_name: ${APP_NAME}-web
depends_on:
- db
- redis
env_file: .env
image: ${APP_NAME}-web
ports:
- 127.0.0.1:5000:5000
restart: "no"
volumes:
- .:/app:delegated

worker:
build: .
command: celery -A datauploader worker --concurrency 1
container_name: ${APP_NAME}-worker
depends_on:
- db
- redis
env_file: .env
image: ${APP_NAME}-worker
restart: "no"
volumes:
- .:/app:delegated

db:
container_name: ${APP_NAME}-db
environment:
POSTGRES_DB: ${APP_NAME}
POSTGRES_USER: ${DB_USERNAME}
POSTGRES_PASSWORD: ${DB_PASSWORD}
PGDATA: /postgres/data
image: postgres:latest
restart: "no"
volumes:
- data:/var/lib/postgresql

redis:
container_name: ${APP_NAME}-redis
image: redis:7-alpine
restart: "no"

volumes:
data:
driver: local
14 changes: 9 additions & 5 deletions env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,23 @@
# When this webapp is run with foreman, variables defined in `.env` are
# loaded as environment variables.

# The application name, makes the docker-compose.yml a bit simpler since it
# can reference the name
APP_NAME=oh-fitbit-integration

# Postgres username and password, used by docker-compose.yml to setup postgres
DB_USERNAME=oh-fitbit-integration
DB_PASSWORD= # a randomly generated password only used for local development

# Django secret. Long and random, e.g.:
# http://www.howtogeek.com/howto/30184/10-ways-to-generate-a-random-password-from-the-command-line/
SECRET_KEY=''

# DEBUG is True by default. Set to 'False' to turn it off (e.g. in production).
# DEBUG='False'

# Get messages to output when running with Foreman. Solution from:
# https://elweb.co/how-to-fix-foremans-missing-output-issue-on-python-projects/
PYTHONUNBUFFERED=true

# Redis configuration, default port is 6379
REDIS_URL='redis://'
REDIS_URL='redis://oh-fitbit-integration-redis:6379'

# Open Humans OAuth2 project settings.
# OH_ACTIVITY_PAGE='https://www.openhumans.org/activity/my-test-project/'
Expand Down
27 changes: 13 additions & 14 deletions fitbit/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,19 @@
FITBIT_CLIENT_ID=os.getenv('FITBIT_CLIENT_ID')
FITBIT_CLIENT_SECRET=os.getenv('FITBIT_CLIENT_SECRET')

if REMOTE is True:
from urllib.parse import urlparse
url_object = urlparse(os.getenv('REDIS_URL'))
logger.info('Connecting to redis at %s:%s',
url_object.hostname,
url_object.port)
RespectfulRequester.configure(
redis={
"host": url_object.hostname,
"port": url_object.port,
"password": url_object.password,
"database": 0
},
safety_threshold=5)
from urllib.parse import urlparse
url_object = urlparse(os.getenv('REDIS_URL'))
logger.info('Connecting to redis at %s:%s',
url_object.hostname,
url_object.port)
RespectfulRequester.configure(
redis={
"host": url_object.hostname,
"port": url_object.port,
"password": url_object.password,
"database": 0
},
safety_threshold=5)

# Requests Respectful (rate limiting, waiting)
rr = RespectfulRequester()
Expand Down