52 lines
1.2 KiB
Docker
52 lines
1.2 KiB
Docker
# ============================================================
|
|
# Weibo-HotSign Backend Multi-Stage Dockerfile
|
|
# 构建目标: auth-service, api-service
|
|
# ============================================================
|
|
|
|
# ---- 基础层 ----
|
|
FROM python:3.11-slim AS base
|
|
|
|
WORKDIR /app
|
|
|
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
gcc default-libmysqlclient-dev curl \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
COPY requirements.txt .
|
|
RUN pip install --no-cache-dir -r requirements.txt
|
|
|
|
# 复制共享模块
|
|
COPY shared/ ./shared/
|
|
|
|
RUN groupadd -r appuser && useradd -r -g appuser appuser
|
|
|
|
|
|
# ---- Auth Service ----
|
|
FROM base AS auth-service
|
|
|
|
COPY auth_service/ ./auth_service/
|
|
|
|
ENV PYTHONPATH=/app
|
|
USER appuser
|
|
EXPOSE 8001
|
|
|
|
HEALTHCHECK --interval=30s --timeout=10s --retries=3 \
|
|
CMD curl -f http://localhost:8001/health || exit 1
|
|
|
|
CMD ["uvicorn", "auth_service.app.main:app", "--host", "0.0.0.0", "--port", "8001"]
|
|
|
|
|
|
# ---- API Service ----
|
|
FROM base AS api-service
|
|
|
|
COPY api_service/ ./api_service/
|
|
|
|
ENV PYTHONPATH=/app
|
|
USER appuser
|
|
EXPOSE 8000
|
|
|
|
HEALTHCHECK --interval=30s --timeout=10s --retries=3 \
|
|
CMD curl -f http://localhost:8000/health || exit 1
|
|
|
|
CMD ["uvicorn", "api_service.app.main:app", "--host", "0.0.0.0", "--port", "8000"]
|