@@ -22,6 +22,12 @@ ARG K9S_VERSION=v0.50.18
2222ARG HELM_VERSION=v3.17.3
2323ARG NVIDIA_CONTAINER_TOOLKIT_VERSION=1.18.2-1
2424
25+ # OS-128 Phase 4: select binary source for final images. `build` (default)
26+ # compiles Rust inside the builder stages below; `prebuilt` consumes binaries
27+ # staged at deploy/docker/.build/prebuilt-binaries/<arch>/. Declared at global
28+ # scope so BuildKit can substitute it in `FROM *-binary-${BINARY_SOURCE}`.
29+ ARG BINARY_SOURCE=build
30+
2531# ---------------------------------------------------------------------------
2632# Shared Rust build stages
2733# ---------------------------------------------------------------------------
@@ -178,10 +184,43 @@ RUN --mount=type=cache,id=cargo-registry-${TARGETARCH},sharing=locked,target=/us
178184 mkdir -p /build/out && \
179185 cp "$(cross_output_dir release)/openshell-sandbox" /build/out/
180186
187+ # ---------------------------------------------------------------------------
188+ # Binary source selector (OS-128 Phase 4)
189+ # ---------------------------------------------------------------------------
190+ # `BINARY_SOURCE` is declared at global scope above (near the other version
191+ # ARGs). `build` (default) routes through the Rust builder stages above;
192+ # `prebuilt` routes through the scratch stages below, which COPY from
193+ # deploy/docker/.build/prebuilt-binaries/<arch>/openshell-{gateway,sandbox}
194+ # in the build context. Prebuilt-artifact production + end-to-end workflow
195+ # wiring land in later Phase 4 PRs; the `prebuilt` path is inert unless a
196+ # caller sets BINARY_SOURCE=prebuilt and stages the binaries.
197+
198+ FROM gateway-builder AS gateway-binary-build
199+ # Inherits /build/out/openshell-gateway from the cargo build stage.
200+
201+ FROM scratch AS gateway-binary-prebuilt
202+ ARG TARGETARCH
203+ # --chmod=755 preserves the executable bit through actions/upload-artifact +
204+ # download-artifact, which strip exec perms during the roundtrip.
205+ COPY --chmod=755 deploy/docker/.build/prebuilt-binaries/${TARGETARCH}/openshell-gateway /build/out/openshell-gateway
206+
207+ FROM gateway-binary-${BINARY_SOURCE} AS gateway-binary
208+
209+ FROM supervisor-builder AS supervisor-binary-build
210+ # Inherits /build/out/openshell-sandbox from the cargo build stage.
211+
212+ FROM scratch AS supervisor-binary-prebuilt
213+ ARG TARGETARCH
214+ # --chmod=755 preserves the executable bit through actions/upload-artifact +
215+ # download-artifact, which strip exec perms during the roundtrip.
216+ COPY --chmod=755 deploy/docker/.build/prebuilt-binaries/${TARGETARCH}/openshell-sandbox /build/out/openshell-sandbox
217+
218+ FROM supervisor-binary-${BINARY_SOURCE} AS supervisor-binary
219+
181220# Minimal extraction stage for fast-deploy: exports only the supervisor
182221# binary (~20-40 MB) instead of the entire build environment (~968 MB).
183222FROM scratch AS supervisor-output
184- COPY --from=supervisor-builder /build/out/openshell-sandbox /openshell-sandbox
223+ COPY --from=supervisor-binary /build/out/openshell-sandbox /openshell-sandbox
185224
186225# ---------------------------------------------------------------------------
187226# Final gateway image
@@ -197,7 +236,7 @@ RUN useradd --create-home --user-group openshell
197236
198237WORKDIR /app
199238
200- COPY --from=gateway-builder /build/out/openshell-gateway /usr/local/bin/
239+ COPY --from=gateway-binary /build/out/openshell-gateway /usr/local/bin/
201240
202241RUN mkdir -p /build/crates/openshell-server
203242COPY --chmod=755 crates/openshell-server/migrations /build/crates/openshell-server/migrations
@@ -222,7 +261,7 @@ RUN useradd --create-home --user-group openshell
222261
223262WORKDIR /app
224263
225- COPY --from=supervisor-builder /build/out/openshell-sandbox /usr/local/bin/
264+ COPY --from=supervisor-binary /build/out/openshell-sandbox /usr/local/bin/
226265
227266USER openshell
228267
@@ -292,7 +331,7 @@ COPY --from=nvidia-container-toolkit /usr/bin/nvidia-cdi-hook /usr/bin/
292331COPY --from=nvidia-container-toolkit /usr/bin/nvidia-container-runtime /usr/bin/
293332COPY --from=nvidia-container-toolkit /usr/bin/nvidia-ctk /usr/bin/
294333COPY --from=nvidia-container-toolkit /etc/nvidia-container-runtime /etc/nvidia-container-runtime
295- COPY --from=supervisor-builder /build/out/openshell-sandbox /opt/openshell/bin/openshell-sandbox
334+ COPY --from=supervisor-binary /build/out/openshell-sandbox /opt/openshell/bin/openshell-sandbox
296335
297336RUN mkdir -p /var/lib/rancher/k3s/server/manifests \
298337 /var/lib/rancher/k3s/server/static/charts \
0 commit comments