diff --git a/Dockerfile b/Dockerfile index 430af538d4ba7f659c670406dda72ea92c1fcc1d..ec15ae7f43e5e55cfa9d7379c69a12ba4059bad0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,10 +3,30 @@ FROM python:3.6 RUN mkdir /code WORKDIR /code ADD requirements.txt /code/ -RUN pip install -r requirements.txt -RUN pip install gunicorn + +RUN apt-get update && apt-get install -y --no-install-recommends \ + nginx \ + supervisor \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* \ + && apt-get autoremove -y --purge + +COPY ./requirements.txt /code/requirements.txt +RUN pip install -r requirements.txt && \ + pip install gunicorn && \ + rm /etc/nginx/sites-enabled/default && \ + echo "daemon off;" >> /etc/nginx/nginx.conf + ADD . /code/ +RUN DATABASE_URL=none python manage.py collectstatic --noinput + +COPY conf/supervisor.conf /etc/supervisor/conf.d/supervisor.conf +COPY conf/nginx.conf /etc/nginx/conf.d/openlobby-server.conf +COPY conf/entrypoint.sh ./ + +WORKDIR /code + EXPOSE 8010 -CMD ["sh", "-c", "make migrate & gunicorn -w 4 -b 0.0.0.0:8010 --access-logfile - --error-logfile - --capture-output openlobby.wsgi"] +ENTRYPOINT ["./entrypoint.sh"] diff --git a/conf/entrypoint.sh b/conf/entrypoint.sh new file mode 100644 index 0000000000000000000000000000000000000000..1d11868c922336fcfdc03490ee15c8948ff9f2a5 --- /dev/null +++ b/conf/entrypoint.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +# migrate +python manage.py migrate + +# Create log dirs and files +mkdir -p $( dirname $(cat /etc/supervisor/supervisord.conf | grep logfile= | grep "\.log" | sed s/.*logfile=// ) ) +touch $( cat /etc/supervisor/supervisord.conf | grep logfile= | grep "\.log" | sed s/.*logfile=// ) +exec /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisor.conf --nodaemon \ No newline at end of file diff --git a/conf/nginx.conf b/conf/nginx.conf new file mode 100644 index 0000000000000000000000000000000000000000..9fb806a6fb61e2a4572ac77a2ff50b9450d6dacb --- /dev/null +++ b/conf/nginx.conf @@ -0,0 +1,13 @@ +server { + listen 80; + server_name 127.0.0.1; + + location /static { + alias /code/static; + } + + location / { + proxy_pass http://0.0.0.0:8000; + proxy_set_header Host $http_host; + } +} diff --git a/conf/supervisor.conf b/conf/supervisor.conf new file mode 100644 index 0000000000000000000000000000000000000000..eaf08f13b5651253ff8097d650e6c47c131364ab --- /dev/null +++ b/conf/supervisor.conf @@ -0,0 +1,23 @@ +[program:app-gunicorn] +command = gunicorn -w 4 -b 0.0.0.0:8010 --access-logfile - --error-logfile - --capture-output openlobby.wsgi +priority=2 +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 + +[program:nginx-app] +command = /usr/sbin/nginx +priority=3 +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 + + +[supervisord] +logfile = /var/log/supervisor/supervisord.log +logfile_maxbytes = 10MB +logfile_backups = 5 +loglevel = info +pidfile = /var/run/supervisord.pid \ No newline at end of file diff --git a/openlobby/settings.py b/openlobby/settings.py index d598d3da701c3f7b86cd7bd4b0d26500d347dd14..ea44c1870876fc13569e6b824cd5b6be195f2fa5 100644 --- a/openlobby/settings.py +++ b/openlobby/settings.py @@ -8,7 +8,7 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) DEBUG = 'DEBUG' in os.environ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = os.environ.get('SECRET_KEY') +SECRET_KEY = os.environ.get('SECRET_KEY','very-secret-key') if not SECRET_KEY: if DEBUG: SECRET_KEY = 'not-secret-at-all' @@ -114,11 +114,9 @@ USE_L10N = True USE_TZ = True -# Static files (CSS, JavaScript, Images) - +STATIC_ROOT = os.path.join(BASE_DIR, 'static') STATIC_URL = '/static/' - LOGGING = { 'version': 1, 'handlers': {