Use Uvicorn for production with Nginx
This commit is contained in:
@@ -2,44 +2,79 @@ version: "2.2"
|
||||
|
||||
services:
|
||||
app:
|
||||
image: xf/envelope:latest
|
||||
build: ./docker/prod
|
||||
image: xf/envelope:prod
|
||||
build: ${PORTAINER_GIT_DIR}/docker/prod
|
||||
volumes:
|
||||
- ${PORTAINER_GIT_DIR}:/code
|
||||
- ${PORTAINER_GIT_DIR}/docker/prod/uwsgi.ini:/conf/uwsgi.ini
|
||||
# - ${PORTAINER_GIT_DIR}/docker/prod/uwsgi.ini:/conf/uwsgi.ini
|
||||
- ${APP_LOCAL_SETTINGS}:/code/app/local_settings.py
|
||||
- ${APP_DATABASE_FILE}:/code/db.sqlite3
|
||||
ports:
|
||||
- "${APP_PORT}:8000" # uwsgi socket
|
||||
- "8000:8000" # uwsgi socket
|
||||
env_file:
|
||||
- ../stack.env
|
||||
# volumes_from:
|
||||
# - tmp
|
||||
volumes_from:
|
||||
- tmp
|
||||
depends_on:
|
||||
# redis:
|
||||
# condition: service_healthy
|
||||
migration:
|
||||
condition: service_started
|
||||
collectstatic:
|
||||
condition: service_started
|
||||
|
||||
migration:
|
||||
image: xf/envelope:latest
|
||||
image: xf/envelope:prod
|
||||
build: ./docker/prod
|
||||
command: sh -c '. /venv/bin/activate && python manage.py migrate --noinput'
|
||||
volumes:
|
||||
- ${PORTAINER_GIT_DIR}:/code
|
||||
- ${APP_LOCAL_SETTINGS}:/code/app/local_settings.py
|
||||
- ${APP_DATABASE_FILE}:/code/db.sqlite3
|
||||
env_file:
|
||||
- ../stack.env
|
||||
|
||||
collectstatic:
|
||||
image: xf/envelope:prod
|
||||
build: ./docker/prod
|
||||
command: sh -c '. /venv/bin/activate && python manage.py collectstatic --noinput'
|
||||
volumes:
|
||||
- ${PORTAINER_GIT_DIR}:/code
|
||||
- ${APP_LOCAL_SETTINGS}:/code/app/local_settings.py
|
||||
- ${APP_DATABASE_FILE}:/code/db.sqlite3
|
||||
env_file:
|
||||
- ../stack.env
|
||||
|
||||
nginx:
|
||||
image: nginx:latest
|
||||
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
|
||||
volumes_from:
|
||||
- tmp
|
||||
depends_on:
|
||||
app:
|
||||
condition: service_started
|
||||
|
||||
|
||||
# volumes_from:
|
||||
# - tmp
|
||||
# depends_on:
|
||||
# redis:
|
||||
# condition: service_healthy
|
||||
|
||||
# tmp:
|
||||
# image: busybox
|
||||
# command: chmod -R 777 /var/run/redis
|
||||
# volumes:
|
||||
# - /var/run/redis
|
||||
tmp:
|
||||
image: busybox
|
||||
command: chmod -R 777 /var/run/socks
|
||||
volumes:
|
||||
- /var/run/socks
|
||||
|
||||
# redis:
|
||||
# image: redis
|
||||
|
||||
23
docker/nginx/conf.d/default.conf
Normal file
23
docker/nginx/conf.d/default.conf
Normal file
@@ -0,0 +1,23 @@
|
||||
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 /code/core/;
|
||||
}
|
||||
|
||||
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;
|
||||
proxy_set_header Host $host;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,4 +18,6 @@ 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 && uwsgi --ini /conf/uwsgi.ini
|
||||
CMD . /venv/bin/activate && uvicorn --reload --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
|
||||
@@ -5,7 +5,9 @@ django-crispy-forms
|
||||
crispy-bulma
|
||||
stripe
|
||||
django-rest-framework
|
||||
uwsgi
|
||||
uvloop
|
||||
uvicorn[standard]
|
||||
gunicorn
|
||||
django-htmx
|
||||
cryptography
|
||||
django-debug-toolbar
|
||||
|
||||
Reference in New Issue
Block a user