Skip to content

Commit b23f46b

Browse files
committed
Provide Dockerfiles for openSUSE TW & Debian
It helps a bit to compare the different distributions. Also the two-stages build looks like a good idea ATM. TODO: For the openSUSE part, adjust it with https://build.opensuse.org/projects/Documentation:Containers/packages/daps-toolchain/files/Dockerfile
1 parent a9c599b commit b23f46b

File tree

2 files changed

+87
-2
lines changed

2 files changed

+87
-2
lines changed

Dockerfile.opensuse

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Source: https://docs.astral.sh/uv/guides/integration/docker/#non-editable-installs
2+
#
3+
# Based on openSUSE Tumbleweed
4+
#
5+
# Build it with:
6+
# $ docker build -t docbuild:latest .
7+
# -- or --
8+
# $ docker buildx build --file Dockerfile.opensuse -t docbuild:latest .
9+
#
10+
# If you want to skip the jing installation step, use:
11+
# $ docker build --file Dockerfile.opensuse \
12+
# --build-arg WITH_JING=false -t docbuild:latest .
13+
14+
ARG CONTAINER=opensuse/tumbleweed
15+
16+
# ------- Stage 1: Build the environment ----------------
17+
FROM ${CONTAINER} AS builder
18+
19+
# Disable recommended packages to save space
20+
RUN echo "rpm.install.recommended = false" >> /etc/zypp/zypp.conf
21+
22+
# Update the package repository and clean up
23+
RUN zypper ref && zypper -n dup && zypper clean -a
24+
25+
# Install uv
26+
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
27+
28+
# Change the working directory
29+
WORKDIR /app
30+
31+
# Install dependencies
32+
RUN --mount=type=cache,target=/root/.cache/uv \
33+
--mount=type=bind,source=uv.lock,target=uv.lock \
34+
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
35+
uv sync --frozen --no-install-project --no-editable
36+
37+
# Copy the project into the intermediate image
38+
ADD --chown=app:app . /app
39+
40+
# Sync the project
41+
RUN --mount=type=cache,target=/root/.cache/uv \
42+
uv sync --frozen --no-editable
43+
44+
# Create a non-root user
45+
RUN useradd -m app
46+
USER app
47+
48+
49+
# ------- Stage 2: Build/provide the application --------
50+
FROM ${CONTAINER}
51+
52+
# Allow conditional installation of jing for XML validation
53+
ARG WITH_JING=true
54+
55+
# Add repos
56+
RUN rpm --import https://download.opensuse.org/repositories/Documentation:/Tools/openSUSE_Tumbleweed/repodata/repomd.xml.key || true
57+
58+
RUN zypper addrepo --no-gpgcheck https://download.opensuse.org/repositories/Documentation:/Tools/openSUSE_Tumbleweed/Documentation:Tools.repo
59+
60+
# Install dependencies
61+
RUN zypper ref && zypper -n install -y --no-recommends daps
62+
63+
RUN [ "$WITH_JING" = "true" ] && zypper -n install -y --no-recommends jing
64+
65+
RUN zypper clean -a
66+
67+
# Create a non-root user to match the builder stage
68+
RUN useradd -m app
69+
70+
# Copy the environment, but not the source code
71+
COPY --from=builder --chown=app:app /app/.venv /app/.venv
72+
73+
# Set the working directory
74+
WORKDIR /app
75+
76+
# Add the virtual environment's bin directory to the PATH
77+
ENV PATH="/app/.venv/bin:${PATH}"
78+
79+
# Switch to the non-root user for security
80+
USER app
81+
82+
# Run the application
83+
CMD ["docbuild"]

Dockerfile renamed to Dockerfile.python

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
# Source: https://docs.astral.sh/uv/guides/integration/docker/#non-editable-installs
22
#
3+
# Based on Debian:bookworm-slim
4+
#
35
# Build it with:
46
# $ docker build -t docbuild:latest .
57
# -- or --
6-
# $ docker buildx build -t docbuild:latest .
8+
# $ docker buildx build --file Dockerfile.python -t docbuild:latest .
79
#
810
# If you want to skip the jing installation step, use:
9-
# $ docker build --build-arg WITH_JING=false -t docbuild:latest .
11+
# $ docker build --file Dockerfile.python --build-arg WITH_JING=false -t docbuild:latest .
1012

1113
ARG PYTHON_VERSION=3.13-slim
1214

0 commit comments

Comments
 (0)