diff options
author | Kelley Spoon <kelley.spoon@linaro.org> | 2018-03-05 09:21:58 -0600 |
---|---|---|
committer | Kelley Spoon <kelley.spoon@linaro.org> | 2018-03-05 09:21:58 -0600 |
commit | 9647b8d7c3c20045f07858faa5eccd967b52cf03 (patch) | |
tree | c59863000d6ba637be0090cece5a4fcc069d3caa | |
parent | cf6d368bae3059f9e6ba93c7294e15f456f91167 (diff) |
Dockerfile: RFC for dockerizing LLPcompose
Creates a docker image for use in a docker-compose
deployment based on the python-2.7 baseimage.
Instead of looking for "header_override.html" in
the parent directory, it changes to look in the
../extra_templates directory.
Change-Id: I3e65fc5c41ba1ad12881061352be0567f8e49e6b
-rw-r--r-- | Dockerfile.python | 28 | ||||
-rw-r--r-- | docker_init.sh | 26 | ||||
-rw-r--r-- | settings.py | 3 | ||||
-rw-r--r-- | settings_production.py | 5 |
4 files changed, 61 insertions, 1 deletions
diff --git a/Dockerfile.python b/Dockerfile.python new file mode 100644 index 0000000..815f3f1 --- /dev/null +++ b/Dockerfile.python @@ -0,0 +1,28 @@ +# There is no base django image and instead they +# suggest using the python base image. We're +# going with the Debian Stretch base python 2.x +# option for now as it's closest to what we +# currently run +FROM python:2.7 + +ENV GUNICORN_WORKERS 4 +ENV WSGI_SCRIPT ${WSGI:-wsgi_production:application} +ENV LLP_PORT ${LLP_PORT:-8000} +ENV SITE_NAME ${SITE_NAME:-Protected Downloads} +ENV DJANGO_SETTINGS_MODULE ${DJANGO_SETTINGS_MODULE:-settings_production} + +EXPOSE 8000 +VOLUME /srv + +ADD ./requirements.txt /tmp/requirements.txt +ADD docker_init.sh /bin/docker_init.sh +RUN chmod 755 /bin/docker_init.sh + +# install reqs +RUN pip install -r /tmp/requirements.txt +# add this manually for the docker environment +RUN pip install gunicorn + +WORKDIR /srv/project + +CMD /bin/docker_init.sh diff --git a/docker_init.sh b/docker_init.sh new file mode 100644 index 0000000..45dac22 --- /dev/null +++ b/docker_init.sh @@ -0,0 +1,26 @@ +#!/bin/sh + +# This script is meant to be run inside of a docker +# container. It takes care of some housekeeping +# commands before the app is started by gunicorn +# and set to run on port 8000. + +cd /srv/project + +./manage.py migrate --noinput +./manage.py collectstatic --noinput + +# These are set by the Dockerfile or at container run time +# GUNICORN_WORKERS +# WSGI_SCRIPT +# DJANGO_SETTINGS_MODULE +# LLP_PORT + +# These should all be present as environment variables from +# the Dockerfile. +gunicorn -w$GUNICORN_WORKERS \ + --pythonpath /srv/project \ + -e DJANGO_SETTINGS_MODULE="$DJANGO_SETTINGS_MODULE" \ + -e SITE_NAME="$SITE_NAME" \ + -b 0.0.0.0:$LLP_PORT \ + $WSGI_SCRIPT diff --git a/settings.py b/settings.py index 8f71885..c1c6192 100644 --- a/settings.py +++ b/settings.py @@ -6,6 +6,9 @@ from version import VERSION DEBUG = True +USE_X_FORWARDED_HOST=True +SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') + PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__)) ROOT_DIR = os.path.split(PROJECT_ROOT)[-1] ROOT_PATH = os.path.dirname(os.path.abspath(__file__)) diff --git a/settings_production.py b/settings_production.py index 8129db1..d0702bc 100644 --- a/settings_production.py +++ b/settings_production.py @@ -27,7 +27,10 @@ for p in SERVED_PATHS + [UPLOAD_PATH]: # allow local override of default page styling if os.path.exists(os.path.join(DEPLOYMENT_DIR, 'header_override.html')): BASE_PAGE = 'header_override.html' - TEMPLATE_DIRS += (DEPLOYMENT_DIR,) + #TEMPLATE_DIRS += (DEPLOYMENT_DIR,) + for t in TEMPLATES: + if t.has_key("DIRS"): + t["DIRS"].append( DEPLOYMENT_DIR ) # allow site specific overrides for secrets if os.path.exists(os.path.join(DEPLOYMENT_DIR, 'secrets.py')): |