adding docker and docker compose file to running project, configurate nginx.conf file for DNS

This commit is contained in:
behruz-dev
2025-11-16 10:43:32 +05:00
parent 586b0cc321
commit a267e4c45c
10 changed files with 179 additions and 1 deletions

1
.dockerignore Normal file
View File

@@ -0,0 +1 @@
venv/

View File

@@ -115,7 +115,7 @@ USE_TZ = True
# https://docs.djangoproject.com/en/5.2/howto/static-files/
STATIC_URL = 'static/'
STATIC_ROOT = BASE_DIR / 'resources/static'
# Default primary key field type
# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field

View File

@@ -0,0 +1,74 @@
services:
nginx:
networks:
- uyqur
ports:
- ${PORT:-8001}:80
volumes:
- ./resources/layout/nginx.conf:/etc/nginx/nginx.conf
- ./resources/:/usr/share/nginx/html/resources/
build:
context: .
dockerfile: ./docker/Dockerfile.nginx
depends_on:
- web
restart: always
web:
networks:
- uyqur
build:
context: .
dockerfile: ./docker/Dockerfile.web
command: ${COMMAND:-sh ./resources/scripts/entrypoint.sh}
environment:
- PYTHONPYCACHEPREFIX=/var/cache/pycache
volumes:
- './:/code'
depends_on:
- db
- redis
restart: always
db:
image: postgres:17
networks:
- uyqur
environment:
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_DB: ${POSTGRES_DB}
volumes:
- pg_data:/var/lib/postgresql/data
restart: always
redis:
networks:
- uyqur
image: redis
restart: always
# celery:
# build:
# context: .
# dockerfile: ./docker/Dockerfile.web
# command: celery -A config worker --loglevel=info
# volumes:
# - "./:/code"
# depends_on:
# - redis
# - web
# networks:
# - uyqur
# environment:
# - CELERY_BROKER_URL=${CELERY_BROKER_URL:-redis://redis:6379/0}
# - CELERY_RESULT_BACKEND=${CELERY_RESULT_BACKEND:-redis://redis:6379/0}
# restart: always
volumes:
pg_data: null
networks:
uyqur:
driver: bridge

3
docker/Dockerfile.nginx Normal file
View File

@@ -0,0 +1,3 @@
FROM nginx:alpine
COPY ./resources/layout/nginx.conf /etc/nginx/nginx.conf

25
docker/Dockerfile.web Normal file
View File

@@ -0,0 +1,25 @@
FROM python:3.12
WORKDIR /code
RUN apt-get update && \
apt-get install -y \
gdal-bin \
libgdal-dev \
python3-gdal \
libgeos-dev \
libproj-dev \
g++ \
wget \
libfontconfig \
libxrender1 \
libjpeg-dev \
xfonts-base && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
COPY ./ /code
RUN --mount=type=cache,target=/root/.cache/pip python3 -m pip install -r requirements.txt
CMD ["sh", "./resources/scripts/entrypoint.sh"]

4
requirements.txt Normal file
View File

@@ -0,0 +1,4 @@
Django==5.2
gunicorn==23.0.0
uvicorn==0.38.0
celery

View File

@@ -0,0 +1,51 @@
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
client_max_body_size 1024M;
server {
listen 80;
server_name _;
location / {
proxy_pass http://web:8000;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header Host $http_host;
}
location /ws/ {
proxy_pass http://web:8000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $http_host;
}
location /resources/static/ {
alias /usr/share/nginx/html/resources/staticfiles/;
}
location /resources/media/ {
alias /usr/share/nginx/html/resources/media/;
}
}
}

View File

@@ -0,0 +1,5 @@
file=/tmp/db-$(/usr/bin/date +\%Y-%m-%d-%H:%M:%S).sql
container=postgres
/usr/bin/docker container exec $container pg_dump -U postgres django > $file
mc cp $file b2/buket-name
rm $file

View File

@@ -0,0 +1,8 @@
#!/bin/bash
python3 manage.py collectstatic --noinput
python3 manage.py migrate --noinput
gunicorn config.wsgi:application -b 0.0.0.0:8000 --workers $(($(nproc) * 2 + 1))
exit $?

View File

@@ -0,0 +1,7 @@
#!/bin/bash
python3 manage.py collectstatic --noinput
python3 manage.py migrate --noinput
uvicorn config.asgi:application --host 0.0.0.0 --port 8000 --reload --reload-dir apps --reload-dir config
exit $?