Skip to content

Commit e3e2878

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 6c3980d commit e3e2878

2 files changed

Lines changed: 113 additions & 0 deletions

File tree

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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 with the Nix
8+
# `glibc-2-28` devShell (glibc 2.28 symbol floor, z3 and aws-lc statically
9+
# embedded), normalizes its 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
12+
# Nix CI pipeline can build the gateway image directly from source. The final
13+
# stage is identical to Dockerfile.gateway.
14+
15+
# In multi-stage builds, 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: reproduce upstream's Nix glibc-2-28 devShell -------------------
22+
FROM nixos/nix:latest AS builder
23+
24+
# Enable flakes and honor the flake's cachix substituter so the prebuilt
25+
# toolchain, z3-static, and aws-lc-static are fetched rather than rebuilt.
26+
RUN printf 'experimental-features = nix-command flakes\naccept-flake-config = true\n' \
27+
>> /etc/nix/nix.conf
28+
29+
WORKDIR /build
30+
COPY . .
31+
32+
# Build the gateway exactly like CI: same devShell, same cargo command, then
33+
# normalize the ELF interpreter so the binary runs on distroless (its Nix-store
34+
# interpreter path does not exist there) and assert z3 is statically embedded.
35+
# Everything runs in a single layer: build, normalize, stage the binary at /,
36+
# then delete the Nix store and Cargo target so the committed builder layer
37+
# stays small (the ~20 GB store never enters the layer diff).
38+
RUN nix develop .#devShells.x86_64-linux.glibc-2-28 \
39+
-c bash -euo pipefail -c '\
40+
GIT_DIR=/nonexistent cargo auditable build --release --package openshell-gateway --bin openshell-gateway && \
41+
patchelf --set-interpreter /lib64/ld-linux-x86-64.so.2 --remove-rpath target/release/openshell-gateway && \
42+
test -z "$(patchelf --print-needed target/release/openshell-gateway | grep "^libz3")"' && \
43+
cp target/release/openshell-gateway /openshell-gateway && \
44+
cd / && rm -rf /nix /build /root/.cache /tmp/*
45+
46+
# ---- Runtime: identical to deploy/docker/Dockerfile.gateway ------------------
47+
#
48+
# Distroless Debian provides the glibc runtime required by the binary.
49+
FROM ${GATEWAY_BASE_IMAGE} AS gateway
50+
51+
ARG TARGETARCH
52+
53+
WORKDIR /app
54+
55+
COPY --from=builder /openshell-gateway /usr/local/bin/openshell-gateway
56+
57+
USER 1000:1000
58+
EXPOSE 8080
59+
60+
ENTRYPOINT ["/usr/local/bin/openshell-gateway"]
61+
CMD ["--bind-address", "0.0.0.0", "--port", "8080"]
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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 with the Nix
8+
# `musl` devShell and stages it under deploy/docker/.build/prebuilt-binaries.
9+
# This multi-stage Dockerfile reproduces that exact binary in a builder stage so
10+
# clusters without the Nix CI pipeline can build the supervisor image directly
11+
# from source. The final stage is identical to Dockerfile.supervisor.
12+
13+
# ---- Builder: reproduce upstream's Nix musl devShell -------------------------
14+
FROM nixos/nix:latest AS builder
15+
16+
# Enable flakes and honor the flake's cachix substituter so the prebuilt musl
17+
# toolchain, z3-static, and aws-lc-static are fetched rather than rebuilt.
18+
RUN printf 'experimental-features = nix-command flakes\naccept-flake-config = true\n' \
19+
>> /etc/nix/nix.conf
20+
21+
WORKDIR /build
22+
COPY . .
23+
24+
# Build the sandbox binary exactly like CI: same devShell, same cargo command.
25+
# The musl devShell's host toolchain is musl, so the binary lands in
26+
# target/release (no --target subdirectory) as a static executable.
27+
#
28+
# Everything runs in a single layer: build, stage the static binary at /, then
29+
# delete the Nix store and Cargo target. The binary is static musl (it needs
30+
# nothing from /nix at runtime), so the committed builder layer shrinks from
31+
# ~20 GB to the binary alone — keeping the intermediate commit fast and well
32+
# under the node's ephemeral-storage budget.
33+
RUN nix develop .#devShells.x86_64-linux.musl \
34+
-c bash -euo pipefail -c \
35+
'GIT_DIR=/nonexistent cargo auditable build --release --package openshell-sandbox --bin openshell-sandbox' && \
36+
cp target/release/openshell-sandbox /openshell-sandbox && \
37+
cd / && rm -rf /nix /build /root/.cache /tmp/*
38+
39+
# ---- Runtime: identical to deploy/docker/Dockerfile.supervisor ---------------
40+
#
41+
# Alpine supplies nftables and iptables for pod-namespace egress enforcement.
42+
FROM alpine:3.22 AS supervisor
43+
44+
ARG TARGETARCH
45+
46+
RUN apk add --no-cache nftables iptables iptables-legacy
47+
48+
# Keep the binary root-owned for Podman image-volume mounts and executable by
49+
# the Kubernetes network sidecar's non-root proxy UID.
50+
COPY --from=builder --chmod=0555 /openshell-sandbox /openshell-sandbox
51+
52+
ENTRYPOINT ["/openshell-sandbox"]

0 commit comments

Comments
 (0)