-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdockerfile
More file actions
69 lines (51 loc) · 2.13 KB
/
Copy pathdockerfile
File metadata and controls
69 lines (51 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# =============================================================================
# Base stage - Common configuration
# =============================================================================
FROM python:3.13-slim AS base
ENV PYTHONUNBUFFERED=1 \
PYTHONPATH=/app \
UV_COMPILE_BYTECODE=1 \
UV_LINK_MODE=copy \
PATH="/app/.venv/bin:$PATH"
WORKDIR /app
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
COPY pyproject.toml uv.lock ./
# =============================================================================
# Worker stage
# =============================================================================
FROM base AS worker
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --frozen --no-install-project --no-dev
# We do NOT copy the 'app/api' folder here.
COPY ./app/domains /app/app/domains
COPY ./app/infrastructure /app/app/infrastructure
COPY ./app/workers /app/app/workers
COPY ./app/scripts /app/scripts
# No specific CMD, Prefect will inject the run command
# =============================================================================
# API stage - Focus on FastAPI
# =============================================================================
FROM base AS api
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --frozen --no-install-project --no-dev
# The API needs everything
COPY ./app /app/app
COPY ./alembic.ini /app/
RUN mkdir -p /app/logs
RUN touch /app/logs/app.log
EXPOSE 80
CMD ["fastapi", "run", "--workers", "4", "--port", "80", "--host", "0.0.0.0", "app/api/main.py"]
# =============================================================================
# Migrations stage - Database migrations
# =============================================================================
FROM base AS migrations
LABEL role="migrations"
# Runtime deps + dev group (alembic, asyncpg for migrations)
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --frozen --no-install-project --no-dev --group dev
# Migrations need models (domains) and alembic config
COPY ./app /app/app
COPY ./alembic.ini /app/
COPY ./alembic /app/alembic
# We define a CMD to run migrations
CMD ["alembic", "upgrade", "head"]