Skip to content

Commit 5b25608

Browse files
committed
OCI: Improve packaging by using multi-stage builds
1 parent c55ebfb commit 5b25608

File tree

1 file changed

+30
-18
lines changed

1 file changed

+30
-18
lines changed

Dockerfile

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,42 @@
1-
FROM python:3.13-slim-bookworm
1+
# -----
2+
# Build
3+
# -----
4+
FROM python:3.13-bookworm AS build
5+
6+
# For more verbose output, use:
7+
# export BUILDKIT_PROGRESS=plain
28

39
# Configure operating system
410
ENV DEBIAN_FRONTEND=noninteractive
511
ENV TERM=linux
612

13+
# Configure build environment
14+
ENV PIP_ROOT_USER_ACTION=ignore
15+
ENV UV_COMPILE_BYTECODE=true
16+
ENV UV_LINK_MODE=copy
17+
ENV UV_PYTHON_DOWNLOADS=never
18+
719
# Provide package sources
820
COPY . /src
921

1022
# Install package and dependencies
11-
ENV UV_COMPILE_BYTECODE=true
12-
ENV UV_NO_CACHE=true
13-
ENV UV_PYTHON_DOWNLOADS=never
14-
ENV UV_SYSTEM_PYTHON=true
1523
RUN \
24+
--mount=type=cache,id=pip,target=/root/.cache/pip \
25+
--mount=type=cache,id=uv,target=/root/.cache/uv \
1626
true \
17-
# Install package.
1827
&& pip install uv \
19-
&& uv pip install /src \
20-
&& uv pip uninstall uv \
21-
# Install `jq`.
22-
&& apt-get update \
23-
&& apt-get install --no-install-recommends --no-install-suggests --yes jq \
24-
# Tear down.
25-
&& apt-get autoremove --yes \
26-
&& apt-get autoclean --yes \
27-
&& rm -rf /var/lib/apt/lists/* \
28-
&& rm -rf /root/.cache \
29-
&& rm -rf /src \
30-
&& rm -rf /tmp/*
28+
&& uv venv --no-project --relocatable /app \
29+
&& uv pip install --directory=/app /src
30+
31+
# Install optional software
32+
RUN wget --quiet --output-document=/tmp/jq "https://github.com/jqlang/jq/releases/download/jq-1.7.1/jq-linux-amd64"
33+
RUN chmod +x /tmp/jq
34+
35+
36+
# ------------
37+
# Distribution
38+
# ------------
39+
FROM python:3.13-slim-bookworm
40+
COPY --from=build /app /opt/grafana-wtf
41+
COPY --from=build /tmp/jq /usr/local/bin/jq
42+
ENV PATH="$PATH:/opt/grafana-wtf/bin"

0 commit comments

Comments
 (0)