diff --git a/requirements.txt b/requirements.txt index 9b65544..9aab945 100644 --- a/requirements.txt +++ b/requirements.txt @@ -19,3 +19,4 @@ django-cors-headers==2.0.1 djangorestframework==3.5.3 coverage==4.3.4 django-nose==1.4.4 +uWSGI==2.0.14 diff --git a/scripts/production/Dockerfile b/scripts/production/Dockerfile new file mode 100644 index 0000000..31f1682 --- /dev/null +++ b/scripts/production/Dockerfile @@ -0,0 +1,68 @@ +# TODO https://github.com/Kazanz/docker-nginx-uwsgi-django/blob/master/Dockerfile +#FROM ubuntu:16.04 + + +#RUN apt-get update +#Install python dependencies +#RUN apt-get install -y python3-dev python3 python3-pip python3 +# install nginx +#RUN apt-get install -y nginx +# install install packet dependencies +#RUN apt-get install -y mysql-client libmysqlclient-dev libssl-dev + +#RUN mkdir -p /code +#RUN mkdir -p /run +#WORKDIR /code +#ADD requirements.txt /code/ +#ADD scripts/production/nginx.conf /etc/nginx/sites-enabled/default + +#RUN pip3 install -r requirements.txt +#ADD . /code/ +#RUN python3 manage.py collectstatic --no-input + +#EXPOSE 80 + +#ENTRYPOINT ["/usr/bin/uwsgi", "/code/scripts/production/uwsgi.ini"] +#ENTRYPOINT ["/bin/bash"] + +FROM python:3.5-alpine + +RUN apk add --update \ + nginx \ + supervisor \ + python-dev \ + build-base \ + linux-headers \ + pcre-dev \ + py-pip \ + vim \ + mysql-client \ + mysql-dev \ + openssl-dev \ + libffi-dev \ + jpeg-dev \ + zlib-dev\ +&& rm -rf /var/cache/apk/* \ +&& chown -R nginx:www-data /var/lib/nginx + +RUN mkdir -p /code +RUN mkdir -p /run +RUN mkdir -p /run/nginx +RUN chmod -R 777 /run + +WORKDIR /code +ADD . /code/ +ADD requirements.txt /code/ + +RUN pip install -r requirements.txt +RUN python manage.py collectstatic --no-input + + +RUN rm -f /etc/nginx/nginx.conf +ADD scripts/production/nginx.conf /etc/nginx/nginx.conf +RUN mkdir /etc/nginx/sites-enabled +ADD scripts/production/nginx-app.conf /etc/nginx/sites-enabled/default + +RUN rm /etc/supervisord.conf +ADD scripts/production/supervisord.conf /etc/supervisord.conf +CMD ["supervisord", "-n"] diff --git a/scripts/production/nginx-app.conf b/scripts/production/nginx-app.conf new file mode 100644 index 0000000..bff49f7 --- /dev/null +++ b/scripts/production/nginx-app.conf @@ -0,0 +1,14 @@ +server{ + listen 80; + server_name _; + location / { + uwsgi_pass unix:///run/django.socket; + include /etc/nginx/uwsgi_params; + } + location /static { + alias /code/static; + } + location /media { + alias /code/media; + } +} diff --git a/scripts/production/nginx.conf b/scripts/production/nginx.conf new file mode 100644 index 0000000..5ec9942 --- /dev/null +++ b/scripts/production/nginx.conf @@ -0,0 +1,20 @@ +#user nobody; +worker_processes 4; + +error_log /dev/stdout debug; +#error_log logs/error.log notice; +#error_log logs/error.log info; +#pid run/nginx.pid; + + +events { + worker_connections 1024; +} +http { + include mime.types; + include /etc/nginx/sites-enabled/*; + default_type application/octet-stream; + keepalive_timeout 65; + sendfile on; +} +daemon off; diff --git a/scripts/production/supervisord.conf b/scripts/production/supervisord.conf new file mode 100644 index 0000000..d5166e9 --- /dev/null +++ b/scripts/production/supervisord.conf @@ -0,0 +1,17 @@ +[supervisord] + +[supervisorctl] + +[program:app-uwsgi] +command = /usr/local/bin/uwsgi --ini /code/scripts/production/uwsgi.ini +stdout_logfile = /dev/stdout +stderr_logfile = /dev/stderr +stdout_logfile_maxbytes=0 +stderr_logfile_maxbytes=0 + +[program:nginx-app] +command = /usr/sbin/nginx +stdout_logfile = /dev/stdout +stderr_logfile = /dev/stderr +stdout_logfile_maxbytes=0 +stderr_logfile_maxbytes=0