baseline: 批次A-D 成果 + membership 半成品(测试红)
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
# Build the Vue app from source rather than relying on a host-generated directory.
|
||||
FROM node:20-alpine AS frontend-builder
|
||||
|
||||
WORKDIR /frontend
|
||||
COPY frontend/package*.json ./
|
||||
RUN npm ci
|
||||
COPY frontend/ ./
|
||||
RUN npm run build
|
||||
|
||||
FROM python:3.12-slim
|
||||
|
||||
ENV PYTHONDONTWRITEBYTECODE=1 \
|
||||
PYTHONUNBUFFERED=1 \
|
||||
PIP_DISABLE_PIP_VERSION_CHECK=1 \
|
||||
DJANGO_SETTINGS_MODULE=config.settings.prod
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
libpq-dev gcc curl && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Keep the runtime dependency set in one lock file used by local and Docker installs.
|
||||
COPY backend/requirements.txt /tmp/requirements.txt
|
||||
RUN pip install --no-cache-dir -r /tmp/requirements.txt
|
||||
|
||||
COPY backend/ /app/
|
||||
COPY --from=frontend-builder /frontend/dist/ /app/frontend_dist/
|
||||
|
||||
RUN mkdir -p /app/staticfiles /app/media
|
||||
|
||||
EXPOSE 8000
|
||||
|
||||
HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \
|
||||
CMD curl -fsS http://127.0.0.1:8000/api/v1/ping/ || exit 1
|
||||
|
||||
CMD ["sh", "infra/scripts/run_prod_granian.sh"]
|
||||
@@ -0,0 +1,42 @@
|
||||
services:
|
||||
backend:
|
||||
build:
|
||||
# Compose file is backend/infra/docker; use the repository root so the
|
||||
# image can build the frontend and copy the backend in one reproducible build.
|
||||
context: ../../..
|
||||
dockerfile: backend/infra/docker/Dockerfile.backend
|
||||
image: dealerhub-backend:latest
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
DJANGO_SETTINGS_MODULE: config.settings.prod
|
||||
DJANGO_SECRET_KEY: ${DJANGO_SECRET_KEY:?required}
|
||||
DATABASE_URL: postgres://dealerhub:${POSTGRES_PASSWORD}@db:5432/dealerhub
|
||||
GRANIAN_WORKERS: "4"
|
||||
depends_on:
|
||||
db:
|
||||
condition: service_healthy
|
||||
volumes:
|
||||
- media:/app/media
|
||||
- staticfiles:/app/staticfiles
|
||||
ports:
|
||||
- "8000:8000"
|
||||
|
||||
db:
|
||||
image: postgres:16-alpine
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
POSTGRES_DB: dealerhub
|
||||
POSTGRES_USER: dealerhub
|
||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?required}
|
||||
volumes:
|
||||
- pgdata:/var/lib/postgresql/data
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U dealerhub"]
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 10
|
||||
|
||||
volumes:
|
||||
pgdata:
|
||||
media:
|
||||
staticfiles:
|
||||
@@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env bash
|
||||
# 开发环境启动脚本:SQLite + Granian + 自动重载
|
||||
set -euo pipefail
|
||||
|
||||
# This script lives in backend/infra/scripts; manage.py lives in backend/.
|
||||
SCRIPT_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)"
|
||||
cd "$SCRIPT_DIR/../.."
|
||||
|
||||
export DJANGO_SETTINGS_MODULE=config.settings.dev
|
||||
|
||||
echo "[dealerhub-dev] Running migrations..."
|
||||
python manage.py migrate --noinput
|
||||
|
||||
echo "[dealerhub-dev] Starting Granian ASGI on 0.0.0.0:8000..."
|
||||
exec granian config.asgi:application \
|
||||
--interface asgi \
|
||||
--host 0.0.0.0 \
|
||||
--port 8000 \
|
||||
--reload \
|
||||
--log-level info
|
||||
@@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env bash
|
||||
# 生产环境启动脚本:PostgreSQL + Granian (多 worker)
|
||||
# WORKDIR in Dockerfile = /app
|
||||
set -e
|
||||
cd /app
|
||||
|
||||
export DJANGO_SETTINGS_MODULE=config.settings.prod
|
||||
|
||||
echo "[dealerhub-prod] Running migrations..."
|
||||
python manage.py migrate --noinput
|
||||
|
||||
echo "[dealerhub-prod] Collecting static files..."
|
||||
python manage.py collectstatic --noinput
|
||||
|
||||
WORKERS="${GRANIAN_WORKERS:-4}"
|
||||
RUNTIME_THREADS="${GRANIAN_RUNTIME_THREADS:-1}"
|
||||
|
||||
echo "[dealerhub-prod] Starting Granian ASGI (workers=$WORKERS, runtime-threads=$RUNTIME_THREADS)..."
|
||||
exec granian config.asgi:application \
|
||||
--interface asgi \
|
||||
--host 0.0.0.0 \
|
||||
--port 8000 \
|
||||
--workers "$WORKERS" \
|
||||
--runtime-threads "$RUNTIME_THREADS" \
|
||||
--log-level info
|
||||
Reference in New Issue
Block a user