Skip to content

Commit 5c2ec53

Browse files
committed
feat: multi-stage Docker build, add .dockerignore, fix compose command
1 parent 83fa368 commit 5c2ec53

3 files changed

Lines changed: 25 additions & 6 deletions

File tree

‎backend/.dockerignore‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.venv
2+
.env
3+
.git
4+
.env.example
5+
.ruff_cache
6+
.pytest_cache
7+
.pre-commit-config.yaml
8+
.logs
9+
__pycache__
10+
tests
11+
README.md

‎backend/Dockerfile‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
1-
FROM python:3.12-slim
1+
# --- Stage 1: Build -----
2+
FROM python:3.12-slim AS builder
23

34
# Install uv.
45
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
56

6-
# Copy the application into the container.
7-
COPY . /app/backend
7+
WORKDIR /app/backend
8+
9+
COPY pyproject.toml uv.lock ./
10+
11+
RUN uv sync --frozen --no-cache --no-dev
12+
13+
COPY . .
14+
15+
# --- Stage 2: Runtime -----
16+
FROM python:3.12-slim AS runtime
817

9-
# Install the application dependencies.
1018
WORKDIR /app/backend
11-
RUN uv sync --frozen --no-cache
1219

20+
COPY --from=builder /app/backend /app/backend
1321

1422
# Run the application.
1523
CMD ["/app/backend/.venv/bin/fastapi", "run", "main.py", "--port", "80", "--host", "0.0.0.0"]

‎backend/compose.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ services:
1616
volumes:
1717
- .:/app/backend
1818
- /app/backend/.venv # Exclude virtual environment from volume mount
19-
command: ["uv", "run", "fastapi", "run", "main.py", "--port", "80", "--host", "0.0.0.0", ]
19+
command: ["/app/backend/.venv/bin/fastapi", "run", "main.py", "--port", "80", "--host", "0.0.0.0"]
2020
db:
2121
image: postgres:16
2222
container_name: postgres-db

0 commit comments

Comments
 (0)