fix docker compose file and docker
This commit is contained in:
16
.dockerignore
Normal file
16
.dockerignore
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
venv
|
||||||
|
__pycache__
|
||||||
|
*.pyc
|
||||||
|
*.pyo
|
||||||
|
*.pyd
|
||||||
|
*.sqlite3
|
||||||
|
db.sqlite3
|
||||||
|
.pytest_cache
|
||||||
|
.mypy_cache
|
||||||
|
.cache
|
||||||
|
.venv
|
||||||
|
.DS_Store
|
||||||
|
.git
|
||||||
|
*.egg-info
|
||||||
|
dist
|
||||||
|
build
|
||||||
12
.env
Normal file
12
.env
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
# Local Development Environment
|
||||||
|
DEBUG=True
|
||||||
|
SECRET_KEY=django-insecure-r616b$_bknw-2nh96gbuwe%2l-2o@g3uui747t8jz&nwp&xe_m
|
||||||
|
ALLOWED_HOSTS=localhost,127.0.0.1
|
||||||
|
|
||||||
|
# Database Configuration (Postgres)
|
||||||
|
DB_ENGINE=postgresql
|
||||||
|
DB_NAME=portfolio_admin
|
||||||
|
DB_USER=postgres
|
||||||
|
DB_PASSWORD=postgres
|
||||||
|
DB_HOST=db
|
||||||
|
DB_PORT=5432
|
||||||
12
.env.example
Normal file
12
.env.example
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
# Django Settings
|
||||||
|
DEBUG=False
|
||||||
|
SECRET_KEY=your-secret-key-here-change-in-production
|
||||||
|
ALLOWED_HOSTS=localhost,127.0.0.1,yourdomain.com
|
||||||
|
|
||||||
|
# Database Configuration (Postgres)
|
||||||
|
DB_ENGINE=postgresql
|
||||||
|
DB_NAME=portfolio_admin
|
||||||
|
DB_USER=postgres
|
||||||
|
DB_PASSWORD=postgres
|
||||||
|
DB_HOST=db
|
||||||
|
DB_PORT=5432
|
||||||
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
venv/
|
||||||
|
products/
|
||||||
Binary file not shown.
@@ -18,4 +18,4 @@ class ProductAdmin(admin.ModelAdmin):
|
|||||||
@admin.register(ContactMessage)
|
@admin.register(ContactMessage)
|
||||||
class ContactAdmin(admin.ModelAdmin):
|
class ContactAdmin(admin.ModelAdmin):
|
||||||
list_display = ('name', 'phone', 'product_name', 'created_at')
|
list_display = ('name', 'phone', 'product_name', 'created_at')
|
||||||
search_fields = ('name', 'phone', 'product_name')
|
search_fields = ('name', 'phone', 'product_name')
|
||||||
BIN
db.sqlite3
BIN
db.sqlite3
Binary file not shown.
52
docker-compose.yml
Normal file
52
docker-compose.yml
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
networks:
|
||||||
|
portfolio:
|
||||||
|
driver: bridge
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
pg_date: null
|
||||||
|
|
||||||
|
|
||||||
|
services:
|
||||||
|
nginx:
|
||||||
|
networks:
|
||||||
|
- portfolio
|
||||||
|
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
|
||||||
|
|
||||||
|
web:
|
||||||
|
networks:
|
||||||
|
- portfolio
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: ./docker/Dockerfile.web
|
||||||
|
restart: always
|
||||||
|
command: sh resources/scripts/entrypoint.sh
|
||||||
|
environment:
|
||||||
|
- PYTHONPYCACHEPREFIX=/var/cache/pycache
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
- './:/code'
|
||||||
|
depends_on:
|
||||||
|
- db
|
||||||
|
|
||||||
|
db:
|
||||||
|
image: postgres:16
|
||||||
|
networks:
|
||||||
|
- portfolio
|
||||||
|
restart: always
|
||||||
|
environment:
|
||||||
|
POSTGRES_DB: ${DB_NAME}
|
||||||
|
POSTGRES_USER: ${DB_USER}
|
||||||
|
POSTGRES_PASSWORD: ${DB_PASSWORD}
|
||||||
|
POSTGRES_HOST: ${DB_HOST}
|
||||||
|
POSTGRES_PORT: ${DB_PORT}
|
||||||
|
volumes:
|
||||||
|
- pg_date:/var/lib/postgresql/data
|
||||||
3
docker/Dockerfile.nginx
Normal file
3
docker/Dockerfile.nginx
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
FROM nginx:alpine
|
||||||
|
|
||||||
|
COPY ./resources/layout/nginx.conf /etc/nginx/nginx.conf
|
||||||
13
docker/Dockerfile.web
Normal file
13
docker/Dockerfile.web
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
FROM python:3.12-alpine
|
||||||
|
|
||||||
|
ENV PYTHONPYCACHEPREFIX=/dev/null
|
||||||
|
|
||||||
|
RUN apk update && apk add git gettext
|
||||||
|
|
||||||
|
WORKDIR /code
|
||||||
|
|
||||||
|
COPY requirements.txt /code/requirements.txt
|
||||||
|
|
||||||
|
RUN --mount=type=cache,target=/root/.cache/pip pip install -r requirements.txt
|
||||||
|
|
||||||
|
CMD ["sh", "./entrypoint.sh"]
|
||||||
@@ -10,7 +10,12 @@ For the full list of settings and their values, see
|
|||||||
https://docs.djangoproject.com/en/5.2/ref/settings/
|
https://docs.djangoproject.com/en/5.2/ref/settings/
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
|
# Load environment variables from .env file
|
||||||
|
load_dotenv()
|
||||||
|
|
||||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||||
@@ -20,12 +25,12 @@ BASE_DIR = Path(__file__).resolve().parent.parent
|
|||||||
# See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/
|
# See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/
|
||||||
|
|
||||||
# SECURITY WARNING: keep the secret key used in production secret!
|
# SECURITY WARNING: keep the secret key used in production secret!
|
||||||
SECRET_KEY = 'django-insecure-r616b$_bknw-2nh96gbuwe%2l-2o@g3uui747t8jz&nwp&xe_m'
|
SECRET_KEY = os.getenv('SECRET_KEY', 'django-insecure-r616b$_bknw-2nh96gbuwe%2l-2o@g3uui747t8jz&nwp&xe_m')
|
||||||
|
|
||||||
# SECURITY WARNING: don't run with debug turned on in production!
|
# SECURITY WARNING: don't run with debug turned on in production!
|
||||||
DEBUG = True
|
DEBUG = os.getenv('DEBUG', 'False').lower() == 'true'
|
||||||
|
|
||||||
ALLOWED_HOSTS = []
|
ALLOWED_HOSTS = os.getenv('ALLOWED_HOSTS', 'localhost,127.0.0.1').split(',')
|
||||||
|
|
||||||
|
|
||||||
# Application definition
|
# Application definition
|
||||||
@@ -75,12 +80,26 @@ WSGI_APPLICATION = 'portfolio_admin.wsgi.application'
|
|||||||
# Database
|
# Database
|
||||||
# https://docs.djangoproject.com/en/5.2/ref/settings/#databases
|
# https://docs.djangoproject.com/en/5.2/ref/settings/#databases
|
||||||
|
|
||||||
DATABASES = {
|
DB_ENGINE = os.getenv('DB_ENGINE', 'sqlite3')
|
||||||
'default': {
|
|
||||||
'ENGINE': 'django.db.backends.sqlite3',
|
if DB_ENGINE == 'postgresql':
|
||||||
'NAME': BASE_DIR / 'db.sqlite3',
|
DATABASES = {
|
||||||
|
'default': {
|
||||||
|
'ENGINE': 'django.db.backends.postgresql',
|
||||||
|
'NAME': os.getenv('DB_NAME', 'portfolio_admin'),
|
||||||
|
'USER': os.getenv('DB_USER', 'postgres'),
|
||||||
|
'PASSWORD': os.getenv('DB_PASSWORD', 'postgres'),
|
||||||
|
'HOST': os.getenv('DB_HOST', 'db'),
|
||||||
|
'PORT': os.getenv('DB_PORT', '5432'),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
DATABASES = {
|
||||||
|
'default': {
|
||||||
|
'ENGINE': 'django.db.backends.sqlite3',
|
||||||
|
'NAME': BASE_DIR / 'db.sqlite3',
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# Password validation
|
# Password validation
|
||||||
|
|||||||
8
requirements.txt
Normal file
8
requirements.txt
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
asgiref==3.11.0
|
||||||
|
Django==5.2.8
|
||||||
|
djangorestframework==3.16.1
|
||||||
|
pillow==12.0.0
|
||||||
|
sqlparse==0.5.4
|
||||||
|
gunicorn
|
||||||
|
psycopg2-binary==2.9.9
|
||||||
|
python-dotenv==1.0.0
|
||||||
53
resources/layout/nginx.conf
Normal file
53
resources/layout/nginx.conf
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
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; # Uvicorn serveri ishga tushadigan port
|
||||||
|
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/static/;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /resources/media/ {
|
||||||
|
alias /usr/share/nginx/html/resources/media/;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
7
resources/scripts/entrypoint.sh
Normal file
7
resources/scripts/entrypoint.sh
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
python3 manage.py collectstatic --noinput
|
||||||
|
python3 manage.py makemigrations --noinput
|
||||||
|
python3 manage.py migrate --noinput
|
||||||
|
|
||||||
|
uvicorn config.asgi:application --host 0.0.0.0 --port 8000 --reload --reload-dir content --reload-dir portfolio_admin
|
||||||
|
|
||||||
|
exit $?
|
||||||
Reference in New Issue
Block a user