Switch to UWSGI and make docker build/run smarter
This commit is contained in:
parent
5cba45e0a7
commit
e121b135a2
|
@ -1,5 +1,6 @@
|
|||
# syntax=docker/dockerfile:1
|
||||
FROM python:3
|
||||
ARG OPERATION
|
||||
|
||||
RUN useradd -d /code xf
|
||||
RUN mkdir -p /code
|
||||
|
@ -18,6 +19,10 @@ WORKDIR /code
|
|||
COPY requirements.txt /code/
|
||||
RUN python -m venv /venv
|
||||
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
|
|
@ -4,9 +4,13 @@ services:
|
|||
app:
|
||||
image: xf/envelope:prod
|
||||
container_name: envelope
|
||||
build: .
|
||||
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}
|
||||
#ports:
|
||||
|
@ -22,11 +26,17 @@ services:
|
|||
condition: service_started
|
||||
collectstatic:
|
||||
condition: service_started
|
||||
networks:
|
||||
- default
|
||||
- xf
|
||||
|
||||
migration:
|
||||
image: xf/envelope:prod
|
||||
container_name: migration_envelope
|
||||
build: .
|
||||
build:
|
||||
context: .
|
||||
args:
|
||||
OPERATION: ${OPERATION}
|
||||
command: sh -c '. /venv/bin/activate && python manage.py migrate --noinput'
|
||||
volumes:
|
||||
- ${PORTAINER_GIT_DIR}:/code
|
||||
|
@ -38,7 +48,10 @@ services:
|
|||
collectstatic:
|
||||
image: xf/envelope:prod
|
||||
container_name: collectstatic_envelope
|
||||
build: .
|
||||
build:
|
||||
context: .
|
||||
args:
|
||||
OPERATION: ${OPERATION}
|
||||
command: sh -c '. /venv/bin/activate && python manage.py collectstatic --noinput'
|
||||
volumes:
|
||||
- ${PORTAINER_GIT_DIR}:/code
|
||||
|
@ -59,15 +72,17 @@ services:
|
|||
hard: 65535
|
||||
volumes:
|
||||
- ${PORTAINER_GIT_DIR}:/code
|
||||
- ${PORTAINER_GIT_DIR}/docker/nginx/conf.d:/etc/nginx/conf.d
|
||||
- ${PORTAINER_GIT_DIR}/docker/nginx/conf.d/${OPERATION}.conf:/etc/nginx/conf.d/default.conf
|
||||
- app_static:${STATIC_ROOT}
|
||||
volumes_from:
|
||||
- tmp
|
||||
networks:
|
||||
- default
|
||||
- xf
|
||||
depends_on:
|
||||
app:
|
||||
condition: service_started
|
||||
|
||||
|
||||
# volumes_from:
|
||||
# - tmp
|
||||
# depends_on:
|
||||
|
@ -101,9 +116,10 @@ services:
|
|||
# retries: 15
|
||||
|
||||
networks:
|
||||
default:
|
||||
external:
|
||||
name: xf
|
||||
default:
|
||||
driver: bridge
|
||||
xf:
|
||||
external: true
|
||||
|
||||
volumes:
|
||||
app_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 {
|
||||
|
@ -9,11 +10,10 @@ server {
|
|||
location = /favicon.ico { access_log off; log_not_found off; }
|
||||
|
||||
location /static/ {
|
||||
root /code/core/;
|
||||
root /conf;
|
||||
}
|
||||
|
||||
location / {
|
||||
include /etc/nginx/uwsgi_params; # the uwsgi_params file you installed
|
||||
proxy_pass http://django;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
@ -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,4 +1,5 @@
|
|||
wheel
|
||||
uwsgi
|
||||
django
|
||||
pre-commit
|
||||
django-crispy-forms
|
||||
|
|
Loading…
Reference in New Issue