|
| 1 | +ARG SERVICE_TYPE=fastapi_server |
| 2 | + |
| 3 | +# ===== Build Stage ===== |
1 | 4 | FROM python:3.10-slim AS builder |
2 | 5 | COPY --from=ghcr.io/astral-sh/uv:0.6.2 /uv /uvx /bin/ |
3 | 6 |
|
4 | | -RUN sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list.d/debian.sources && \ |
5 | | - apt-get update \ |
6 | | - && apt-get install -y --no-install-recommends gcc python3-dev\ |
| 7 | +# Install dependencies for building Python packages |
| 8 | +RUN sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list.d/debian.sources \ |
| 9 | + && apt-get update \ |
| 10 | + && apt-get install -y --no-install-recommends gcc python3-dev \ |
7 | 11 | && rm -rf /var/lib/apt/lists/* |
8 | 12 |
|
9 | | -ENV UV_COMPILE_BYTECODE=1 |
10 | | -ENV UV_NO_CACHE=1 |
11 | | -ENV UV_LINK_MODE=copy |
12 | | -ENV UV_PROJECT_ENVIRONMENT=/usr/local |
| 13 | +# Configure uv environment |
| 14 | +ENV UV_COMPILE_BYTECODE=1 \ |
| 15 | + UV_NO_CACHE=1 \ |
| 16 | + UV_LINK_MODE=copy \ |
| 17 | + UV_PROJECT_ENVIRONMENT=/usr/local |
| 18 | + |
| 19 | +# COPY backend/plugin/casbin/requirements.txt plugin_casbin_requirements.txt |
13 | 20 |
|
14 | | -# Install dependencies |
| 21 | +# Install dependencies using uv (with cache optimization) |
15 | 22 | RUN --mount=type=cache,target=/root/.cache/uv \ |
16 | 23 | --mount=type=bind,source=backend/uv.lock,target=uv.lock \ |
17 | 24 | --mount=type=bind,source=backend/pyproject.toml,target=pyproject.toml \ |
18 | | - uv sync --frozen --no-install-project --no-default-groups --group server |
| 25 | + uv sync --frozen --no-install-project --no-default-groups --group server \ |
| 26 | + # && uv pip install --system -r plugin_casbin_requirements.txt |
19 | 27 |
|
20 | 28 |
|
21 | | -FROM python:3.10-slim |
22 | | - |
| 29 | +# ===== Runtime Base Image ===== |
| 30 | +FROM python:3.10-slim AS runtime |
23 | 31 | SHELL ["/bin/bash", "-c"] |
24 | | - |
25 | 32 | ENV TZ="Asia/Shanghai" |
26 | 33 |
|
27 | | -WORKDIR /fba |
28 | | - |
29 | | -RUN sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list.d/debian.sources && \ |
30 | | - apt-get update \ |
| 34 | +# Install runtime dependencies |
| 35 | +RUN sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list.d/debian.sources \ |
| 36 | + && apt-get update \ |
31 | 37 | && apt-get install -y --no-install-recommends supervisor procps iproute2 \ |
32 | | - && rm -rf /var/lib/apt/lists/* \ |
33 | | - && mkdir -p /var/log/fastapi_server \ |
34 | | - && mkdir -p /var/log/celery |
| 38 | + && rm -rf /var/lib/apt/lists/* |
35 | 39 |
|
36 | | -COPY . . |
37 | | -RUN chmod +x backend/*.sh |
| 40 | +# Copy application and Python packages |
| 41 | +COPY . /fba |
38 | 42 | COPY --from=builder /usr/local /usr/local |
39 | | -COPY deploy/backend/supervisord.conf /etc/supervisor/supervisord.conf |
40 | | -ARG SERVICE_TYPE=fastapi_server |
41 | | -COPY deploy/backend/${SERVICE_TYPE}.conf /etc/supervisor/conf.d/ |
42 | 43 |
|
| 44 | +# ===== FastAPI Server Image ===== |
| 45 | +FROM runtime AS fastapi_server |
| 46 | +WORKDIR /fba/backend |
| 47 | +RUN mkdir -p /var/log/fastapi_server |
| 48 | +COPY deploy/backend/supervisord.conf /etc/supervisor/supervisord.conf |
| 49 | +COPY deploy/backend/fastapi_server.conf /etc/supervisor/conf.d/ |
43 | 50 | EXPOSE 8001 |
| 51 | +ENV PYTHONPATH=/fba |
| 52 | +CMD ["uvicorn", "backend.main:app", "--host", "0.0.0.0", "--port","8000"] |
| 53 | + |
| 54 | +# ===== Celery Worker Image ===== |
| 55 | +FROM runtime AS celery |
| 56 | +WORKDIR /fba/backend |
| 57 | +RUN mkdir -p /var/log/celery && chmod +x /fba/backend/*.sh |
| 58 | +COPY deploy/backend/supervisord.conf /etc/supervisor/supervisord.conf |
| 59 | +COPY deploy/backend/celery.conf /etc/supervisor/conf.d/ |
44 | 60 | EXPOSE 8555 |
| 61 | +CMD ["./celery-start.sh"] |
45 | 62 |
|
46 | | -CMD ["backend/${SERVICE_TYPE}-start.sh"] |
| 63 | +# Select the image type based on SERVICE_TYPE build arg |
| 64 | +FROM ${SERVICE_TYPE} |
0 commit comments