|
| 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 | +# Put single-user Nix on PATH directly (Buildah RUN is not a login shell, so the |
| 44 | +# profile script is unreliable) and point it at Debian's CA bundle for HTTPS |
| 45 | +# substituter fetches. |
| 46 | +ENV HOME=/root \ |
| 47 | + PATH=/root/.nix-profile/bin:/nix/var/nix/profiles/default/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \ |
| 48 | + NIX_SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt |
| 49 | + |
| 50 | +WORKDIR /build |
| 51 | +COPY . . |
| 52 | + |
| 53 | +# Build the gateway exactly like CI: same devShell, same cargo command and |
| 54 | +# target triple. The gnu cross toolchain emits a standard ELF interpreter, so |
| 55 | +# the binary runs on distroless without post-processing. Everything runs in a |
| 56 | +# single layer: build, stage the binary at /, then delete the Nix store and |
| 57 | +# Cargo target so the committed builder layer stays small. |
| 58 | +ARG CRYPTO_BACKEND=aws-lc |
| 59 | +RUN if [ "${CRYPTO_BACKEND}" = "openssl" ]; then \ |
| 60 | + sed -i 's/features = \["aws-lc"\]/features = ["openssl"]/' crates/openshell-gateway/Cargo.toml; \ |
| 61 | + fi |
| 62 | +RUN nix develop -c bash -euo pipefail -c '\ |
| 63 | + GIT_DIR=/nonexistent cargo auditable build --release \ |
| 64 | + --target x86_64-unknown-linux-gnu \ |
| 65 | + --package openshell-gateway --bin openshell-gateway' && \ |
| 66 | + cp target/x86_64-unknown-linux-gnu/release/openshell-gateway /openshell-gateway && \ |
| 67 | + cd / && rm -rf /nix /build /root/.cache /tmp/* |
| 68 | + |
| 69 | +# ---- Runtime: identical to deploy/docker/Dockerfile.gateway ------------------ |
| 70 | +# |
| 71 | +# Distroless Debian provides the glibc runtime required by the binary. |
| 72 | +FROM ${GATEWAY_BASE_IMAGE} AS gateway |
| 73 | + |
| 74 | +ARG TARGETARCH |
| 75 | + |
| 76 | +WORKDIR /app |
| 77 | + |
| 78 | +COPY --from=builder /openshell-gateway /usr/local/bin/openshell-gateway |
| 79 | + |
| 80 | +USER 1000:1000 |
| 81 | +EXPOSE 8080 |
| 82 | + |
| 83 | +ENTRYPOINT ["/usr/local/bin/openshell-gateway"] |
| 84 | +CMD ["--bind-address", "0.0.0.0", "--port", "8080"] |
| 85 | + |
| 86 | +# --- OpenSSL/FIPS support --- |
| 87 | +# Override CRYPTO_BACKEND=openssl to build with system OpenSSL instead of aws-lc |
0 commit comments