Skip to content

Commit 8bafe6d

Browse files
committed
build(docker): add OpenShift in-cluster build variants for supervisor and gateway
Add multi-stage Dockerfiles that build the OpenShell supervisor and gateway images entirely inside an OpenShift/Buildah cluster, for environments without the upstream Nix CI pipeline that stages prebuilt binaries under deploy/docker/.build/prebuilt-binaries. Both reproduce the exact upstream artifacts by running the project's own Nix devShells in a builder stage, then assembling a runtime stage identical to the existing Dockerfile.supervisor / Dockerfile.gateway: - Dockerfile.supervisor.multistage: builds the static musl openshell-sandbox binary via the musl devShell; runtime is alpine:3.22 with nftables/iptables and COPY --chmod=0555. - Dockerfile.gateway.multistage: builds openshell-gateway via the glibc-2-28 devShell, normalizes the ELF interpreter with patchelf and asserts z3 is statically embedded; runtime is distroless cc-debian13. Each builder collapses build and cleanup into a single RUN so the Nix store never enters the committed layer, keeping the intermediate commit small and within the node's ephemeral-storage budget. The upstream Dockerfiles and CI binary pipeline are unchanged. Signed-off-by: Akram Signed-off-by: Akram <akram.benaissi@gmail.com>
1 parent 25021ee commit 8bafe6d

2 files changed

Lines changed: 148 additions & 0 deletions

