forked from lsst-sqre/strimzi-registry-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
68 lines (54 loc) · 2.24 KB
/
Dockerfile
File metadata and controls
68 lines (54 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# This Dockerfile has three stages:
#
# base-image
# Updates the base Python image with security patches and common system
# packages. This image becomes the base of all other images.
# install-image
# Installs third-party dependencies and the
# application into a virtual environment. This virtual environment is ideal
# for copying across build stages.
# runtime-image
# - Copies the virtual environment into place.
# - Runs a non-root user.
# - Sets up the entrypoint and port.
FROM python:3.13.7-slim-bookworm AS base-image
# Update system packages.
COPY scripts/install-base-packages.sh .
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
./install-base-packages.sh && rm ./install-base-packages.sh
FROM base-image AS install-image
# Install uv.
COPY --from=ghcr.io/astral-sh/uv:0.7.13 /uv /bin/uv
# Install system packages only needed for building dependencies.
COPY scripts/install-dependency-packages.sh .
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
./install-dependency-packages.sh
# Disable hard links during uv package installation since we're using a
# cache on a separate file system.
ENV UV_LINK_MODE=copy
# Install the dependencies.
WORKDIR /app
RUN --mount=type=cache,target=/root/.cache/uv \
--mount=type=bind,source=uv.lock,target=uv.lock \
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
uv sync --frozen --no-default-groups --compile-bytecode --no-install-project
# Install the application itself.
ADD . /app
RUN --mount=type=cache,target=/root/.cache/uv \
uv pip install --no-deps --compile-bytecode .
FROM base-image AS runtime-image
# Create a non-root user.
RUN useradd --create-home appuser
# Copy the virtualenv.
COPY --from=install-image /app /app
# Switch to the non-root user.
USER appuser
# Make sure we use the virtualenv
WORKDIR /app
ENV PATH="/app/.venv/bin:$PATH"
# Run the Kopf-based operator.
# Accept the SSR_NAMESPACE env var for a namespace to watch,
# defaulting to 'events' for compatibility with Roundtable.
CMD ["sh", "-c", "kopf run --standalone -m strimziregistryoperator.handlers --namespace ${SSR_NAMESPACE:-events} --verbose"]