events {}
http {
upstream api {
server django:8000;
}
upstream front {
server react:3000;
}
server {
listen 80;
###########
# STATIC FOLDER ROUTING #
###########
location /static/django/ {
alias /django/static/;
}
location /media/django/ {
alias /django/media/;
}
location /static/ {
root /var/www/static/react;
}
###########
# WS URL ROUTING #
###########
location /ws/ {
proxy_pass http://daphne;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 86400;
}
###########
# URL ROUTING #
###########
location /api/ {
proxy_pass http://api;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
}
location / {
proxy_pass http://front;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
}
}
}
version: "3.3"
services:
redis:
image: redis
restart: always
env_file:
- .env
servis_db:
restart: on-failure
image: postgres
container_name: servis_db
volumes:
- pg_data:/var/lib/postgresql/data/
env_file:
- .env
django:
restart: on-failure
build: app
command: sh -c "python manage.py makemigrations
&& python manage.py migrate
&& python manage.py add_admin
&& python manage.py create_trajectories
&& python manage.py collectstatic --noinput
&& gunicorn app.wsgi:application --bind 0.0.0.0:8000"
volumes:
- django_static:/django/static
- django_media:/django/media
ports:
- "8000:8000"
depends_on:
- servis_db
env_file:
- .env
celery:
restart: on-failure
build: app
command: sh -c "celery -A app worker -l INFO"
depends_on:
- redis
env_file:
- .env
daphne:
restart: on-failure
build: app
command: daphne -b 0.0.0.0 -p 8081 app.asgi:application
ports:
- "8081:8081"
depends_on:
- redis
links:
- redis
react:
build:
context: trajectory-frontend
dockerfile: Dockerfile
volumes:
- react_build:/react/build
ports:
- "3000:3000"
env_file:
- .env
depends_on:
- django
command: serve -s build
nginx:
restart: always
build: nginx
volumes:
- react_build:/var/www/static/react
- django_static:/django/static
- django_media:/django/media
ports:
- "80:80"
depends_on:
- django
- daphne
- react
volumes:
django_static:
django_media:
react_build:
pg_data:
http {
#...
include /etc/nginx/mime.types;
#...
}