Switch to UWSGI and improve Docker definitions

This commit is contained in:
2022-10-18 07:22:22 +01:00
parent d3694d1821
commit 8ce0066c38
7 changed files with 93 additions and 32 deletions

View File

@@ -1,109 +0,0 @@
version: "2.2"
services:
app:
image: xf/fisk:prod
container_name: fisk
build: ${PORTAINER_GIT_DIR}/docker/prod
volumes:
- ${PORTAINER_GIT_DIR}:/code
- ${APP_DATABASE_FILE}:/conf/db.sqlite3
- app_static:${STATIC_ROOT}
#ports:
# - "8000:8000" # uwsgi socket
env_file:
- ../stack.env
volumes_from:
- tmp
depends_on:
# redis:
# condition: service_healthy
migration:
condition: service_started
collectstatic:
condition: service_started
migration:
image: xf/fisk:prod
container_name: migration_fisk
build: ./docker/prod
command: sh -c '. /venv/bin/activate && python manage.py migrate --noinput'
volumes:
- ${PORTAINER_GIT_DIR}:/code
- ${APP_DATABASE_FILE}:/conf/db.sqlite3
- app_static:${STATIC_ROOT}
env_file:
- ../stack.env
collectstatic:
image: xf/fisk:prod
container_name: collectstatic_fisk
build: ./docker/prod
command: sh -c '. /venv/bin/activate && python manage.py collectstatic --noinput'
volumes:
- ${PORTAINER_GIT_DIR}:/code
- ${APP_DATABASE_FILE}:/conf/db.sqlite3
- app_static:${STATIC_ROOT}
env_file:
- ../stack.env
nginx:
image: nginx:latest
container_name: nginx_fisk
ports:
- ${APP_PORT}:9999
ulimits:
nproc: 65535
nofile:
soft: 65535
hard: 65535
volumes:
- ${PORTAINER_GIT_DIR}:/code
- ${PORTAINER_GIT_DIR}/docker/nginx/conf.d:/etc/nginx/conf.d
- app_static:${STATIC_ROOT}
volumes_from:
- tmp
depends_on:
app:
condition: service_started
# volumes_from:
# - tmp
# depends_on:
# redis:
# condition: service_healthy
tmp:
image: busybox
container_name: tmp_fisk
command: chmod -R 777 /var/run/socks
volumes:
- /var/run/socks
# redis:
# image: redis
# command: redis-server /etc/redis.conf
# ulimits:
# nproc: 65535
# nofile:
# soft: 65535
# hard: 65535
# volumes:
# - ${PORTAINER_GIT_DIR}/docker/redis.conf:/etc/redis.conf
# - redis_data:/data
# volumes_from:
# - tmp
# healthcheck:
# test: "redis-cli -s /var/run/redis/redis.sock ping"
# interval: 2s
# timeout: 2s
# retries: 15
networks:
default:
external:
name: xf
volumes:
app_static: {}

View File

@@ -1,6 +1,7 @@
upstream django {
#server app:8000;
server unix:///var/run/socks/app.sock;
#server unix:///var/run/socks/app.sock;
server app:8000;
}
server {

View File

@@ -0,0 +1,24 @@
upstream django {
server app:8000;
#server unix:///var/run/socks/app.sock;
}
server {
listen 9999;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /conf;
}
location / {
include /etc/nginx/uwsgi_params; # the uwsgi_params file you installed
uwsgi_pass django;
uwsgi_param Host $host;
uwsgi_param X-Real-IP $remote_addr;
uwsgi_param X-Forwarded-For $proxy_add_x_forwarded_for;
uwsgi_param X-Forwarded-Proto $http_x_forwarded_proto;
}
}

View File

@@ -1,23 +0,0 @@
# syntax=docker/dockerfile:1
FROM python:3
RUN useradd -d /code xf
RUN mkdir -p /code
RUN chown -R xf:xf /code
RUN mkdir -p /conf/static
RUN chown -R xf:xf /conf
RUN mkdir /venv
RUN chown xf:xf /venv
USER xf
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
WORKDIR /code
COPY requirements.prod.txt /code/
RUN python -m venv /venv
RUN . /venv/bin/activate && pip install -r requirements.prod.txt
# CMD . /venv/bin/activate && uwsgi --ini /conf/uwsgi.ini
CMD . /venv/bin/activate && uvicorn --reload --reload-include *.html --workers 2 --uds /var/run/socks/app.sock app.asgi:application
# CMD . /venv/bin/activate && gunicorn -b 0.0.0.0:8000 --reload app.asgi:application -k uvicorn.workers.UvicornWorker

View File

@@ -1,25 +0,0 @@
wheel
django
pre-commit
django-crispy-forms==1.14.0
crispy-bulma
stripe
django-rest-framework
uvloop
uvicorn[standard]
gunicorn
django-htmx
cryptography
django-debug-toolbar
django-debug-toolbar-template-profiler
orjson
django-otp
django-two-factor-auth
django-otp-yubikey
phonenumbers
qrcode
pydantic
alpaca-py
oandapyV20
glom
watchfiles

13
docker/uwsgi.ini Normal file
View File

@@ -0,0 +1,13 @@
[uwsgi]
chdir=/code
module=app.wsgi:application
env=DJANGO_SETTINGS_MODULE=app.settings
master=1
pidfile=/tmp/project-master.pid
socket=0.0.0.0:8000
processes=5
harakiri=20
max-requests=5000
vacuum=1
home=/venv