build: add docker-compose deployment

This commit is contained in:
James Graham
2021-07-30 16:42:51 +01:00
parent 40c138de00
commit d2093f849a
6 changed files with 88 additions and 1 deletions

16
.dockerignore Normal file
View File

@@ -0,0 +1,16 @@
.dbbackup/
.idea/
.mypy_cache/
.vagrant/
.venv/
venv/
.vscode/
Caddyfile
docker-compose.yml
mail.log/
/roles/
/static/
*.sqlite3*
*.log*
deployment*

18
Caddyfile Normal file
View File

@@ -0,0 +1,18 @@
localhost breccia-mapper-dev breccia-mapper-dev.jagraham.co.uk mapper.gcrf-breccia.com {
tls internal
root * /srv
file_server
@proxy_paths {
not path /static/*
}
reverse_proxy @proxy_paths http://web:8000
log {
output stderr
format single_field common_log
}
}

15
Dockerfile Normal file
View File

@@ -0,0 +1,15 @@
FROM python:3.8-slim
RUN groupadd -r mapper && useradd --no-log-init -r -g mapper mapper
WORKDIR /app
COPY requirements.txt ./
RUN pip install --no-cache-dir --upgrade pip \
&& pip install --no-cache-dir -r /app/requirements.txt gunicorn
COPY . ./
ENTRYPOINT [ "/app/entrypoint.sh" ]
CMD [ "gunicorn", "-w", "2", "-b", "0.0.0.0:8000", "breccia_mapper.wsgi" ]

33
docker-compose.yml Normal file
View File

@@ -0,0 +1,33 @@
version: '3.1'
services:
web:
build: .
ports:
- 8000:8000
environment:
DEBUG: "true"
DATABASE_URL: sqlite:////app/db.sqlite3
volumes:
- ./db.sqlite3:/app/db.sqlite3:z
- static_files:/app/static
caddy:
image: caddy:2
restart: unless-stopped
ports:
- 80:80
- 443:443
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile:z
# Caddy serves static files collected by Django
- static_files:/srv/static
- caddy_data:/data
- caddy_config:/config
depends_on:
- web
volumes:
caddy_data:
caddy_config:
static_files:

5
entrypoint.sh Executable file
View File

@@ -0,0 +1,5 @@
#!/bin/sh
python manage.py migrate \
&& python manage.py collectstatic --no-input \
&& exec "$@"

View File

@@ -21,7 +21,7 @@ isort==4.3.21
jsonfield==3.1.0
lazy-object-proxy==1.4.3
mccabe==0.6.1
mysqlclient==1.4.6
# mysqlclient==1.4.6
pep8-naming==0.4.1
prospector==1.2.0
pycodestyle==2.4.0