From 89aee17c2e1e481d90dafa950317ec468ade451b Mon Sep 17 00:00:00 2001 From: Michael Herrmann Date: Tue, 14 Nov 2023 08:43:22 +0800 Subject: [PATCH] First implementation of Docker support --- .dockerignore | 1 + README.md | 3 +++ deploy/.dockerignore | 1 + deploy/Dockerfile | 19 +++++++++++++++++++ deploy/docker-compose.yml | 24 ++++++++++++++++++++++++ deploy/nginx.conf | 32 ++++++++++++++++++++++++++++++++ 6 files changed, 80 insertions(+) create mode 120000 .dockerignore create mode 100644 deploy/.dockerignore create mode 100644 deploy/Dockerfile create mode 100644 deploy/docker-compose.yml create mode 100644 deploy/nginx.conf diff --git a/.dockerignore b/.dockerignore new file mode 120000 index 0000000..a37ec9b --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +/home/michael/dev/api.winget.pro/.gitignore \ No newline at end of file diff --git a/README.md b/README.md index 005d145..61ea232 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,9 @@ Upload [`install.sh`](install.sh) and a `.bashrc` file with the settings below to a Debian 11 server, then run `install.sh` as root. ```bash +# Set DEBUG to False in production: +export DEBUG=False + # The domain under which this server runs: export HOST_NAME=some.domain.com diff --git a/deploy/.dockerignore b/deploy/.dockerignore new file mode 100644 index 0000000..f59ec20 --- /dev/null +++ b/deploy/.dockerignore @@ -0,0 +1 @@ +* \ No newline at end of file diff --git a/deploy/Dockerfile b/deploy/Dockerfile new file mode 100644 index 0000000..76cce5e --- /dev/null +++ b/deploy/Dockerfile @@ -0,0 +1,19 @@ +FROM python:3.9 + +ENV DEBUG=False +ENV HOST_NAME=* + +WORKDIR /srv + +COPY . . + +RUN pip install --no-cache-dir -Ur requirements/base-full.txt + +RUN python manage.py migrate + +RUN python manage.py collectstatic --noinput + +EXPOSE 8000 + +CMD ["gunicorn", "core.wsgi:application", "--bind", "0.0.0.0:8000", \ + "--log-level=warning", "--log-file=-"] \ No newline at end of file diff --git a/deploy/docker-compose.yml b/deploy/docker-compose.yml new file mode 100644 index 0000000..9c0f1b1 --- /dev/null +++ b/deploy/docker-compose.yml @@ -0,0 +1,24 @@ +version: '3.8' + +services: + django: + build: + context: .. + dockerfile: deploy/Dockerfile + volumes: + - static:/srv/static + - media:/srv/media + nginx: + image: nginx:1.25.3 + volumes: + - static:/srv/static + - media:/srv/media + - ./nginx.conf:/etc/nginx/nginx.conf:ro + ports: + - "8000:80" + depends_on: + - django + +volumes: + static: + media: \ No newline at end of file diff --git a/deploy/nginx.conf b/deploy/nginx.conf new file mode 100644 index 0000000..7a292e3 --- /dev/null +++ b/deploy/nginx.conf @@ -0,0 +1,32 @@ +# The events block is required; We need to supply it, even if empty: +events {} + +http { + # Make Nginx serve CSS files as text/css instead of text/plain. Otherwise, + # the browser does not apply styles: + include /etc/nginx/mime.types; + + upstream django { + server django:8000; + } + + server { + listen 80; + + location /static/ { + alias /srv/static/; + } + + location /media/ { + alias /srv/media/; + } + + location / { + proxy_pass http://django; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } + } +}