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
|
# syntax=docker/dockerfile:1
|
||||||
FROM python:3
|
FROM python:3
|
||||||
|
ARG OPERATION
|
||||||
|
|
||||||
RUN useradd -d /code xf
|
RUN useradd -d /code xf
|
||||||
RUN mkdir -p /code
|
RUN mkdir -p /code
|
||||||
|
@ -18,6 +19,10 @@ WORKDIR /code
|
||||||
COPY requirements.txt /code/
|
COPY requirements.txt /code/
|
||||||
RUN python -m venv /venv
|
RUN python -m venv /venv
|
||||||
RUN . /venv/bin/activate && pip install -r requirements.txt
|
RUN . /venv/bin/activate && pip install -r requirements.txt
|
||||||
|
|
||||||
# CMD . /venv/bin/activate && uwsgi --ini /conf/uwsgi.ini
|
# 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
|
# 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:
|
app:
|
||||||
image: xf/envelope:prod
|
image: xf/envelope:prod
|
||||||
container_name: envelope
|
container_name: envelope
|
||||||
build: .
|
build:
|
||||||
|
context: .
|
||||||
|
args:
|
||||||
|
OPERATION: ${OPERATION}
|
||||||
volumes:
|
volumes:
|
||||||
- ${PORTAINER_GIT_DIR}:/code
|
- ${PORTAINER_GIT_DIR}:/code
|
||||||
|
- ${PORTAINER_GIT_DIR}/docker/uwsgi.ini:/conf/uwsgi.ini
|
||||||
- ${APP_DATABASE_FILE}:/conf/db.sqlite3
|
- ${APP_DATABASE_FILE}:/conf/db.sqlite3
|
||||||
- app_static:${STATIC_ROOT}
|
- app_static:${STATIC_ROOT}
|
||||||
#ports:
|
#ports:
|
||||||
|
@ -22,11 +26,17 @@ services:
|
||||||
condition: service_started
|
condition: service_started
|
||||||
collectstatic:
|
collectstatic:
|
||||||
condition: service_started
|
condition: service_started
|
||||||
|
networks:
|
||||||
|
- default
|
||||||
|
- xf
|
||||||
|
|
||||||
migration:
|
migration:
|
||||||
image: xf/envelope:prod
|
image: xf/envelope:prod
|
||||||
container_name: migration_envelope
|
container_name: migration_envelope
|
||||||
build: .
|
build:
|
||||||
|
context: .
|
||||||
|
args:
|
||||||
|
OPERATION: ${OPERATION}
|
||||||
command: sh -c '. /venv/bin/activate && python manage.py migrate --noinput'
|
command: sh -c '. /venv/bin/activate && python manage.py migrate --noinput'
|
||||||
volumes:
|
volumes:
|
||||||
- ${PORTAINER_GIT_DIR}:/code
|
- ${PORTAINER_GIT_DIR}:/code
|
||||||
|
@ -38,7 +48,10 @@ services:
|
||||||
collectstatic:
|
collectstatic:
|
||||||
image: xf/envelope:prod
|
image: xf/envelope:prod
|
||||||
container_name: collectstatic_envelope
|
container_name: collectstatic_envelope
|
||||||
build: .
|
build:
|
||||||
|
context: .
|
||||||
|
args:
|
||||||
|
OPERATION: ${OPERATION}
|
||||||
command: sh -c '. /venv/bin/activate && python manage.py collectstatic --noinput'
|
command: sh -c '. /venv/bin/activate && python manage.py collectstatic --noinput'
|
||||||
volumes:
|
volumes:
|
||||||
- ${PORTAINER_GIT_DIR}:/code
|
- ${PORTAINER_GIT_DIR}:/code
|
||||||
|
@ -59,15 +72,17 @@ services:
|
||||||
hard: 65535
|
hard: 65535
|
||||||
volumes:
|
volumes:
|
||||||
- ${PORTAINER_GIT_DIR}:/code
|
- ${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}
|
- app_static:${STATIC_ROOT}
|
||||||
volumes_from:
|
volumes_from:
|
||||||
- tmp
|
- tmp
|
||||||
|
networks:
|
||||||
|
- default
|
||||||
|
- xf
|
||||||
depends_on:
|
depends_on:
|
||||||
app:
|
app:
|
||||||
condition: service_started
|
condition: service_started
|
||||||
|
|
||||||
|
|
||||||
# volumes_from:
|
# volumes_from:
|
||||||
# - tmp
|
# - tmp
|
||||||
# depends_on:
|
# depends_on:
|
||||||
|
@ -102,8 +117,9 @@ services:
|
||||||
|
|
||||||
networks:
|
networks:
|
||||||
default:
|
default:
|
||||||
external:
|
driver: bridge
|
||||||
name: xf
|
xf:
|
||||||
|
external: true
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
app_static: {}
|
app_static: {}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
upstream django {
|
upstream django {
|
||||||
#server app:8000;
|
#server app:8000;
|
||||||
server unix:///var/run/socks/app.sock;
|
#server unix:///var/run/socks/app.sock;
|
||||||
|
server app:8000;
|
||||||
}
|
}
|
||||||
|
|
||||||
server {
|
server {
|
||||||
|
@ -9,11 +10,10 @@ server {
|
||||||
location = /favicon.ico { access_log off; log_not_found off; }
|
location = /favicon.ico { access_log off; log_not_found off; }
|
||||||
|
|
||||||
location /static/ {
|
location /static/ {
|
||||||
root /code/core/;
|
root /conf;
|
||||||
}
|
}
|
||||||
|
|
||||||
location / {
|
location / {
|
||||||
include /etc/nginx/uwsgi_params; # the uwsgi_params file you installed
|
|
||||||
proxy_pass http://django;
|
proxy_pass http://django;
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
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
|
wheel
|
||||||
|
uwsgi
|
||||||
django
|
django
|
||||||
pre-commit
|
pre-commit
|
||||||
django-crispy-forms
|
django-crispy-forms
|
||||||
|
|
Loading…
Reference in New Issue