File tree

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# syntax=docker/dockerfile:1.4
2+
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
# In-cluster (OpenShift/Buildah) variant of Dockerfile.gateway.
6+
#
7+
# Upstream CI builds the GNU-linked openshell-gateway binary inside the
8+
# project's Nix devShell with the gnu cross target (z3 and aws-lc statically
9+
# embedded, standard ELF interpreter), and stages it under
10+
# deploy/docker/.build/prebuilt-binaries. This multi-stage Dockerfile
11+
# reproduces that exact artifact in a builder stage so clusters without the Nix
12+
# CI pipeline can build the gateway image directly from source. The final stage
13+
# is identical to Dockerfile.gateway.
14+
15+
# In a multi-stage build, an ARG that feeds a `FROM` must be declared before the
16+
# very first FROM (global pre-FROM scope). Declaring it between the two stages
17+
# makes Buildah attach it to the builder stage and fail the second FROM with
18+
# "no FROM statement found".
19+
ARG GATEWAY_BASE_IMAGE=gcr.io/distroless/cc-debian13:nonroot@sha256:d97bc0a941b8d4be647dc0ee75b264ddbb772f1ac5ba690a4309c00723b23775
20+
21+
# ---- Builder: glibc base + Nix, reproduce upstream's cross build -------------
22+
#
23+
# The build must run on a glibc/FHS base (like the CI runners), NOT on the
24+
# minimal nixos/nix image: cross-compiling emits host build-scripts linked for
25+
# x86_64-unknown-linux-gnu whose ELF interpreter is /lib64/ld-linux-x86-64.so.2,
26+
# which the nixos/nix (Alpine, store-only) image does not provide.
27+
FROM debian:bookworm-slim AS builder
28+
29+
RUN apt-get update && apt-get install -y --no-install-recommends \
30+
curl xz-utils ca-certificates git && rm -rf /var/lib/apt/lists/*
31+
32+
# Single-user Nix (no daemon) as root. NIX_CONFIG disables per-build users
33+
# during the install itself (the installer reads config before our nix.conf
34+
# exists); the written nix.conf carries that to later `nix develop` runs, plus
35+
# flakes and the flake's cachix substituter for prebuilt toolchain/z3/aws-lc.
36+
RUN export NIX_CONFIG="build-users-group =" && \
37+
mkdir -m 0755 /nix && \
38+
curl -L https://nixos.org/nix/install -o /tmp/nix-install.sh && \
39+
sh /tmp/nix-install.sh --no-daemon && \
40+
mkdir -p /etc/nix && \
41+
printf 'experimental-features = nix-command flakes\naccept-flake-config = true\nbuild-users-group =\nsandbox = false\n' > /etc/nix/nix.conf
42+
43+
# The single-user profile script only extends PATH with Nix when HOME is set,
44+
# and Buildah does not set it inside RUN by default.
45+
ENV HOME=/root
46+
47+
WORKDIR /build
48+
COPY . .
49+
50+
# Build the gateway exactly like CI: same devShell, same cargo command and
51+
# target triple. The gnu cross toolchain emits a standard ELF interpreter, so
52+
# the binary runs on distroless without post-processing. Everything runs in a
53+
# single layer: build, stage the binary at /, then delete the Nix store and
54+
# Cargo target so the committed builder layer stays small.
55+
RUN . /root/.nix-profile/etc/profile.d/nix.sh && \
56+
nix develop -c bash -euo pipefail -c '\
57+
GIT_DIR=/nonexistent cargo auditable build --release \
58+
--target x86_64-unknown-linux-gnu \
59+
--package openshell-gateway --bin openshell-gateway' && \
60+
cp target/x86_64-unknown-linux-gnu/release/openshell-gateway /openshell-gateway && \
61+
cd / && rm -rf /nix /build /root/.cache /tmp/*
62+
63+
# ---- Runtime: identical to deploy/docker/Dockerfile.gateway ------------------
64+
#
65+
# Distroless Debian provides the glibc runtime required by the binary.
66+
FROM ${GATEWAY_BASE_IMAGE} AS gateway
67+
68+
ARG TARGETARCH
69+
70+
WORKDIR /app
71+
72+
COPY --from=builder /openshell-gateway /usr/local/bin/openshell-gateway
73+
74+
USER 1000:1000
75+
EXPOSE 8080
76+
77+
ENTRYPOINT ["/usr/local/bin/openshell-gateway"]
78+
CMD ["--bind-address", "0.0.0.0", "--port", "8080"]
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# syntax=docker/dockerfile:1.4
2+
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
# In-cluster (OpenShift/Buildah) variant of Dockerfile.supervisor.
6+
#
7+
# Upstream CI produces the static musl `openshell-sandbox` binary by building
8+
# inside the project's Nix devShell with the musl cross target, and stages it
9+
# under deploy/docker/.build/prebuilt-binaries. This multi-stage Dockerfile
10+
# reproduces that exact binary in a builder stage so clusters without the Nix
11+
# CI pipeline can build the supervisor image directly from source. The final
12+
# stage is identical to Dockerfile.supervisor.
13+
14+
# ---- Builder: glibc base + Nix, reproduce upstream's cross build -------------
15+
#
16+
# The build must run on a glibc/FHS base (like the CI runners), NOT on the
17+
# minimal nixos/nix image: cross-compiling emits host build-scripts linked for
18+
# x86_64-unknown-linux-gnu whose ELF interpreter is /lib64/ld-linux-x86-64.so.2,
19+
# which the nixos/nix (Alpine, store-only) image does not provide.
20+
FROM debian:bookworm-slim AS builder
21+
22+
RUN apt-get update && apt-get install -y --no-install-recommends \
23+
curl xz-utils ca-certificates git && rm -rf /var/lib/apt/lists/*
24+
25+
# Single-user Nix (no daemon) as root. NIX_CONFIG disables per-build users
26+
# during the install itself (the installer reads config before our nix.conf
27+
# exists); the written nix.conf carries that to later `nix develop` runs, plus
28+
# flakes and the flake's cachix substituter for prebuilt toolchain/z3/aws-lc.
29+
RUN export NIX_CONFIG="build-users-group =" && \
30+
mkdir -m 0755 /nix && \
31+
curl -L https://nixos.org/nix/install -o /tmp/nix-install.sh && \
32+
sh /tmp/nix-install.sh --no-daemon && \
33+
mkdir -p /etc/nix && \
34+
printf 'experimental-features = nix-command flakes\naccept-flake-config = true\nbuild-users-group =\nsandbox = false\n' > /etc/nix/nix.conf
35+
36+
# The single-user profile script only extends PATH with Nix when HOME is set,
37+
# and Buildah does not set it inside RUN by default.
38+
ENV HOME=/root
39+
40+
WORKDIR /build
41+
COPY . .
42+
43+
# Build the sandbox binary exactly like CI: same devShell, same cargo command
44+
# and target triple. Everything runs in a single layer: build, stage the static
45+
# binary at /, then delete the Nix store and Cargo target. The binary is static
46+
# musl (it needs nothing from /nix at runtime), so the committed builder layer
47+
# shrinks to the binary alone, keeping the intermediate commit fast and within
48+
# the node's ephemeral-storage budget.
49+
RUN . /root/.nix-profile/etc/profile.d/nix.sh && \
50+
nix develop -c bash -euo pipefail -c '\
51+
GIT_DIR=/nonexistent cargo auditable build --release \
52+
--target x86_64-unknown-linux-musl \
53+
--package openshell-sandbox --bin openshell-sandbox' && \
54+
cp target/x86_64-unknown-linux-musl/release/openshell-sandbox /openshell-sandbox && \
55+
cd / && rm -rf /nix /build /root/.cache /tmp/*
56+
57+
# ---- Runtime: identical to deploy/docker/Dockerfile.supervisor ---------------
58+
#
59+
# Alpine supplies nftables and iptables for pod-namespace egress enforcement.
60+
FROM alpine:3.22 AS supervisor
61+
62+
ARG TARGETARCH
63+
64+
RUN apk add --no-cache nftables iptables iptables-legacy
65+
66+
# Keep the binary root-owned for Podman image-volume mounts and executable by
67+
# the Kubernetes network sidecar's non-root proxy UID.
68+
COPY --from=builder --chmod=0555 /openshell-sandbox /openshell-sandbox
69+
70+
ENTRYPOINT ["/openshell-sandbox"]

0 commit comments

Comments
 (0)