gealogiuya
This commit is contained in:
15
deployments/compose/backup/Dockerfile
Normal file
15
deployments/compose/backup/Dockerfile
Normal file
@@ -0,0 +1,15 @@
|
||||
FROM postgres:15-alpine
|
||||
|
||||
# Cron o'rnatish
|
||||
RUN apt-get update && apt-get install -y cron
|
||||
|
||||
# Backup skriptni konteynerga qo'shish
|
||||
COPY deployments/compose/backup/backup.sh /usr/local/bin/backup.sh
|
||||
RUN chmod +x /usr/local/bin/backup.sh
|
||||
|
||||
# Crontab qo'shish
|
||||
RUN echo "* * * * * /usr/local/bin/backup.sh" > /etc/cron.d/db-backup
|
||||
RUN crontab /etc/cron.d/db-backup
|
||||
|
||||
# Cron va PostgreSQL serverni birgalikda ishga tushirish
|
||||
CMD cron && tail -f /dev/null
|
||||
14
deployments/compose/backup/backup.sh
Normal file
14
deployments/compose/backup/backup.sh
Normal file
@@ -0,0 +1,14 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Hozirgi vaqtni olish (backup fayl nomi uchun)
|
||||
TIMESTAMP=$(date +"%F_%H-%M-%S")
|
||||
|
||||
# Backup saqlanadigan katalogni yaratish
|
||||
BACKUP_DIR="/backups/$TIMESTAMP"
|
||||
mkdir -p "$BACKUP_DIR"
|
||||
|
||||
# PostgreSQL'dan backup olish
|
||||
PGPASSWORD=$POSTGRES_PASSWORD pg_dump -U $POSTGRES_USER -d $POSTGRES_DB -F c > "$BACKUP_DIR/my_database.dump"
|
||||
|
||||
# Eski backuplarni 7 kundan keyin o'chirish
|
||||
find /backups/* -mtime +7 -exec rm -rf {} \;
|
||||
52
deployments/compose/django/Dockerfile
Normal file
52
deployments/compose/django/Dockerfile
Normal file
@@ -0,0 +1,52 @@
|
||||
FROM python:3.10-slim-buster
|
||||
|
||||
|
||||
# Set environment variables to ensure UTF-8 encoding
|
||||
ENV PYTHONUNBUFFERED=1 \
|
||||
PYTHONDONTWRITEBYTECODE=1 \
|
||||
LANG=C.UTF-8 \
|
||||
LC_ALL=C.UTF-8
|
||||
|
||||
# Install Flower for Celery monitoring
|
||||
#RUN pip install flower
|
||||
|
||||
# Copy and set permissions for celery worker start script
|
||||
#COPY ./deployments/compose/django/celery/worker/start /start-celeryworker
|
||||
#RUN sed -i 's/\r$//g' /start-celeryworker && \
|
||||
# chmod +x /start-celeryworker
|
||||
|
||||
# Copy and set permissions for celery beat start script
|
||||
#COPY ./deployments/compose/django/celery/beat/start /start-celerybeat
|
||||
#RUN sed -i 's/\r$//g' /start-celerybeat && \
|
||||
# chmod +x /start-celerybeat
|
||||
|
||||
# Copy and set permissions for flower start script
|
||||
#COPY ./deployments/compose/django/celery/flower/start /start-flower
|
||||
#RUN sed -i 's/\r$//g' /start-flower && \
|
||||
# chmod +x /start-flower
|
||||
|
||||
# Update and install necessary packages
|
||||
RUN apt update && apt upgrade -y && apt install git -y && apt install -y gettext
|
||||
|
||||
WORKDIR /app
|
||||
COPY . /app
|
||||
|
||||
# Update pip and install requirements
|
||||
RUN --mount=type=cache,id=custom-pip,target=/root/.cache/pip \
|
||||
pip install --upgrade pip && \
|
||||
pip install -r /app/requirements.txt && \
|
||||
pip install gunicorn && \
|
||||
pip install uvicorn
|
||||
|
||||
# Copy and set permissions for entrypoint script
|
||||
COPY ./deployments/compose/django/entrypoint /entrypoint
|
||||
RUN sed -i 's/\r$//g' /entrypoint && \
|
||||
chmod +x /entrypoint
|
||||
|
||||
# Copy and set permissions for start script
|
||||
COPY ./deployments/compose/django/start /start
|
||||
RUN sed -i 's/\r$//g' /start && \
|
||||
chmod +x /start
|
||||
|
||||
|
||||
ENTRYPOINT ["/entrypoint"]
|
||||
10
deployments/compose/django/celery/beat/start
Normal file
10
deployments/compose/django/celery/beat/start
Normal file
@@ -0,0 +1,10 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
|
||||
# wait for RabbitMQ server to start
|
||||
sleep 10
|
||||
|
||||
rm -f './celerybeat.pid'
|
||||
celery -A core beat -l INFO
|
||||
9
deployments/compose/django/celery/flower/start
Normal file
9
deployments/compose/django/celery/flower/start
Normal file
@@ -0,0 +1,9 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
|
||||
# wait for RabbitMQ server to start
|
||||
sleep 10
|
||||
|
||||
celery -A core --broker="${CELERY_BROKER}" flower
|
||||
9
deployments/compose/django/celery/worker/start
Normal file
9
deployments/compose/django/celery/worker/start
Normal file
@@ -0,0 +1,9 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
|
||||
# wait for RabbitMQ server to start
|
||||
sleep 10
|
||||
|
||||
celery -A core worker -l INFO
|
||||
36
deployments/compose/django/entrypoint
Normal file
36
deployments/compose/django/entrypoint
Normal file
@@ -0,0 +1,36 @@
|
||||
#!/bin/bash
|
||||
|
||||
# if any of the commands in your code fails for any reason, the entire script fails
|
||||
set -o errexit
|
||||
# fail exit if one of your pipe command fails
|
||||
set -o pipefail
|
||||
# exits if any of your variables is not set
|
||||
set -o nounset
|
||||
|
||||
postgres_ready() {
|
||||
python << END
|
||||
import sys
|
||||
|
||||
import psycopg2
|
||||
|
||||
try:
|
||||
psycopg2.connect(
|
||||
dbname="${POSTGRES_DB}",
|
||||
user="${POSTGRES_USER}",
|
||||
password="${POSTGRES_PASSWORD}",
|
||||
host="${POSTGRES_HOST}",
|
||||
port="${POSTGRES_PORT}",
|
||||
)
|
||||
except psycopg2.OperationalError:
|
||||
sys.exit(-1)
|
||||
sys.exit(0)
|
||||
|
||||
END
|
||||
}
|
||||
until postgres_ready; do
|
||||
>&2 echo 'Waiting for PostgreSQL to become available...'
|
||||
sleep 1
|
||||
done
|
||||
>&2 echo 'PostgreSQL is available'
|
||||
|
||||
exec "$@"
|
||||
19
deployments/compose/django/start
Normal file
19
deployments/compose/django/start
Normal file
@@ -0,0 +1,19 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -o errexit
|
||||
set -o pipefail
|
||||
set -o nounset
|
||||
|
||||
# Apply Django migrations
|
||||
#python manage.py makemigrations
|
||||
python manage.py migrate
|
||||
python manage.py createadmin
|
||||
|
||||
# Collect static files
|
||||
python manage.py collectstatic --noinput
|
||||
|
||||
# Run Gunicorn server with increased timeout
|
||||
#exec gunicorn core.wsgi:application --bind 0.0.0.0:8000 --timeout 120
|
||||
|
||||
# Run Uvicorn server using ASGI
|
||||
exec uvicorn core.asgi:application --host 0.0.0.0 --port 8000 --reload
|
||||
7
deployments/compose/nginx/Dockerfile
Normal file
7
deployments/compose/nginx/Dockerfile
Normal file
@@ -0,0 +1,7 @@
|
||||
FROM nginx:1.21-alpine
|
||||
|
||||
# Remove the default NGINX configuration file
|
||||
RUN rm /etc/nginx/conf.d/default.conf
|
||||
|
||||
# Copy your custom NGINX configuration file
|
||||
COPY ./deployments/compose/nginx/nginx.conf /etc/nginx/conf.d/default.conf
|
||||
101
deployments/compose/nginx/nginx.conf
Normal file
101
deployments/compose/nginx/nginx.conf
Normal file
@@ -0,0 +1,101 @@
|
||||
# server {
|
||||
# listen 80;
|
||||
# server_name yourdomain.uz;
|
||||
#
|
||||
# location / {
|
||||
# proxy_pass http://localhost:PROJECT_PORT;
|
||||
# proxy_set_header Host $host;
|
||||
# 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 $scheme;
|
||||
# }
|
||||
#
|
||||
# location /static/ {
|
||||
# alias /path/project/assets/staticfiles/;
|
||||
# }
|
||||
#
|
||||
# location /media/ {
|
||||
# alias /path/project/assets/media/;
|
||||
# }
|
||||
#
|
||||
# location /assets/ {
|
||||
# alias /path/project/assets/;
|
||||
#
|
||||
# location ~ /.well-known/acme-challenge {
|
||||
# allow all;
|
||||
# root /var/www/html;
|
||||
# }
|
||||
# }
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
server_name yourdomain.uz;
|
||||
return 301 https://$host$request_uri; # Redirect HTTP to HTTPS
|
||||
}
|
||||
|
||||
server {
|
||||
listen 443 ssl;
|
||||
server_name yourdomain.uz;
|
||||
|
||||
ssl_certificate /etc/letsencrypt/live/yourdomain.uz/fullchain.pem;
|
||||
ssl_certificate_key /etc/letsencrypt/live/yourdomain.uz/privkey.pem;
|
||||
include /etc/letsencrypt/options-ssl-nginx.conf;
|
||||
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
|
||||
|
||||
# Security headers
|
||||
add_header X-Frame-Options SAMEORIGIN;
|
||||
add_header X-Content-Type-Options nosniff;
|
||||
add_header X-XSS-Protection "1; mode=block";
|
||||
add_header Referrer-Policy no-referrer-when-downgrade;
|
||||
add_header Content-Security-Policy "default-src 'self' http: https: data: blob: 'unsafe-inline'";
|
||||
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
|
||||
|
||||
# Maximize performance
|
||||
client_max_body_size 50M;
|
||||
keepalive_timeout 65;
|
||||
|
||||
location / {
|
||||
proxy_pass http://127.0.0.1:PROJECT_PORT; # your Django app's IP and port
|
||||
proxy_set_header Host $host;
|
||||
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 $scheme;
|
||||
|
||||
# WebSockets support
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "Upgrade";
|
||||
}
|
||||
|
||||
location /static/ {
|
||||
alias /path/project/assets/staticfiles/; # adjust the path to your static files
|
||||
expires 1y;
|
||||
access_log off;
|
||||
add_header Cache-Control "public";
|
||||
}
|
||||
|
||||
location /media/ {
|
||||
alias /path/project/assets/media/; # adjust the path to your media files
|
||||
expires 1y;
|
||||
access_log off;
|
||||
add_header Cache-Control "public";
|
||||
}
|
||||
|
||||
location /assets/ {
|
||||
alias /path/project/assets/; # adjust the path to your assets
|
||||
expires 1y;
|
||||
access_log off;
|
||||
add_header Cache-Control "public";
|
||||
}
|
||||
|
||||
# Enable compression
|
||||
gzip on;
|
||||
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
|
||||
gzip_proxied any;
|
||||
gzip_vary on;
|
||||
|
||||
error_page 500 502 503 504 /50x.html;
|
||||
location = /50x.html {
|
||||
root /usr/share/nginx/html;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user