Browse Source

Add docker stuff

master
Johann Schmitz 4 years ago
parent
commit
c8ae1a7ec3
Signed by: ercpe GPG Key ID: A084064277C501ED
  1. 26
      Dockerfile
  2. 26
      docker/nginx.conf
  3. 19
      docker/supervisord.conf
  4. 34
      docker_settings.py

26
Dockerfile

@ -0,0 +1,26 @@
FROM python:2.7
MAINTAINER Johann Schmitz
RUN apt-get update -y && apt-get upgrade -y && \
apt-get install nginx supervisor rrdtool -y
RUN mkdir -p /code
WORKDIR /code
EXPOSE 8080
ADD . /code/app
WORKDIR /code/app
RUN chown nobody:nogroup /code -R && python -m compileall /code/app
# installing gunicorn via pip3 installs the python3 version
RUN pip install -r requirements.txt && \
pip install mysqlclient gunicorn
COPY docker/nginx.conf /etc/nginx/conf.d/
COPY docker/supervisord.conf /etc/supervisord.conf
ENV DJANGO_SETTINGS_MODULE docker_settings
CMD /usr/bin/supervisord -c /etc/supervisord.conf -n

26
docker/nginx.conf

@ -0,0 +1,26 @@
server {
listen 8080;
access_log off;
error_log off;
client_max_body_size 10m;
add_header Referrer-Policy no-referrer;
location /static/admin {
alias /usr/lib/python2.7/site-packages/django/contrib/admin/static/admin;
}
location /static {
alias /code/app/djunin/static;
}
location / {
proxy_pass_header Server;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_connect_timeout 30;
proxy_read_timeout 120;
proxy_pass http://127.0.0.1:8000/;
}
}

19
docker/supervisord.conf

@ -0,0 +1,19 @@
[supervisord]
nodaemon=true
[program:nginx]
command=/usr/sbin/nginx -g "daemon off;"
autostart=true
autorestart=true
priority=20
[program:gunicorn]
directory=/code/app
command=gunicorn -b 127.0.0.1:8000 -w 4 -t 120 --graceful-timeout 120 djunin.wsgi
autostart=true
autorestart=true
priority=20
user=nobody
[include]
files = /etc/supervisord.d/*.ini

34
docker_settings.py

@ -0,0 +1,34 @@
# -*- coding: utf-8 -*-
from djunin.settings import *
import os
import logging
SECRET_KEY = os.environ.get('DJANGO_SECRET_KEY')
DEBUG = False
ALLOWED_HOSTS = [x.strip() for x in os.environ.get('DJANGO_ALLOWED_HOSTS', '').split(',')]
logging.basicConfig(
level=logging.WARNING,
format='%(asctime)s %(levelname)-7s %(message)s'
)
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': os.environ.get('DJANGO_DATABASE_NAME'),
'USER': os.environ.get('DJANGO_DATABASE_USER'),
'PASSWORD': os.environ.get('DJANGO_DATABASE_PASS'),
'HOST': os.environ.get('DJANGO_DATABASE_HOST'),
'PORT': os.environ.get('DJANGO_DATABASE_PORT', ''),
'OPTIONS': {
'init_command': "SET sql_mode='STRICT_TRANS_TABLES'",
}
}
}
MUNIN_DATA_DIR = '/munin'
COMPRESS_ROOT = os.path.join(BASE_DIR, 'djunin/static')