feat: implement CI/CD pipeline with Gitea Actions
- Add Gitea Actions workflow with 4 stages: lint, test, build, push - Configure ruff linting and formatting checks - Set up Django tests with PostgreSQL and Redis services - Implement Docker image building for web and celery services - Add requirements.txt and requirements-dev.txt generation - Fix ipdb compatibility issues in test runner - Update ruff configuration for Django compatibility - Add comprehensive CI/CD documentation
This commit is contained in:
@@ -36,6 +36,7 @@ app.conf.beat_schedule = {
|
||||
|
||||
app.conf.timezone = "UTC"
|
||||
|
||||
|
||||
@app.task(bind=True)
|
||||
def debug_task(self):
|
||||
print(f"Request: {self.request!r}")
|
||||
|
||||
@@ -1,23 +1,27 @@
|
||||
from django.test.runner import DiscoverRunner
|
||||
import sys
|
||||
|
||||
from django.test.runner import DiscoverRunner
|
||||
|
||||
|
||||
class CustomTestRunner(DiscoverRunner):
|
||||
"""Custom test runner that avoids ipdb import issues"""
|
||||
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
# Отключаем использование ipdb
|
||||
import os
|
||||
os.environ['PYTHONBREAKPOINT'] = 'pdb.set_trace'
|
||||
|
||||
os.environ["PYTHONBREAKPOINT"] = "pdb.set_trace"
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
|
||||
def run_tests(self, test_labels, extra_tests=None, **kwargs):
|
||||
# Проверяем, что ipdb не будет импортирован
|
||||
sys.modules['ipdb'] = None
|
||||
|
||||
# Создаем mock-модуль вместо None
|
||||
mock_ipdb = type("MockModule", (), {"__getattr__": lambda s, n: None})()
|
||||
sys.modules["ipdb"] = mock_ipdb
|
||||
|
||||
try:
|
||||
return super().run_tests(test_labels, extra_tests, **kwargs)
|
||||
finally:
|
||||
# Восстанавливаем модуль если был
|
||||
if 'ipdb' in sys.modules:
|
||||
del sys.modules['ipdb']
|
||||
if "ipdb" in sys.modules:
|
||||
del sys.modules["ipdb"]
|
||||
|
||||
@@ -4,8 +4,8 @@ Base settings for Django project.
|
||||
Generated by 'django-admin startproject' using Django 3.2.25.
|
||||
"""
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
from decouple import Config, RepositoryEnv
|
||||
|
||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||
@@ -17,19 +17,24 @@ if ENV_FILE.exists():
|
||||
config = Config(RepositoryEnv(str(ENV_FILE)))
|
||||
else:
|
||||
from decouple import AutoConfig
|
||||
|
||||
config = AutoConfig(search_path=BASE_DIR)
|
||||
|
||||
|
||||
# Helper function for getting config values
|
||||
def get_env(key, default=None):
|
||||
return config(key, default=default)
|
||||
|
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = get_env("SECRET_KEY", "django-insecure-development-key-change-in-production")
|
||||
SECRET_KEY = get_env(
|
||||
"SECRET_KEY", "django-insecure-development-key-change-in-production"
|
||||
)
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = get_env("DEBUG", True)
|
||||
if isinstance(DEBUG, str):
|
||||
DEBUG = DEBUG.lower() in ('true', '1', 'yes')
|
||||
DEBUG = DEBUG.lower() in ("true", "1", "yes")
|
||||
|
||||
ALLOWED_HOSTS = get_env("ALLOWED_HOSTS", "localhost,127.0.0.1")
|
||||
if isinstance(ALLOWED_HOSTS, str):
|
||||
@@ -43,17 +48,14 @@ INSTALLED_APPS = [
|
||||
"django.contrib.sessions",
|
||||
"django.contrib.messages",
|
||||
"django.contrib.staticfiles",
|
||||
|
||||
# Third-party apps
|
||||
"rest_framework",
|
||||
"corsheaders",
|
||||
"django_celery_beat",
|
||||
"django_celery_results",
|
||||
"drf_yasg",
|
||||
|
||||
# Local apps
|
||||
"apps.user",
|
||||
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
@@ -99,11 +101,10 @@ DATABASES = {
|
||||
"OPTIONS": {
|
||||
"charset": "utf8mb4",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
|
||||
# Password validation
|
||||
AUTH_PASSWORD_VALIDATORS = [
|
||||
{
|
||||
@@ -175,26 +176,24 @@ SIMPLE_JWT = {
|
||||
"ISSUER": None,
|
||||
"JWK_URL": None,
|
||||
"LEEWAY": 0,
|
||||
|
||||
"AUTH_HEADER_TYPES": ("Bearer",),
|
||||
"AUTH_HEADER_NAME": "HTTP_AUTHORIZATION",
|
||||
"USER_ID_FIELD": "id",
|
||||
"USER_ID_CLAIM": "user_id",
|
||||
"USER_AUTHENTICATION_RULE": "rest_framework_simplejwt.authentication.default_user_authentication_rule",
|
||||
|
||||
"AUTH_TOKEN_CLASSES": ("rest_framework_simplejwt.tokens.AccessToken",),
|
||||
"TOKEN_TYPE_CLAIM": "token_type",
|
||||
"TOKEN_USER_CLASS": "rest_framework_simplejwt.models.TokenUser",
|
||||
|
||||
"JTI_CLAIM": "jti",
|
||||
|
||||
"SLIDING_TOKEN_REFRESH_EXP_CLAIM": "refresh_exp",
|
||||
"SLIDING_TOKEN_LIFETIME": timedelta(minutes=5),
|
||||
"SLIDING_TOKEN_REFRESH_LIFETIME": timedelta(days=1),
|
||||
}
|
||||
|
||||
# CORS settings
|
||||
CORS_ALLOWED_ORIGINS = get_env("CORS_ALLOWED_ORIGINS", "http://localhost:3000,http://127.0.0.1:3000")
|
||||
CORS_ALLOWED_ORIGINS = get_env(
|
||||
"CORS_ALLOWED_ORIGINS", "http://localhost:3000,http://127.0.0.1:3000"
|
||||
)
|
||||
if isinstance(CORS_ALLOWED_ORIGINS, str):
|
||||
CORS_ALLOWED_ORIGINS = CORS_ALLOWED_ORIGINS.split(",")
|
||||
CORS_ALLOW_CREDENTIALS = True
|
||||
@@ -236,6 +235,8 @@ LOGGING = {
|
||||
"level": "INFO",
|
||||
"propagate": False,
|
||||
},
|
||||
|
||||
},
|
||||
}
|
||||
|
||||
# Test runner configuration
|
||||
TEST_RUNNER = "config.custom_test_runner.CustomTestRunner"
|
||||
|
||||
@@ -41,6 +41,6 @@ CACHES = {
|
||||
"LOCATION": "redis://127.0.0.1:6379/1",
|
||||
"OPTIONS": {
|
||||
"CLIENT_CLASS": "django_redis.client.DefaultClient",
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,8 +57,8 @@ CACHES = {
|
||||
"CONNECTION_POOL_KWARGS": {
|
||||
"max_connections": 20,
|
||||
"retry_on_timeout": True,
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ LOGGING = {
|
||||
"level": "INFO",
|
||||
"class": "logging.handlers.RotatingFileHandler",
|
||||
"filename": "/var/log/django/app.log",
|
||||
"maxBytes": 1024*1024*15, # 15MB
|
||||
"maxBytes": 1024 * 1024 * 15, # 15MB
|
||||
"backupCount": 10,
|
||||
"formatter": "verbose",
|
||||
},
|
||||
|
||||
@@ -8,9 +8,9 @@ from django.conf import settings
|
||||
from django.conf.urls.static import static
|
||||
from django.contrib import admin
|
||||
from django.urls import include, path
|
||||
from rest_framework import permissions
|
||||
from drf_yasg.views import get_schema_view
|
||||
from drf_yasg import openapi
|
||||
from drf_yasg.views import get_schema_view
|
||||
from rest_framework import permissions
|
||||
|
||||
# Swagger schema view
|
||||
schema_view = get_schema_view(
|
||||
@@ -31,7 +31,11 @@ urlpatterns = [
|
||||
path("api/users/", include("apps.user.urls")),
|
||||
path("api-auth/", include("rest_framework.urls")),
|
||||
# Swagger documentation
|
||||
path("swagger/", schema_view.with_ui("swagger", cache_timeout=0), name="schema-swagger-ui"),
|
||||
path(
|
||||
"swagger/",
|
||||
schema_view.with_ui("swagger", cache_timeout=0),
|
||||
name="schema-swagger-ui",
|
||||
),
|
||||
path("redoc/", schema_view.with_ui("redoc", cache_timeout=0), name="schema-redoc"),
|
||||
]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user