Skip to content

Commit 8ae553f

Browse files
committed
perf: Lower container size
1 parent cc06e73 commit 8ae553f

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

cicd/Dockerfile

+17-11
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,33 @@
1-
# Base container
2-
FROM ghcr.io/astral-sh/uv:python3.12-bookworm AS base
1+
# Builder container (with UV as package manager)
2+
FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim@sha256:aacf61c53ed988e4a32b8b4da19043fdce7a8efcc67fb21ebc4cc0ba85f335b3 AS builder
3+
4+
ENV UV_COMPILE_BYTECODE=1
5+
ENV UV_LINK_MODE=copy
36

47
RUN rm -f /etc/apt/apt.conf.d/docker-clean \
58
&& echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache
69
RUN --mount=target=/var/lib/apt/lists,type=cache,id=apt-lists-${TARGETPLATFORM},sharing=locked \
710
apt-get update -q \
811
&& apt-get install -y -q --no-install-recommends \
9-
ffmpeg
12+
build-essential
1013

11-
ARG VERSION
12-
ENV VERSION=${VERSION}
14+
WORKDIR /app
15+
16+
COPY . .
1317

14-
RUN useradd -m appuser
18+
RUN --mount=target=/root/.cache/uv,type=cache,id=uv-${TARGETPLATFORM},sharing=locked \
19+
uv sync --frozen --no-dev
1520

16-
COPY --chown=appuser:appuser . /app
21+
# Output container (with only venv and app source)
22+
FROM python:3.12-slim-bookworm@sha256:10f3aaab98db50cba827d3b33a91f39dc9ec2d02ca9b85cbc5008220d07b17f3
1723

1824
WORKDIR /app
1925

20-
RUN --mount=target=/root/.cache/uv,type=cache,id=uv-${TARGETPLATFORM},sharing=locked \
21-
uv sync --frozen
26+
ENV PATH=/app/.venv/bin:$PATH
2227

23-
USER appuser
28+
COPY --from=builder --chown=app:app /app .
2429

25-
ENV PATH=/app/.venv/bin:$PATH
30+
ARG VERSION
31+
ENV VERSION=${VERSION}
2632

2733
CMD ["bash", "-c", "gunicorn app.main:api --bind 0.0.0.0:8080 --graceful-timeout 60 --proxy-protocol --timeout 60 --worker-class uvicorn.workers.UvicornWorker --workers 4"]

0 commit comments

Comments
 (0)