Commit a08f7ae8 authored by BERJON Matthieu's avatar BERJON Matthieu

Update of the Django container configuration

I updated the container in order to correct several bugs regarding nginx
and writing permissions. I added the use of supervisor and gunicorn.
I'm using as well Debian Stretch because Jessie doesn't have up to date
packages for django and gunicorn.
Signed-off-by: BERJON Matthieu's avatarMatthieu Berjon <matthieu.berjon@inria.fr>

Add of production config

I added a production config file for the Django app and updated the wsgi
configuration to run in production.
Signed-off-by: BERJON Matthieu's avatarMatthieu Berjon <matthieu.berjon@inria.fr>
parent d6bf4e5e
FROM debian:stretch
# install system packages
# Installation of gunicorn through pip because the debian package
# python3-gunicorn doesn't install any binary
RUN apt-get update && apt-get install -y \
mysql-server default-libmysqlclient-dev \
nginx-light zip \
python3 python3-dev python3-pip python3-django python3-mysqldb python-mysqldb \
python3-django-environ
python3-django-environ supervisor && pip3 install gunicorn
COPY . /opt/allgo
COPY init /dk/container_init
RUN bash /opt/allgo/setup/dk/container_init
RUN patch /etc/nginx/nginx.conf < /opt/allgo/setup/dk/nginx.patch
RUN rm /etc/nginx/sites-enabled/default && \
rm /etc/supervisor/supervisord.conf && \
ln -s "/opt/allgo/setup/dk/allgo.conf" /etc/nginx/sites-enabled/allgo && \
ln -s "/opt/allgo/setup/dk/run-allgo" /usr/local/bin && \
ln -s "/opt/allgo/setup/dk/supervisord.conf" /etc/supervisor/ && \
bash /opt/allgo/setup/dk/container_init
WORKDIR /opt/allgo
LABEL dk.migrate_always=1
# ENTRYPOINT /bin/bash /opt/allgo/setup/dk/run-allgo
CMD run-allgo
import logging
from .base import * # noqa
from .base import env
# GENERAL
# ------------------------------------------------------------------------------
SECRET_KEY = env('DJANGO_SECRET_KEY')
ALLOWED_HOSTS = env.list('DJANGO_ALLOWED_HOSTS', default=['localhost'])
# DATABASES
# ------------------------------------------------------------------------------
DATABASES['default'] = env.db('DATABASE_URL') # noqa F405
DATABASES['default']['ATOMIC_REQUESTS'] = True # noqa F405
DATABASES['default']['CONN_MAX_AGE'] = env.int('CONN_MAX_AGE', default=60) # noqa F405
# Gunicorn
# ------------------------------------------------------------------------------
INSTALLED_APPS += ['gunicorn'] # noqa F405
......@@ -6,7 +6,7 @@ from django.core.wsgi import get_wsgi_application
app_path = os.path.abspath(os.path.join(
os.path.dirname(os.path.abspath(__file__)), os.pardir))
sys.path.append(os.path.join(app_path, 'django'))
sys.path.append(os.path.join(app_path, 'allgo'))
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings.production')
......
#!/bin/sh
set -e -x
# mkdir /vol && chown allgo: /vol
SETUP=/opt/allgo/setup/dk
#pip3 install --force-reinstall mysqlclient django-environ
mkdir -p \
/vol/rw/datastore \
/vol/rw/app \
/vol/rw/system \
/vol/log/nginx \
/vol/log/django \
/vol/log/redis \
/vol/log/supervisor \
/vol/log/gunicorn \
/vol/cache/redis \
/vol/cache/nginx
# Apply patch to nginx.conf to update the volume paths
patch /etc/nginx/nginx.conf < $SETUP/nginx.patch
# supervisord config
# rm /etc/supervisor/supervisord.conf
# ln -s "/opt/allgo/setup/dk/supervisord.conf" /etc/supervisor/
# nginx config
rm /etc/nginx/sites-enabled/default
ln -s "/opt/allgo/setup/dk/allgo.conf" /etc/nginx/sites-enabled/allgo
# Nothing to do here at the moment
41,42c41,42
5a6,7
> error_log /vol/log/nginx/error.log;
>
41,42c43,47
< access_log /var/log/nginx/access.log;
< error_log /var/log/nginx/error.log;
---
> access_log /vol/log/nginx/access.log;
> error_log /vol/log/nginx/error.log;
>
> client_body_temp_path /vol/cache/nginx/body;
> fastcgi_temp_path /vol/cache/nginx/body;
> proxy_temp_path /vol/cache/nginx/body;
......@@ -2,6 +2,19 @@
set -e
mkdir -p \
/vol/rw/datastore \
/vol/rw/app \
/vol/rw/system \
/vol/log/nginx \
/vol/log/django \
/vol/log/redis \
/vol/log/supervisor \
/vol/log/gunicorn \
/vol/cache/redis \
/vol/cache/nginx
# dump the database and execute the migration
while ! mysql -u allgo -h dev-mysql --password=allgo -e ";"
do
......@@ -12,6 +25,5 @@ done
/bin/bash /opt/allgo/tools/migration.sh -d allgo allgo dev-mysql allgo
/bin/bash /opt/allgo/tools/migration.sh -m allgo allgo dev-mysql allgo
# service nginx start
python3 /opt/allgo/manage.py runserver 4000 &
exec nginx -g 'daemon off;'
# Run supervisor in order to launch both nginx and gunicorn
exec supervisord -n
......@@ -15,12 +15,8 @@ supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[supervisorctl]
serverurl=unix:///vol/cache/supervisor.sock ; use a unix:// URL for a unix socket
;[program:redis]
;command=/usr/bin/redis-server /etc/redis/redis.conf
;startsecs=10
[program:django]
command=gunicorn allgo.wsgi:application -w 2 -b :4000
command=gunicorn config.wsgi:application -w 2 -b :4000
startsecs=10
[program:nginx]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment