Added docker deployment files

This commit is contained in:
Claudio Maggioni 2018-08-10 13:44:52 +02:00
parent d41dab6051
commit f3e6a53cfd
6 changed files with 137 additions and 0 deletions

48
Dockerfile Normal file
View File

@ -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"]

36
nginx-app.conf Normal file
View File

@ -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
}
}

1
requirements.txt Normal file
View File

@ -0,0 +1 @@
django

5
supervisor-app.conf Normal file
View File

@ -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

31
uwsgi.ini Normal file
View File

@ -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

16
uwsgi_params Normal file
View File

@ -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;