Skip to content

Commit b7c6ea6

Browse files
committed
chore(docker): reduce image size via multistage build
1 parent 4f86e7b commit b7c6ea6

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

Dockerfile

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# https://github.com/astral-sh/uv-docker-example/blob/c16a61fb3e6ab568ac58d94b73a7d79594a5d570/Dockerfile
2-
FROM python:3.13-slim
2+
3+
# Build stage
4+
FROM python:3.13-slim AS builder
35

46
WORKDIR /app
57

6-
ENV PATH="/app/.venv/bin:$PATH"
78
ENV UV_COMPILE_BYTECODE=1
89
ENV UV_LINK_MODE=copy
910
ENV UV_PROJECT_ENVIRONMENT=/usr/local
@@ -22,4 +23,18 @@ ADD . /app
2223
RUN --mount=type=cache,target=/root/.cache/uv \
2324
uv sync --frozen --no-dev
2425

26+
# Runtime stage
27+
FROM python:3.13-slim
28+
29+
WORKDIR /app
30+
31+
# Copy installed packages from builder
32+
COPY --from=builder /usr/local/lib/python3.13/site-packages /usr/local/lib/python3.13/site-packages
33+
COPY --from=builder /usr/local/bin /usr/local/bin
34+
35+
# Copy only the source code directory needed at runtime
36+
COPY --from=builder /app/src/stac_auth_proxy /app/src/stac_auth_proxy
37+
38+
ENV PYTHONPATH=/app/src
39+
2540
CMD ["python", "-m", "stac_auth_proxy"]

0 commit comments

Comments
 (0)