-
Notifications
You must be signed in to change notification settings - Fork 527
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Dockerfile, docker-compose.yml, S3 uploaded media settings (confi…
…gurable via the environment), Docker instructions, and a .travis.yml to build/test the Docker image.
- Loading branch information
1 parent
6eefd5f
commit 6652c42
Showing
14 changed files
with
249 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Dockerfile | ||
docker-compose.yml | ||
Procfile | ||
Vagrantfile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
sudo: required | ||
services: | ||
- docker | ||
|
||
env: | ||
global: | ||
- GREP_TIMEOUT=360 | ||
|
||
before_install: | ||
- sudo apt-get update | ||
- sudo apt-get install -qy -o Dpkg::Options::="--force-confold" docker-engine coreutils | ||
|
||
script: | ||
# Bring up the postgres, redis, and app containers | ||
- docker-compose up --build -d | ||
|
||
- timeout $GREP_TIMEOUT grep -m 1 'Running migrations' <(docker-compose logs --follow app 2>&1) | ||
- timeout $GREP_TIMEOUT grep -m 1 'spawned uWSGI http 1' <(docker-compose logs --follow app 2>&1) | ||
- docker-compose run app /venv/bin/python /code/manage.py check | ||
|
||
after_script: | ||
- docker-compose logs | ||
- docker images |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
FROM python:3.5-alpine | ||
|
||
ADD requirements/ /requirements/ | ||
RUN set -ex \ | ||
&& apk add --no-cache --virtual .build-deps \ | ||
gcc \ | ||
g++ \ | ||
make \ | ||
libc-dev \ | ||
musl-dev \ | ||
linux-headers \ | ||
pcre-dev \ | ||
postgresql-dev \ | ||
libjpeg-turbo-dev \ | ||
&& pyvenv /venv \ | ||
&& /venv/bin/pip install -U pip \ | ||
&& LIBRARY_PATH=/lib:/usr/lib /bin/sh -c "/venv/bin/pip install -r /requirements/production.txt" \ | ||
&& runDeps="$( \ | ||
scanelf --needed --nobanner --recursive /venv \ | ||
| awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }' \ | ||
| sort -u \ | ||
| xargs -r apk info --installed \ | ||
| sort -u \ | ||
)" \ | ||
&& apk add --virtual .python-rundeps $runDeps \ | ||
&& apk del .build-deps | ||
RUN apk add --no-cache postgresql-client | ||
RUN mkdir /code/ | ||
WORKDIR /code/ | ||
ADD . /code/ | ||
EXPOSE 8000 | ||
|
||
# Add custom environment variables needed by Django or your settings file here: | ||
ENV DJANGO_SETTINGS_MODULE=bakerydemo.settings.production DJANGO_DEBUG=off | ||
|
||
# uWSGI configuration (customize as needed): | ||
ENV UWSGI_VIRTUALENV=/venv UWSGI_WSGI_FILE=bakerydemo/wsgi_production.py UWSGI_HTTP=:8000 UWSGI_MASTER=1 UWSGI_WORKERS=2 UWSGI_THREADS=8 UWSGI_UID=1000 UWSGI_GID=2000 | ||
|
||
# Call collectstatic with dummy environment variables: | ||
RUN DATABASE_URL=postgres://none REDIS_URL=none /venv/bin/python manage.py collectstatic --noinput | ||
|
||
# start uWSGI, using a wrapper script to allow us to easily add more commands to container startup: | ||
ENTRYPOINT ["/code/docker-entrypoint.sh"] | ||
CMD ["/venv/bin/uwsgi", "--http-auto-chunked", "--http-keepalive"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
release: yes "yes" | python manage.py migrate | ||
web: gunicorn bakerydemo.heroku_wsgi --log-file - | ||
web: uwsgi --http-socket=:$PORT --master --workers=2 --threads=8 --die-on-term --wsgi-file=bakerydemo/wsgi_production.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import os | ||
import dj_database_url | ||
import random | ||
import string | ||
|
||
from .base import * | ||
|
||
DEBUG = os.getenv('DJANGO_DEBUG', 'off') == 'on' | ||
|
||
# DJANGO_SECRET_KEY *should* be specified in the environment. If it's not, generate an ephemeral key. | ||
if 'DJANGO_SECRET_KEY' in os.environ: | ||
SECRET_KEY = os.environ['DJANGO_SECRET_KEY'] | ||
else: | ||
# Use if/else rather than a default value to avoid calculating this if we don't need it | ||
print("WARNING: DJANGO_SECRET_KEY not found in os.environ. Generating ephemeral SECRET_KEY.") | ||
SECRET_KEY = ''.join([random.SystemRandom().choice(string.printable) for i in range(50)]) | ||
|
||
# Make sure Django can detect a secure connection properly on Heroku: | ||
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') | ||
|
||
# Redirect all requests to HTTPS | ||
SECURE_SSL_REDIRECT = os.getenv('DJANGO_SECURE_SSL_REDIRECT', 'off') == 'on' | ||
|
||
# Accept all hostnames, since we don't know in advance which hostname will be used for any given Heroku instance. | ||
# IMPORTANT: Set this to a real hostname when using this in production! | ||
# See https://docs.djangoproject.com/en/1.10/ref/settings/#allowed-hosts | ||
ALLOWED_HOSTS = os.getenv('DJANGO_ALLOWED_HOSTS', '*').split(';') | ||
|
||
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' | ||
|
||
# BASE_URL required for notification emails | ||
BASE_URL = 'http://localhost:8000' | ||
|
||
db_from_env = dj_database_url.config(conn_max_age=500) | ||
DATABASES['default'].update(db_from_env) | ||
|
||
# Simplified static file serving. | ||
# https://warehouse.python.org/project/whitenoise/ | ||
|
||
MIDDLEWARE.append('whitenoise.middleware.WhiteNoiseMiddleware') | ||
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' | ||
|
||
if 'AWS_STORAGE_BUCKET_NAME' in os.environ: | ||
AWS_STORAGE_BUCKET_NAME = os.getenv('AWS_STORAGE_BUCKET_NAME') | ||
AWS_ACCESS_KEY_ID = os.getenv('AWS_ACCESS_KEY_ID', '') | ||
AWS_SECRET_ACCESS_KEY = os.getenv('AWS_SECRET_ACCESS_KEY', '') | ||
AWS_S3_CUSTOM_DOMAIN = '%s.s3.amazonaws.com' % AWS_STORAGE_BUCKET_NAME | ||
AWS_AUTO_CREATE_BUCKET = True | ||
|
||
INSTALLED_APPS.append('storages') | ||
MEDIA_URL = "https://%s/" % AWS_S3_CUSTOM_DOMAIN | ||
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage' | ||
|
||
LOGGING = { | ||
'version': 1, | ||
'disable_existing_loggers': False, | ||
'handlers': { | ||
'console': { | ||
'class': 'logging.StreamHandler', | ||
}, | ||
}, | ||
'loggers': { | ||
'django': { | ||
'handlers': ['console'], | ||
'level': os.getenv('DJANGO_LOG_LEVEL', 'INFO'), | ||
}, | ||
}, | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
version: '2' | ||
|
||
services: | ||
db: | ||
environment: | ||
POSTGRES_DB: app_db | ||
POSTGRES_USER: app_user | ||
POSTGRES_PASSWORD: changeme | ||
restart: always | ||
image: postgres:9.6 | ||
expose: | ||
- "5432" | ||
redis: | ||
restart: always | ||
image: redis:3.0 | ||
expose: | ||
- "6379" | ||
app: | ||
environment: | ||
DJANGO_SECRET_KEY: changeme | ||
DATABASE_URL: postgres://app_user:changeme@db/app_db | ||
REDIS_URL: redis://redis | ||
build: | ||
context: . | ||
dockerfile: ./Dockerfile | ||
links: | ||
- db:db | ||
- redis:redis | ||
ports: | ||
- "8000:8000" | ||
depends_on: | ||
- db | ||
- redis |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/bin/sh | ||
set -e | ||
|
||
until psql $DATABASE_URL -c '\l'; do | ||
>&2 echo "Postgres is unavailable - sleeping" | ||
sleep 1 | ||
done | ||
|
||
>&2 echo "Postgres is up - continuing" | ||
|
||
if [ "$1" = '/venv/bin/uwsgi' ]; then | ||
/venv/bin/python manage.py migrate --noinput | ||
fi | ||
|
||
if [ "x$DJANGO_LOAD_INITIAL_DATA" = 'xon' ]; then | ||
/venv/bin/python manage.py load_initial_data | ||
fi | ||
|
||
exec "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
-r requirements/heroku.txt | ||
-r requirements/production.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
-r base.txt | ||
# Additional dependencies for Heroku deployment | ||
dj-database-url==0.4.1 | ||
gunicorn==19.6.0 | ||
uwsgi==2.0.14 | ||
psycopg2==2.6.2 | ||
whitenoise==3.2.2 | ||
boto==2.45.0 | ||
django-storages==1.5.2 |