Skip to content
Snippets Groups Projects
Commit f018f7b3 authored by Michal Holub's avatar Michal Holub
Browse files

Static files now served with nginx

static nginx part of docker. Supervisor used to control both gunicorn
and nginx
parent b826b694
No related branches found
No related tags found
No related merge requests found
...@@ -3,10 +3,30 @@ FROM python:3.6 ...@@ -3,10 +3,30 @@ FROM python:3.6
RUN mkdir /code RUN mkdir /code
WORKDIR /code WORKDIR /code
ADD requirements.txt /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/ 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 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"]
#!/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
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;
}
}
[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
...@@ -8,7 +8,7 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) ...@@ -8,7 +8,7 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
DEBUG = 'DEBUG' in os.environ DEBUG = 'DEBUG' in os.environ
# SECURITY WARNING: keep the secret key used in production secret! # 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 not SECRET_KEY:
if DEBUG: if DEBUG:
SECRET_KEY = 'not-secret-at-all' SECRET_KEY = 'not-secret-at-all'
...@@ -114,11 +114,9 @@ USE_L10N = True ...@@ -114,11 +114,9 @@ USE_L10N = True
USE_TZ = True USE_TZ = True
# Static files (CSS, JavaScript, Images) STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/' STATIC_URL = '/static/'
LOGGING = { LOGGING = {
'version': 1, 'version': 1,
'handlers': { 'handlers': {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment