From f3e6a53cfd1ddd2f9b2a9fc5a118d1d49997a8c3 Mon Sep 17 00:00:00 2001 From: praticamentetilde Date: Fri, 10 Aug 2018 13:44:52 +0200 Subject: [PATCH] Added docker deployment files --- Dockerfile | 48 +++++++++++++++++++++++++++++++++++++++++++++ nginx-app.conf | 36 ++++++++++++++++++++++++++++++++++ requirements.txt | 1 + supervisor-app.conf | 5 +++++ uwsgi.ini | 31 +++++++++++++++++++++++++++++ uwsgi_params | 16 +++++++++++++++ 6 files changed, 137 insertions(+) create mode 100644 Dockerfile create mode 100644 nginx-app.conf create mode 100644 requirements.txt create mode 100644 supervisor-app.conf create mode 100644 uwsgi.ini create mode 100644 uwsgi_params diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..24f679d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,48 @@ +# Original file from: https://github.com/dockerfiles/django-uwsgi-nginx +# Copyright 2013 Thatcher Peskens +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FROM alpine:3.8 + +MAINTAINER Dockerfiles + +# Install required packages and remove the apt packages cache when done. + +RUN apk add -y + git \ + python3 \ + python3-dev \ + nginx \ + supervisor \ + pip3 install -U pip setuptools + +# install uwsgi now because it takes a little while +RUN pip3 install uwsgi + +# setup all the configfiles +RUN echo "daemon off;" >> /etc/nginx/nginx.conf +COPY nginx-app.conf /etc/nginx/sites-available/default +COPY supervisor-app.conf /etc/supervisor/conf.d/ + +# COPY requirements.txt and RUN pip install BEFORE adding the rest of your code, this will cause Docker's caching mechanism +# to prevent re-installing (all your) dependencies when you made a change a line or two in your app. + +COPY requirements.txt /home/docker/code/ +RUN pip3 install -r /home/docker/code/requirements.txt + +# add (the rest of) our code +COPY . /home/docker/code/ + +EXPOSE 80 +CMD ["supervisord", "-n"] diff --git a/nginx-app.conf b/nginx-app.conf new file mode 100644 index 0000000..3fdff04 --- /dev/null +++ b/nginx-app.conf @@ -0,0 +1,36 @@ +# nginx-app.conf + +# the upstream component nginx needs to connect to +upstream django { + server unix:/home/docker/code/app.sock; # for a file socket + # server 127.0.0.1:8001; # for a web port socket (we'll use this first) +} + +# configuration of the server +server { + # the port your site will be served on, default_server indicates that this server block + # is the block to use if no blocks match the server_name + listen 80 default_server; + + # the domain name it will serve for + server_name .example.com; # substitute your machine's IP address or FQDN + charset utf-8; + + # max upload size + client_max_body_size 75M; # adjust to taste + + # Django media + location /media { + alias /home/docker/persistent/media; # your Django project's media files - amend as required + } + + location /static { + alias /home/docker/volatile/static; # your Django project's static files - amend as required + } + + # Finally, send all non-media requests to the Django server. + location / { + uwsgi_pass django; + include /home/docker/code/uwsgi_params; # the uwsgi_params file you installed + } +} diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..d3e4ba5 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +django diff --git a/supervisor-app.conf b/supervisor-app.conf new file mode 100644 index 0000000..d8e3db8 --- /dev/null +++ b/supervisor-app.conf @@ -0,0 +1,5 @@ +[program:app-uwsgi] +command = /usr/local/bin/uwsgi --ini /home/docker/code/uwsgi.ini + +[program:nginx-app] +command = /usr/sbin/nginx diff --git a/uwsgi.ini b/uwsgi.ini new file mode 100644 index 0000000..41d8bec --- /dev/null +++ b/uwsgi.ini @@ -0,0 +1,31 @@ +[uwsgi] +# this config will be loaded if nothing specific is specified +# load base config from below +ini = :base + +# %d is the dir this configuration file is in +socket = %dapp.sock +master = true +processes = 4 + +[dev] +ini = :base +# socket (uwsgi) is not the same as http, nor http-socket +socket = :8001 + + +[local] +ini = :base +http = :8000 +# set the virtual env to use +home=/Users/you/envs/env + + +[base] +# chdir to the folder of this config file, plus app/website +chdir = %d/ +# load the module from wsgi.py, it is a python path from +# the directory above. +module=website.wsgi:application +# allow anyone to connect to the socket. This is very permissive +chmod-socket=666 diff --git a/uwsgi_params b/uwsgi_params new file mode 100644 index 0000000..f539451 --- /dev/null +++ b/uwsgi_params @@ -0,0 +1,16 @@ + +uwsgi_param QUERY_STRING $query_string; +uwsgi_param REQUEST_METHOD $request_method; +uwsgi_param CONTENT_TYPE $content_type; +uwsgi_param CONTENT_LENGTH $content_length; + +uwsgi_param REQUEST_URI $request_uri; +uwsgi_param PATH_INFO $document_uri; +uwsgi_param DOCUMENT_ROOT $document_root; +uwsgi_param SERVER_PROTOCOL $server_protocol; +uwsgi_param HTTPS $https if_not_empty; + +uwsgi_param REMOTE_ADDR $remote_addr; +uwsgi_param REMOTE_PORT $remote_port; +uwsgi_param SERVER_PORT $server_port; +uwsgi_param SERVER_NAME $server_name;