Mais conteúdo relacionado
Semelhante a Running Django on Docker: a workflow and code (20)
Running Django on Docker: a workflow and code
- 9. Base OS (Debian bootstrap)
App dependencies
(Python, libs)
Built application
Transient runtime
Immutable
External
Storage
- 20. RUN echo "__version__ = '`git describe`'"
> myapp/__version__.py
RUN ./invoke.sh install
ENTRYPOINT ["./invoke.sh"]
EXPOSE 8000
- 21. invoke.sh
#!/bin/sh
# default parameters
: ${APP_USER:=app}
: ${WEB_CONCURRENCY:=1}
export WEB_CONCURRENCY
if [ "x$(whoami)" != "x$APP_USER" ]; then
# ensure we own our storage
chown -R "$APP_USER" /static /storage
# Call back into ourselves as the app user
exec sudo -sE -u "$APP_USER" -- "$0" "$@"
else
- 22. else
. ./startenv
case "$1" in
deploy)
shift 1 # consume command from $@
./manage.py migrate "$@"
;;
serve)
gunicorn -w "$WEB_CONCURRENCY"
-b 0.0.0.0:8000 "${APP}.wsgi:applicatio
;;
*)
./manage.py "$@"
;;
esac
fi
- 25. # Logging is complex
LOGGING['handlers']['logstash'] = {
'level': 'DEBUG' if DEBUG else 'INFO',
'class': 'logging.handlers.SysLogHandler',
'address': (os.environ['SYSLOG_SERVER'],
int(os.environ['SYSLOG_PORT']))
'socktype': socket.SOCK_STREAM
if os.environ['SYSLOG_PROTO'] ==
else socket.SOCK_DGRAM,
}
- 26. # Trust our nginx server
USE_X_FORWARDED_HOST = True
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO',
MY_SITE_DOMAIN = os.environ.get('SITE_DOMAIN')
if MY_SITE_DOMAIN:
ALLOWED_HOSTS = (MY_SITE_DOMAIN,)
- 30. docker run
-p 8000:8000
-e DB_DEFAULT_URL=postgres://user:pass@db3:5432/mya
-e SITE_DOMAIN=myapp-staging.company.com
-e SITE_PROTO=https
-e ENVIRONMENT=staging
-e ELASTICSEARCH_URLS=http://elastic-1:9200/myapp
-v /mnt/docker-storage/myapp:/storage
-h WHY_ARE_YOU_STILL_READING_THIS
myapp
serve