From 8ac8fd87877b424283ee270146f2a18de9aec0a6 Mon Sep 17 00:00:00 2001 From: behruz-dev Date: Thu, 28 Aug 2025 13:05:11 +0500 Subject: [PATCH] initial commit --- .dockerignore | 0 .env.example | 0 .gitignore | 267 ++++++++++++++++++++++ config/__init__.py | 0 config/asgi.py | 16 ++ config/conf/__init__.py | 6 + config/conf/cors.py | 9 + config/conf/jwt.py | 10 + config/conf/logs.py | 0 config/conf/redis.py | 24 ++ config/conf/rest_framework.py | 9 + config/conf/swagger.py | 13 ++ config/env.py | 8 + config/settings/base.py | 99 ++++++++ config/settings/local.py | 0 config/settings/prod.py | 0 config/settings/test.py | 0 config/urls.py | 32 +++ config/wsgi.py | 16 ++ core/apps/accounts/__init__.py | 0 core/apps/accounts/admin.py | 3 + core/apps/accounts/apps.py | 6 + core/apps/accounts/migrations/__init__.py | 0 core/apps/accounts/models.py | 3 + core/apps/accounts/tests.py | 3 + core/apps/accounts/views.py | 3 + core/apps/orders/__init__.py | 0 core/apps/orders/admin.py | 3 + core/apps/orders/apps.py | 6 + core/apps/orders/migrations/__init__.py | 0 core/apps/orders/models.py | 3 + core/apps/orders/tests.py | 3 + core/apps/orders/views.py | 3 + core/apps/products/__init__.py | 0 core/apps/products/admin.py | 3 + core/apps/products/apps.py | 6 + core/apps/products/migrations/__init__.py | 0 core/apps/products/models.py | 3 + core/apps/products/tests.py | 3 + core/apps/products/views.py | 3 + core/apps/shared/__init__.py | 0 core/apps/shared/admin.py | 3 + core/apps/shared/apps.py | 6 + core/apps/shared/migrations/__init__.py | 0 core/apps/shared/models.py | 3 + core/apps/shared/tests.py | 3 + core/apps/shared/views.py | 3 + docker-compose.yaml | 52 +++++ docker/Dockerfile.nginx | 3 + docker/Dockerfile.web | 26 +++ manage.py | 22 ++ requirements.txt | 11 + resources/layout/Dockerfile.alpine | 13 ++ resources/layout/Dockerfile.nginx | 3 + resources/layout/nginx.conf | 52 +++++ resources/scripts/backup.sh | 5 + resources/scripts/entrypoint-server.sh | 8 + resources/scripts/entrypoint.sh | 7 + 58 files changed, 783 insertions(+) create mode 100644 .dockerignore create mode 100644 .env.example create mode 100644 .gitignore create mode 100644 config/__init__.py create mode 100644 config/asgi.py create mode 100644 config/conf/__init__.py create mode 100644 config/conf/cors.py create mode 100644 config/conf/jwt.py create mode 100644 config/conf/logs.py create mode 100644 config/conf/redis.py create mode 100644 config/conf/rest_framework.py create mode 100644 config/conf/swagger.py create mode 100644 config/env.py create mode 100644 config/settings/base.py create mode 100644 config/settings/local.py create mode 100644 config/settings/prod.py create mode 100644 config/settings/test.py create mode 100644 config/urls.py create mode 100644 config/wsgi.py create mode 100644 core/apps/accounts/__init__.py create mode 100644 core/apps/accounts/admin.py create mode 100644 core/apps/accounts/apps.py create mode 100644 core/apps/accounts/migrations/__init__.py create mode 100644 core/apps/accounts/models.py create mode 100644 core/apps/accounts/tests.py create mode 100644 core/apps/accounts/views.py create mode 100644 core/apps/orders/__init__.py create mode 100644 core/apps/orders/admin.py create mode 100644 core/apps/orders/apps.py create mode 100644 core/apps/orders/migrations/__init__.py create mode 100644 core/apps/orders/models.py create mode 100644 core/apps/orders/tests.py create mode 100644 core/apps/orders/views.py create mode 100644 core/apps/products/__init__.py create mode 100644 core/apps/products/admin.py create mode 100644 core/apps/products/apps.py create mode 100644 core/apps/products/migrations/__init__.py create mode 100644 core/apps/products/models.py create mode 100644 core/apps/products/tests.py create mode 100644 core/apps/products/views.py create mode 100644 core/apps/shared/__init__.py create mode 100644 core/apps/shared/admin.py create mode 100644 core/apps/shared/apps.py create mode 100644 core/apps/shared/migrations/__init__.py create mode 100644 core/apps/shared/models.py create mode 100644 core/apps/shared/tests.py create mode 100644 core/apps/shared/views.py create mode 100644 docker-compose.yaml create mode 100644 docker/Dockerfile.nginx create mode 100644 docker/Dockerfile.web create mode 100755 manage.py create mode 100644 requirements.txt create mode 100644 resources/layout/Dockerfile.alpine create mode 100644 resources/layout/Dockerfile.nginx create mode 100644 resources/layout/nginx.conf create mode 100644 resources/scripts/backup.sh create mode 100644 resources/scripts/entrypoint-server.sh create mode 100644 resources/scripts/entrypoint.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..e69de29 diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..e69de29 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a821800 --- /dev/null +++ b/.gitignore @@ -0,0 +1,267 @@ +# Created by https://www.toptal.com/developers/gitignore/api/python,django +# Edit at https://www.toptal.com/developers/gitignore?templates=python,django + +### Django ### +*.log +*.pot +*.pyc +__pycache__/ +local_settings.py +db.sqlite3 +db.sqlite3-journal +resources/media +resources/static + +# If your build process includes running collectstatic, then you probably don't need or want to include staticfiles/ +# in your Git repository. Update and uncomment the following line accordingly. +# /staticfiles/ + +### Django.Python Stack ### +# Byte-compiled / optimized / DLL files +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo + +# Django stuff: + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/#use-with-ide +.pdm.toml + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +.idea/ + +### Python ### +# Byte-compiled / optimized / DLL files + +# C extensions + +# Distribution / packaging + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. + +# Installer logs + +# Unit test / coverage reports + +# Translations + +# Django stuff: + +# Flask stuff: + +# Scrapy stuff: + +# Sphinx documentation + +# PyBuilder + +# Jupyter Notebook + +# IPython + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/#use-with-ide + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm + +# Celery stuff + +# SageMath parsed files + +# Environments + +# Spyder project settings + +# Rope project settings + +# mkdocs documentation + +# mypy + +# Pyre type checker + +# pytype static type analyzer + +# Cython debug symbols + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. + +### Python Patch ### +# Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration +poetry.toml + +# ruff +.ruff_cache/ + +# LSP config files +pyrightconfig.json + +# End of https://www.toptal.com/developers/gitignore/api/python,django \ No newline at end of file diff --git a/config/__init__.py b/config/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/config/asgi.py b/config/asgi.py new file mode 100644 index 0000000..5b6ed6c --- /dev/null +++ b/config/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for config project. + +It exposes the ASGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/5.2/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings.base') + +application = get_asgi_application() diff --git a/config/conf/__init__.py b/config/conf/__init__.py new file mode 100644 index 0000000..bba5ee0 --- /dev/null +++ b/config/conf/__init__.py @@ -0,0 +1,6 @@ +from .rest_framework import * +from .cors import * +from .jwt import * +from .logs import * +from .swagger import * +from .redis import * \ No newline at end of file diff --git a/config/conf/cors.py b/config/conf/cors.py new file mode 100644 index 0000000..79bd23a --- /dev/null +++ b/config/conf/cors.py @@ -0,0 +1,9 @@ +CORS_ALLOWED_ORIGINS = [ + "http://localhost:5173", + "http://127.0.0.1:5173", +] + +CSRF_TRUSTED_ORIGINS = [ + 'http://localhost:8001', + 'http://127.0.0.1:8001', +] \ No newline at end of file diff --git a/config/conf/jwt.py b/config/conf/jwt.py new file mode 100644 index 0000000..15af64a --- /dev/null +++ b/config/conf/jwt.py @@ -0,0 +1,10 @@ +from datetime import timedelta + + +SIMPLE_JWT = { + "ACCESS_TOKEN_LIFETIME": timedelta(days=30), + "REFRESH_TOKEN_LIFETIME": timedelta(days=365), + "ROTATE_REFRESH_TOKENS": True, + "BLACKLIST_AFTER_ROTATION": True, + "UPDATE_LAST_LOGIN": True, +} \ No newline at end of file diff --git a/config/conf/logs.py b/config/conf/logs.py new file mode 100644 index 0000000..e69de29 diff --git a/config/conf/redis.py b/config/conf/redis.py new file mode 100644 index 0000000..f4e8686 --- /dev/null +++ b/config/conf/redis.py @@ -0,0 +1,24 @@ +CACHES = { + "default": { + "BACKEND": 'django_redis.cache.RedisCache', + "LOCATION": 'redis://redis:6379', + "TIMEOUT": 300, + }, +} + +CACHE_MIDDLEWARE_SECONDS = 300 + + +CACHEOPS_REDIS = 'redis://redis:6379' +CACHEOPS_DEFAULTS = { + "timeout": 300, +} + +CACHEOPS = { + "accounts.*": { + "ops": "all", + "timeout": 60 * 5, + }, +} +CACHEOPS_DEGRADE_ON_FAILURE = True +CACHEOPS_ENABLED = False \ No newline at end of file diff --git a/config/conf/rest_framework.py b/config/conf/rest_framework.py new file mode 100644 index 0000000..7148bc9 --- /dev/null +++ b/config/conf/rest_framework.py @@ -0,0 +1,9 @@ +REST_FRAMEWORK = { + "DEFAULT_AUTHENTICATION_CLASSES": [ + 'rest_framework.authentication.SessionAuthentication', + 'rest_framework.authentication.BasicAuthentication', + 'rest_framework_simplejwt.authentication.JWTAuthentication', + ], + # 'DEFAULT_PAGINATION_CLASS': 'core.apps.shared.paginations.custom.CustomPageNumberPagination', + # 'PAGE_SIZE': 10 +} \ No newline at end of file diff --git a/config/conf/swagger.py b/config/conf/swagger.py new file mode 100644 index 0000000..b2d6dde --- /dev/null +++ b/config/conf/swagger.py @@ -0,0 +1,13 @@ +SWAGGER_SETTINGS = { + 'SECURITY_DEFINITIONS': { + 'Basic': { + 'type': 'basic' + }, + 'Bearer': { + 'type': 'apiKey', + 'name': 'Authorization', + 'in': 'header' + } + }, + "USE_SESSION_AUTH": False +} \ No newline at end of file diff --git a/config/env.py b/config/env.py new file mode 100644 index 0000000..9506fb1 --- /dev/null +++ b/config/env.py @@ -0,0 +1,8 @@ +import os, environ + + +environ.Env.read_env(os.path.join(".env")) + +env = environ.Env( + +) \ No newline at end of file diff --git a/config/settings/base.py b/config/settings/base.py new file mode 100644 index 0000000..23d5052 --- /dev/null +++ b/config/settings/base.py @@ -0,0 +1,99 @@ +from pathlib import Path +from config.env import env + +BASE_DIR = Path(__file__).resolve().parent.parent.parent + + +SECRET_KEY = env.str('SECRET_KEY') + +DEBUG = env.bool('DEBUG') + +ALLOWED_HOSTS = env.list('ALLOWED_HOSTS') + + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'config.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'config.wsgi.application' + + + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.postgresql', + 'NAME': env.str('POSTGRES_DB'), + 'USER': env.str('POSTGRES_USER'), + 'PASSWORD': env.str('POSTGRES_PASSWORD'), + 'HOST': env.str('POSTGRES_HOST'), + 'PORT': env.str('POSTGRES_PORT'), + } +} + + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +LANGUAGE_CODE = 'uz' + +TIME_ZONE = 'Asia/Tashkent' + +USE_I18N = True + +USE_TZ = False + + +STATIC_URL = 'static/' +STATIC_ROOT = BASE_DIR / 'resources/static' + +MEDIA_URL = 'media/' +MEDIA_ROOT = BASE_DIR / 'resources/media' + +DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' + +from config.conf import * \ No newline at end of file diff --git a/config/settings/local.py b/config/settings/local.py new file mode 100644 index 0000000..e69de29 diff --git a/config/settings/prod.py b/config/settings/prod.py new file mode 100644 index 0000000..e69de29 diff --git a/config/settings/test.py b/config/settings/test.py new file mode 100644 index 0000000..e69de29 diff --git a/config/urls.py b/config/urls.py new file mode 100644 index 0000000..de36fa2 --- /dev/null +++ b/config/urls.py @@ -0,0 +1,32 @@ +from django.contrib import admin +from django.urls import path, include +from django.conf import settings +from django.conf.urls.static import static + +from rest_framework.permissions import IsAdminUser +from drf_yasg.views import get_schema_view +from drf_yasg import openapi + +schema_view = get_schema_view( + openapi.Info( + title="Horeca 360 API", + default_version='v1', + description="Test description", + terms_of_service="https://www.google.com/policies/terms/", + contact=openapi.Contact(email="xoliqberdiyevbehru12@gmail.com"), + license=openapi.License(name="Felix IT Solutions License"), + ), + public=True, + permission_classes=[IsAdminUser] +) + + +urlpatterns = [ + path('admin/', admin.site.urls), + + + path('', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'), +] + +urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) +urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) \ No newline at end of file diff --git a/config/wsgi.py b/config/wsgi.py new file mode 100644 index 0000000..c46f145 --- /dev/null +++ b/config/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for config project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/5.2/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings.base') + +application = get_wsgi_application() diff --git a/core/apps/accounts/__init__.py b/core/apps/accounts/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/core/apps/accounts/admin.py b/core/apps/accounts/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/core/apps/accounts/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/core/apps/accounts/apps.py b/core/apps/accounts/apps.py new file mode 100644 index 0000000..3e3c765 --- /dev/null +++ b/core/apps/accounts/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class AccountsConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'accounts' diff --git a/core/apps/accounts/migrations/__init__.py b/core/apps/accounts/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/core/apps/accounts/models.py b/core/apps/accounts/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/core/apps/accounts/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/core/apps/accounts/tests.py b/core/apps/accounts/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/core/apps/accounts/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/core/apps/accounts/views.py b/core/apps/accounts/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/core/apps/accounts/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/core/apps/orders/__init__.py b/core/apps/orders/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/core/apps/orders/admin.py b/core/apps/orders/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/core/apps/orders/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/core/apps/orders/apps.py b/core/apps/orders/apps.py new file mode 100644 index 0000000..8ae0375 --- /dev/null +++ b/core/apps/orders/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class OrdersConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'orders' diff --git a/core/apps/orders/migrations/__init__.py b/core/apps/orders/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/core/apps/orders/models.py b/core/apps/orders/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/core/apps/orders/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/core/apps/orders/tests.py b/core/apps/orders/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/core/apps/orders/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/core/apps/orders/views.py b/core/apps/orders/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/core/apps/orders/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/core/apps/products/__init__.py b/core/apps/products/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/core/apps/products/admin.py b/core/apps/products/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/core/apps/products/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/core/apps/products/apps.py b/core/apps/products/apps.py new file mode 100644 index 0000000..145a2ac --- /dev/null +++ b/core/apps/products/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class ProductsConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'products' diff --git a/core/apps/products/migrations/__init__.py b/core/apps/products/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/core/apps/products/models.py b/core/apps/products/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/core/apps/products/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/core/apps/products/tests.py b/core/apps/products/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/core/apps/products/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/core/apps/products/views.py b/core/apps/products/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/core/apps/products/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/core/apps/shared/__init__.py b/core/apps/shared/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/core/apps/shared/admin.py b/core/apps/shared/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/core/apps/shared/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/core/apps/shared/apps.py b/core/apps/shared/apps.py new file mode 100644 index 0000000..87efe00 --- /dev/null +++ b/core/apps/shared/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class SharedConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'shared' diff --git a/core/apps/shared/migrations/__init__.py b/core/apps/shared/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/core/apps/shared/models.py b/core/apps/shared/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/core/apps/shared/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/core/apps/shared/tests.py b/core/apps/shared/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/core/apps/shared/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/core/apps/shared/views.py b/core/apps/shared/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/core/apps/shared/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..ef9235c --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,52 @@ +networks: + horeca: + driver: bridge + +volumes: + pg_data: null + +services: + nginx: + networks: + - horeca + 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: + - horeca + build: + context: . + dockerfile: ./docker/Dockerfile.web + command: ${COMMAND:-sh ./resources/scripts/entrypoint.sh} + environment: + - PYTHONPYCACHEPREFIX=/var/cache/pycache + volumes: + - './:/code' + depends_on: + - db + - redis + + db: + image: postgres:17 + networks: + - horeca + environment: + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} + POSTGRES_USER: ${POSTGRES_USER} + POSTGRES_DB: ${POSTGRES_DB} + volumes: + - pg_data:/var/lib/postgresql/data + + redis: + networks: + - horeca + image: redis \ No newline at end of file diff --git a/docker/Dockerfile.nginx b/docker/Dockerfile.nginx new file mode 100644 index 0000000..42738e3 --- /dev/null +++ b/docker/Dockerfile.nginx @@ -0,0 +1,3 @@ +FROM nginx:alpine + +COPY ./resources/layout/nginx.conf /etc/nginx/nginx.conf \ No newline at end of file diff --git a/docker/Dockerfile.web b/docker/Dockerfile.web new file mode 100644 index 0000000..bad8b32 --- /dev/null +++ b/docker/Dockerfile.web @@ -0,0 +1,26 @@ +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++ \ + make \ + 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"] \ No newline at end of file diff --git a/manage.py b/manage.py new file mode 100755 index 0000000..6361598 --- /dev/null +++ b/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" +import os +import sys + + +def main(): + """Run administrative tasks.""" + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings.base') + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) + + +if __name__ == '__main__': + main() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..cf1e5ed --- /dev/null +++ b/requirements.txt @@ -0,0 +1,11 @@ +Django==5.2 +django-environ==0.12.0 +gunicorn +uvicorn +django-cors-headers +djangorestframework +djangorestframework-simplejwt +drf_yasg +redis +django-redis +psycopg2-binary \ No newline at end of file diff --git a/resources/layout/Dockerfile.alpine b/resources/layout/Dockerfile.alpine new file mode 100644 index 0000000..7d6e714 --- /dev/null +++ b/resources/layout/Dockerfile.alpine @@ -0,0 +1,13 @@ +FROM python:3.13-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"] \ No newline at end of file diff --git a/resources/layout/Dockerfile.nginx b/resources/layout/Dockerfile.nginx new file mode 100644 index 0000000..42738e3 --- /dev/null +++ b/resources/layout/Dockerfile.nginx @@ -0,0 +1,3 @@ +FROM nginx:alpine + +COPY ./resources/layout/nginx.conf /etc/nginx/nginx.conf \ No newline at end of file diff --git a/resources/layout/nginx.conf b/resources/layout/nginx.conf new file mode 100644 index 0000000..6831a45 --- /dev/null +++ b/resources/layout/nginx.conf @@ -0,0 +1,52 @@ +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 block for handling requests + 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 /static/ { + alias /usr/share/nginx/html/resources/static/; + } + + location /media/ { + alias /usr/share/nginx/html/resources/media/; + } + } +} \ No newline at end of file diff --git a/resources/scripts/backup.sh b/resources/scripts/backup.sh new file mode 100644 index 0000000..5bac180 --- /dev/null +++ b/resources/scripts/backup.sh @@ -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 \ No newline at end of file diff --git a/resources/scripts/entrypoint-server.sh b/resources/scripts/entrypoint-server.sh new file mode 100644 index 0000000..b1c9cb5 --- /dev/null +++ b/resources/scripts/entrypoint-server.sh @@ -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 $? \ No newline at end of file diff --git a/resources/scripts/entrypoint.sh b/resources/scripts/entrypoint.sh new file mode 100644 index 0000000..03b69ef --- /dev/null +++ b/resources/scripts/entrypoint.sh @@ -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 core --reload-dir config + +exit $? \ No newline at end of file