Switch to UWSGI and improve Docker definitions
This commit is contained in:
parent
d3694d1821
commit
8ce0066c38
|
@ -1,5 +1,6 @@
|
|||
# syntax=docker/dockerfile:1
|
||||
FROM python:3
|
||||
ARG OPERATION
|
||||
|
||||
RUN useradd -d /code xf
|
||||
RUN mkdir -p /code
|
||||
|
@ -15,9 +16,13 @@ USER xf
|
|||
ENV PYTHONDONTWRITEBYTECODE=1
|
||||
ENV PYTHONUNBUFFERED=1
|
||||
WORKDIR /code
|
||||
COPY requirements.prod.txt /code/
|
||||
COPY requirements.txt /code/
|
||||
RUN python -m venv /venv
|
||||
RUN . /venv/bin/activate && pip install -r requirements.prod.txt
|
||||
RUN . /venv/bin/activate && pip install -r requirements.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 if [ "$OPERATION" = "uwsgi" ] ; then . /venv/bin/activate && uwsgi --ini /conf/uwsgi.ini ; else . /venv/bin/activate && exec python manage.py runserver 0.0.0.0:8000; fi
|
||||
|
||||
# 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
|
18
Makefile
18
Makefile
|
@ -1,26 +1,26 @@
|
|||
run:
|
||||
docker-compose -f docker/docker-compose.prod.yml --env-file=stack.env up -d
|
||||
docker-compose --env-file=stack.env up -d
|
||||
|
||||
build:
|
||||
docker-compose -f docker/docker-compose.prod.yml --env-file=stack.env build
|
||||
docker-compose --env-file=stack.env build
|
||||
|
||||
stop:
|
||||
docker-compose -f docker/docker-compose.prod.yml --env-file=stack.env down
|
||||
docker-compose --env-file=stack.env down
|
||||
|
||||
log:
|
||||
docker-compose -f docker/docker-compose.prod.yml --env-file=stack.env logs -f
|
||||
docker-compose --env-file=stack.env logs -f
|
||||
|
||||
test:
|
||||
docker-compose -f docker/docker-compose.prod.yml --env-file=stack.env run --rm app sh -c ". /venv/bin/activate && python manage.py test $(MODULES)"
|
||||
docker-compose --env-file=stack.env run --rm app sh -c ". /venv/bin/activate && python manage.py test $(MODULES)"
|
||||
|
||||
migrate:
|
||||
docker-compose -f docker/docker-compose.prod.yml --env-file=stack.env run --rm app sh -c ". /venv/bin/activate && python manage.py migrate"
|
||||
docker-compose --env-file=stack.env run --rm app sh -c ". /venv/bin/activate && python manage.py migrate"
|
||||
|
||||
makemigrations:
|
||||
docker-compose -f docker/docker-compose.prod.yml --env-file=stack.env run --rm app sh -c ". /venv/bin/activate && python manage.py makemigrations"
|
||||
docker-compose --env-file=stack.env run --rm app sh -c ". /venv/bin/activate && python manage.py makemigrations"
|
||||
|
||||
auth:
|
||||
docker-compose -f docker/docker-compose.prod.yml --env-file=stack.env run --rm app sh -c ". /venv/bin/activate && python manage.py createsuperuser"
|
||||
docker-compose --env-file=stack.env run --rm app sh -c ". /venv/bin/activate && python manage.py createsuperuser"
|
||||
|
||||
token:
|
||||
docker-compose -f docker/docker-compose.prod.yml --env-file=stack.env run --rm app sh -c ". /venv/bin/activate && python manage.py addstatictoken m"
|
||||
docker-compose --env-file=stack.env run --rm app sh -c ". /venv/bin/activate && python manage.py addstatictoken m"
|
||||
|
|
|
@ -4,15 +4,19 @@ services:
|
|||
app:
|
||||
image: xf/fisk:prod
|
||||
container_name: fisk
|
||||
build: ${PORTAINER_GIT_DIR}/docker/prod
|
||||
build:
|
||||
context: .
|
||||
args:
|
||||
OPERATION: ${OPERATION}
|
||||
volumes:
|
||||
- ${PORTAINER_GIT_DIR}:/code
|
||||
- ${PORTAINER_GIT_DIR}/docker/uwsgi.ini:/conf/uwsgi.ini
|
||||
- ${APP_DATABASE_FILE}:/conf/db.sqlite3
|
||||
- app_static:${STATIC_ROOT}
|
||||
- fisk_static:${STATIC_ROOT}
|
||||
#ports:
|
||||
# - "8000:8000" # uwsgi socket
|
||||
env_file:
|
||||
- ../stack.env
|
||||
- stack.env
|
||||
volumes_from:
|
||||
- tmp
|
||||
depends_on:
|
||||
|
@ -22,30 +26,39 @@ services:
|
|||
condition: service_started
|
||||
collectstatic:
|
||||
condition: service_started
|
||||
networks:
|
||||
- default
|
||||
- xf
|
||||
|
||||
migration:
|
||||
image: xf/fisk:prod
|
||||
container_name: migration_fisk
|
||||
build: ./docker/prod
|
||||
build:
|
||||
context: .
|
||||
args:
|
||||
OPERATION: ${OPERATION}
|
||||
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}
|
||||
- fisk_static:${STATIC_ROOT}
|
||||
env_file:
|
||||
- ../stack.env
|
||||
- stack.env
|
||||
|
||||
collectstatic:
|
||||
image: xf/fisk:prod
|
||||
container_name: collectstatic_fisk
|
||||
build: ./docker/prod
|
||||
build:
|
||||
context: .
|
||||
args:
|
||||
OPERATION: ${OPERATION}
|
||||
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}
|
||||
- fisk_static:${STATIC_ROOT}
|
||||
env_file:
|
||||
- ../stack.env
|
||||
- stack.env
|
||||
|
||||
nginx:
|
||||
image: nginx:latest
|
||||
|
@ -59,10 +72,13 @@ services:
|
|||
hard: 65535
|
||||
volumes:
|
||||
- ${PORTAINER_GIT_DIR}:/code
|
||||
- ${PORTAINER_GIT_DIR}/docker/nginx/conf.d:/etc/nginx/conf.d
|
||||
- app_static:${STATIC_ROOT}
|
||||
- ${PORTAINER_GIT_DIR}/docker/nginx/conf.d/${OPERATION}.conf:/etc/nginx/conf.d/default.conf
|
||||
- fisk_static:${STATIC_ROOT}
|
||||
volumes_from:
|
||||
- tmp
|
||||
networks:
|
||||
- default
|
||||
- xf
|
||||
depends_on:
|
||||
app:
|
||||
condition: service_started
|
||||
|
@ -102,8 +118,9 @@ services:
|
|||
|
||||
networks:
|
||||
default:
|
||||
external:
|
||||
name: xf
|
||||
driver: bridge
|
||||
xf:
|
||||
external: true
|
||||
|
||||
volumes:
|
||||
app_static: {}
|
||||
fisk_static: {}
|
|
@ -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 {
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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
|
||||
|
|
@ -1,13 +1,14 @@
|
|||
wheel
|
||||
uwsgi
|
||||
django
|
||||
pre-commit
|
||||
django-crispy-forms==1.14.0
|
||||
crispy-bulma
|
||||
stripe
|
||||
django-rest-framework
|
||||
uvloop
|
||||
uvicorn[standard]
|
||||
gunicorn
|
||||
uvloop #
|
||||
uvicorn[standard] #
|
||||
gunicorn #
|
||||
django-htmx
|
||||
cryptography
|
||||
django-debug-toolbar
|
||||
|
@ -22,4 +23,4 @@ pydantic
|
|||
alpaca-py
|
||||
oandapyV20
|
||||
glom
|
||||
watchfiles
|
||||
watchfiles #
|
Loading…
Reference in New Issue