diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..94b09d1 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,24 @@ +.git +.gitignore +.env +.env.example +.vscode +.idea +venv/ +.venv/ +__pycache__/ +*.pyc +*.pyo +*.egg-info/ +dist/ +build/ +*.log +*.sqlite3 +media/ +staticfiles/ +.DS_Store +k8s/ +.gitea/ +docs/ +CLAUDE.md +README.md diff --git a/Dockerfile b/Dockerfile index b6dc1ff..918ab4b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -28,4 +28,4 @@ COPY . /app/ EXPOSE 8000 # Run entrypoint -CMD ["gunicorn", "--bind", "0.0.0.0:8000", "config.wsgi:application"] +CMD ["gunicorn", "--bind", "0.0.0.0:8000", "--workers", "2", "--timeout", "120", "--access-logfile", "-", "--error-logfile", "-", "config.wsgi:application"] diff --git a/config/urls.py b/config/urls.py index eb93305..2f907ce 100644 --- a/config/urls.py +++ b/config/urls.py @@ -7,8 +7,13 @@ URL configuration for RTC_DEMO project. """ from django.contrib import admin from django.urls import path, include +from django.http import JsonResponse from drf_spectacular.views import SpectacularAPIView, SpectacularSwaggerView, SpectacularRedocView + +def health_check(request): + return JsonResponse({"status": "ok"}) + # ============ App端路由 (普通用户,手机一键登录) ============ app_api_patterns = [ path('', include('apps.users.urls')), @@ -37,6 +42,9 @@ admin_api_patterns = [ ] urlpatterns = [ + # Health check (no auth, for K8s probes) + path('healthz/', health_check), + # Django Admin path('django-admin/', admin.site.urls), diff --git a/k8s/backend-deployment-dev.yaml b/k8s/backend-deployment-dev.yaml index a486430..bb3c818 100644 --- a/k8s/backend-deployment-dev.yaml +++ b/k8s/backend-deployment-dev.yaml @@ -68,6 +68,22 @@ spec: value: "https://qiyuan-log-center-api.airlabs.art" - name: LOG_CENTER_ENABLED value: "true" + livenessProbe: + httpGet: + path: /healthz/ + port: 8000 + initialDelaySeconds: 30 + periodSeconds: 10 + timeoutSeconds: 5 + failureThreshold: 3 + readinessProbe: + httpGet: + path: /healthz/ + port: 8000 + initialDelaySeconds: 15 + periodSeconds: 5 + timeoutSeconds: 3 + failureThreshold: 3 resources: requests: memory: "256Mi" diff --git a/k8s/backend-deployment-prod.yaml b/k8s/backend-deployment-prod.yaml index 162b032..a9cae7d 100644 --- a/k8s/backend-deployment-prod.yaml +++ b/k8s/backend-deployment-prod.yaml @@ -76,6 +76,22 @@ spec: value: "https://qiyuan-log-center-api.airlabs.art" - name: LOG_CENTER_ENABLED value: "true" + livenessProbe: + httpGet: + path: /healthz/ + port: 8000 + initialDelaySeconds: 30 + periodSeconds: 10 + timeoutSeconds: 5 + failureThreshold: 3 + readinessProbe: + httpGet: + path: /healthz/ + port: 8000 + initialDelaySeconds: 15 + periodSeconds: 5 + timeoutSeconds: 3 + failureThreshold: 3 resources: requests: memory: "256Mi"