Skip to content

Commit c9ae9c1

Browse files
committed
feat: improve docker image size, efficiency and security
1 parent 8289ef3 commit c9ae9c1

File tree

2 files changed

+7
-14
lines changed

2 files changed

+7
-14
lines changed

Dockerfile

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,25 @@
11
FROM python:3.13-slim AS builder
22

3-
WORKDIR /install
3+
ENV UV_SYSTEM_PYTHON=1
44

5-
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
5+
WORKDIR /build
66

7-
RUN apt-get update && apt-get install -y \
8-
gcc \
9-
g++ \
10-
&& rm -rf /var/lib/apt/lists/*
7+
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
118

129
COPY pyproject.toml uv.lock README.md ./
13-
COPY app ./app
1410

1511
RUN uv sync --frozen --no-dev --no-cache
1612

1713
FROM python:3.13-slim AS runtime
1814

1915
ENV PYTHONDONTWRITEBYTECODE=1 \
2016
PYTHONUNBUFFERED=1 \
21-
PATH="/install/.venv/bin:$PATH"
17+
PATH="/build/.venv/bin:$PATH"
2218

2319
WORKDIR /app
2420

25-
COPY --from=builder /install/.venv /install/.venv
21+
COPY --from=builder /build/.venv /build/.venv
22+
2623
COPY ./app ./app
2724

2825
EXPOSE 8000

dev/Dockerfile

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,14 @@ FROM python:3.13-slim
22

33
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
44

5-
RUN apt-get update && apt-get install -y \
6-
gcc \
7-
g++ \
8-
&& rm -rf /var/lib/apt/lists/*
9-
105
ENV PYTHONDONTWRITEBYTECODE=1 \
116
PYTHONUNBUFFERED=1 \
127
UV_SYSTEM_PYTHON=1
138

149
WORKDIR /
1510

1611
COPY pyproject.toml uv.lock README.md ./
12+
1713
COPY app ./app
1814

1915
RUN uv sync --frozen --no-dev --no-cache

0 commit comments

Comments
 (0)