From cb40fb71c8969be204f846ea713bcbb895ef9483 Mon Sep 17 00:00:00 2001 From: Data-Name-ID Date: Tue, 2 Apr 2024 11:46:37 +0300 Subject: [PATCH] [fix] docker deploy --- backend/.dockerignore | 4 +--- docker-compose.yml | 35 +++++++++++++++++++++++------------ nginx/nginx.conf | 23 +++++++++++++++++++++++ 3 files changed, 47 insertions(+), 15 deletions(-) create mode 100644 nginx/nginx.conf diff --git a/backend/.dockerignore b/backend/.dockerignore index 93d78d9..9414382 100644 --- a/backend/.dockerignore +++ b/backend/.dockerignore @@ -1,3 +1 @@ -# Folders -venv/ -__pycache__/ +Dockerfile diff --git a/docker-compose.yml b/docker-compose.yml index 0e9dbac..057b4bf 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -21,12 +21,12 @@ services: backend: build: ./backend container_name: backend + volumes: + - media_volume:/app/project/media/ + - static_volume:/app/project/static/ depends_on: postgres: condition: service_healthy - restart: unless-stopped - expose: - - 8000 environment: POSTGRES_USER: ${POSTGRES_USER:-postgres} POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-postgres} @@ -38,18 +38,28 @@ services: DJANGO_DEBUG: ${DJANGO_DEBUG:-false} DJANGO_ALLOWED_HOSTS: ${DJANGO_ALLOWED_HOSTS:-*} DJANGO_INTERNAL_IPS: ${DJANGO_INTERNAL_IPS:-127.0.0.1} - command: ["sh", "-c", "cd project && python manage.py migrate && gunicorn config.wsgi:application --bind 0.0.0.0:8080"] - ports: - - 8080:8080 - - frontend: - container_name: frontend + expose: + - 8080 + command: + [ + "sh", + "-c", + "cd project && python manage.py collectstatic --noinput && python manage.py migrate && gunicorn config.wsgi:application --bind 0.0.0.0:8080", + ] + + nginx: + container_name: nginx build: context: ./frontend dockerfile: Dockerfile ports: - - "3000:3000" - restart: always + - "80:80" + volumes: + - ./nginx/nginx.conf:/etc/nginx/conf.d/default.conf + - media_volume:/var/html/media/ + - static_volume:/var/html/static/ + depends_on: + - backend pgadmin: image: dpage/pgadmin4:8.4 @@ -68,5 +78,6 @@ services: volumes: postgres_data: - redis_data: pgadmin_data: + media_volume: + static_volume: diff --git a/nginx/nginx.conf b/nginx/nginx.conf new file mode 100644 index 0000000..14d9870 --- /dev/null +++ b/nginx/nginx.conf @@ -0,0 +1,23 @@ +server { + listen 80; + + server_tokens off; + + location /api/ { + proxy_pass http://backend:8080/api/; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $host; + proxy_redirect off; + } + location / { + root /usr/share/nginx/html/; + index index.html; + try_files $uri $uri/ /index.html; + } + location /media/ { + root /var/html/; + } + location /static/ { + root /var/html/; + } +} \ No newline at end of file