From 098dce9fdbcff96ed628ecc8739ced4e0fe987bc Mon Sep 17 00:00:00 2001 From: A'zamov Samandar Date: Sat, 19 Apr 2025 17:45:12 +0500 Subject: [PATCH] `dockerfile, api: Yangi loyiha uchun Dockerfile va Django API modullarini qo'shish. Kiritilgan fayllar: requirements.txt, admin.py, models.py, tests.py va boshqalar.` --- template/Dockerfile | 13 +++ template/api/__init__.py | 0 template/api/admin.py | 3 + template/api/apps.py | 6 ++ template/api/migrations/__init__.py | 0 template/api/models.py | 3 + template/api/tests.py | 3 + template/api/urls.py | 6 ++ template/api/views.py | 7 ++ template/config/__init__.py | 0 template/config/asgi.py | 16 ++++ template/config/settings.py | 126 ++++++++++++++++++++++++++++ template/config/urls.py | 7 ++ template/config/wsgi.py | 16 ++++ template/db.sqlite3 | Bin 0 -> 131072 bytes template/entrypoint.sh | 5 ++ template/manage.py | 22 +++++ template/requirements.txt | 2 + 18 files changed, 235 insertions(+) create mode 100644 template/Dockerfile create mode 100644 template/api/__init__.py create mode 100644 template/api/admin.py create mode 100644 template/api/apps.py create mode 100644 template/api/migrations/__init__.py create mode 100644 template/api/models.py create mode 100644 template/api/tests.py create mode 100644 template/api/urls.py create mode 100644 template/api/views.py create mode 100644 template/config/__init__.py create mode 100644 template/config/asgi.py create mode 100644 template/config/settings.py create mode 100644 template/config/urls.py create mode 100644 template/config/wsgi.py create mode 100644 template/db.sqlite3 create mode 100644 template/entrypoint.sh create mode 100755 template/manage.py create mode 100644 template/requirements.txt diff --git a/template/Dockerfile b/template/Dockerfile new file mode 100644 index 0000000..7d6e714 --- /dev/null +++ b/template/Dockerfile @@ -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/template/api/__init__.py b/template/api/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/template/api/admin.py b/template/api/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/template/api/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/template/api/apps.py b/template/api/apps.py new file mode 100644 index 0000000..878e7d5 --- /dev/null +++ b/template/api/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class ApiConfig(AppConfig): + default_auto_field = "django.db.models.BigAutoField" + name = "api" diff --git a/template/api/migrations/__init__.py b/template/api/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/template/api/models.py b/template/api/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/template/api/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/template/api/tests.py b/template/api/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/template/api/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/template/api/urls.py b/template/api/urls.py new file mode 100644 index 0000000..108460e --- /dev/null +++ b/template/api/urls.py @@ -0,0 +1,6 @@ +from django.urls import path +from .views import HealthView + +urlpatterns = [ + path("health/", HealthView.as_view()) +] \ No newline at end of file diff --git a/template/api/views.py b/template/api/views.py new file mode 100644 index 0000000..3877edb --- /dev/null +++ b/template/api/views.py @@ -0,0 +1,7 @@ +from rest_framework.views import APIView +from rest_framework.response import Response + + +class HealthView(APIView): + def get(self, *args, **kwargs): + return Response(data={"detail": "OK"}) \ No newline at end of file diff --git a/template/config/__init__.py b/template/config/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/template/config/asgi.py b/template/config/asgi.py new file mode 100644 index 0000000..19b90e3 --- /dev/null +++ b/template/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.1/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings") + +application = get_asgi_application() diff --git a/template/config/settings.py b/template/config/settings.py new file mode 100644 index 0000000..bb269d2 --- /dev/null +++ b/template/config/settings.py @@ -0,0 +1,126 @@ +""" +Django settings for config project. + +Generated by 'django-admin startproject' using Django 5.1.3. + +For more information on this file, see +https://docs.djangoproject.com/en/5.1/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/5.1/ref/settings/ +""" + +from pathlib import Path + +# Build paths inside the project like this: BASE_DIR / 'subdir'. +BASE_DIR = Path(__file__).resolve().parent.parent + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = "django-insecure-iv-iwjd(4d%g5&fyo*+xybkjhaik+r@3j0$h91u0^$u4fwuh53" + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [ + "*" +] + + +# Application definition + +INSTALLED_APPS = [ + "django.contrib.admin", + "django.contrib.auth", + "django.contrib.contenttypes", + "django.contrib.sessions", + "django.contrib.messages", + "django.contrib.staticfiles", + "api", +] + +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.debug", + "django.template.context_processors.request", + "django.contrib.auth.context_processors.auth", + "django.contrib.messages.context_processors.messages", + ], + }, + }, +] + +WSGI_APPLICATION = "config.wsgi.application" + + +# Database +# https://docs.djangoproject.com/en/5.1/ref/settings/#databases + +DATABASES = { + "default": { + "ENGINE": "django.db.backends.sqlite3", + "NAME": BASE_DIR / "db.sqlite3", + } +} + + +# Password validation +# https://docs.djangoproject.com/en/5.1/ref/settings/#auth-password-validators + +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", + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/5.1/topics/i18n/ + +LANGUAGE_CODE = "en-us" + +TIME_ZONE = "UTC" + +USE_I18N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/5.1/howto/static-files/ + +STATIC_URL = "static/" + +# Default primary key field type +# https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" diff --git a/template/config/urls.py b/template/config/urls.py new file mode 100644 index 0000000..de9a619 --- /dev/null +++ b/template/config/urls.py @@ -0,0 +1,7 @@ +from django.contrib import admin +from django.urls import path, include + +urlpatterns = [ + path("payment/api/", include("api.urls")), + path("payment/admin/", admin.site.urls), +] diff --git a/template/config/wsgi.py b/template/config/wsgi.py new file mode 100644 index 0000000..b2bb19f --- /dev/null +++ b/template/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.1/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings") + +application = get_wsgi_application() diff --git a/template/db.sqlite3 b/template/db.sqlite3 new file mode 100644 index 0000000000000000000000000000000000000000..ebf68870804870e6afeb169ec6ea61b49e9775ea GIT binary patch literal 131072 zcmeI5TWlNIdB-{8kQ617M^}#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z~Rv=PMuGzhc`btG_wzNupr(APJ z8)*TR^2$xExks_>&fyF7dd1nx_};@wTZb58$$M;7FIQ}l$xOOOBp1@sx3^>kl3Z}ZV#Efu{diB6SDjjsY+@QJ-5f*R15Tk|l<(`FgJJzoi>$K=xYiX^=y9Qs= zNN%TdStH$9e6j5!W{WzX1h8`t^x{~pu&w!ca2=LrqMM5WJ-GubT#qSHX(~T^5)rq zl1fSYdFLtBS#p4e`QD}v*YcFdFP6)DN8R^%QZgVc2{hRnQYo9 z=vlYH8M9iwS1kvZ?}6Pl<5lMqHD73tx6hvmC>kvyzvb*HUEBWAoGuiNHKX8`cKQ%$ z&IaT2V$t+-utZmhSp4HZds;js^odnxPv}Z@D>^%{4|L6s)dA{-dq%Ov!I>9Wos*)u zyJ76oBC2&(O}fS_KPS~|+IB_XiA9@Ly;7m)lcIaIW_gEBN8Ph%^zzk>%dhjn;I#ko z4@MJlJ{8`jbxT95(uJ1O;H{ksC`GEwox>_)($@5R#?VWu<2ep@y?^A$)o}YfN(Ia^G-o`V zrKdcC>(c(}QMLC}UQ^S0wvbIF?TZZI+g+VGvpNH=HwM~w=g%QW`+h1)Y$KupMEp(6rx89B&?@!{J=t@}sKkN<*`5*uS zAOHd&00JNY0w4eaAOHd&@ca|N{r~gdhNuAufB*=900@8p2!H?xfB*=900OhhS2YJ<7cJ858=+82YKH#$$f}@0oZ?Rf1a( z009sH0T2KI5C8!X009sH0T2LzXMzBp|9>W$0U|&E1V8`;KmY_l00ck)1V8`;K;Wqo i!2SPI#S7;k00JNY0w4eaAOHd&00JNY0wC~A5cq$?{Pev5 literal 0 HcmV?d00001 diff --git a/template/entrypoint.sh b/template/entrypoint.sh new file mode 100644 index 0000000..b4bce27 --- /dev/null +++ b/template/entrypoint.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +python3 manage.py collectstatus --no-input +python3 manage.py migrate --no-input +python3 manage.py runserver 0.0.0.0:8000 \ No newline at end of file diff --git a/template/manage.py b/template/manage.py new file mode 100755 index 0000000..d28672e --- /dev/null +++ b/template/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") + 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/template/requirements.txt b/template/requirements.txt new file mode 100644 index 0000000..ddd6f0f --- /dev/null +++ b/template/requirements.txt @@ -0,0 +1,2 @@ +django==5.1.3 +djangorestframework==3.15.2 \ No newline at end of file