Skip to content

Commit b42cec5

Browse files
committed
fix(stargate): include Kubernetes router in runtime image
Signed-off-by: Mike Camp <mcamp@nvidia.com>
1 parent 5106ec3 commit b42cec5

6 files changed

Lines changed: 57 additions & 3 deletions

File tree

src/libraries/rust/stargate/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ ARG TARGETARCH
129129
# Health probe changes less often than the binary, so copy it first for layer caching.
130130
COPY --from=health-probe-downloader /usr/local/bin/grpc_health_probe /usr/local/bin/grpc_health_probe
131131
COPY --from=binary-builder /out/stargate /usr/local/bin/stargate
132+
COPY --from=binary-builder /out/stargate-k8s-router /usr/local/bin/stargate-k8s-router
132133

133134
ENTRYPOINT ["stargate"]
134135
CMD []

src/libraries/rust/stargate/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ load-balancer topology for production backend traffic.
9191
- `crates/mock-dynamo`: local OpenAI-style backend
9292
- `crates/stargate-bench`: benchmark runner
9393

94+
The versioned Stargate runtime image also includes
95+
`/usr/local/bin/stargate-k8s-router`. Kubernetes deployments can run the main
96+
Stargate process and the backend router from the same immutable image tag.
97+
9498
## Benchmarks
9599

96100
```bash

src/libraries/rust/stargate/crates/stargate-k8s-router/BUILD.bazel

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ rust_test(
4848
# Multi-arch OCI image. distroless/cc base, binary at
4949
# /usr/local/bin/stargate-k8s-router.
5050
rust_oci_image(
51-
name = "image",
51+
name = "stargate-k8s-router-image",
5252
base = "@distroless_cc",
5353
binary = ":stargate-k8s-router",
5454
binary_path = "/usr/local/bin/stargate-k8s-router",
@@ -62,8 +62,8 @@ sh_test(
6262
name = "image_entrypoint_mode_test",
6363
srcs = ["//src/libraries/rust/stargate/tools/ci:image_entrypoint_mode_test.sh"],
6464
args = [
65-
"$(location :image_layer)",
65+
"$(location :stargate-k8s-router-image_layer)",
6666
"/usr/local/bin/stargate-k8s-router",
6767
],
68-
data = [":image_layer"],
68+
data = [":stargate-k8s-router-image_layer"],
6969
)

src/libraries/rust/stargate/crates/stargate/BUILD.bazel

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ rust_oci_image(
116116
base = "@distroless_cc",
117117
binary = ":stargate",
118118
binary_path = "/usr/local/bin/stargate",
119+
extra_layers = ["//src/libraries/rust/stargate/crates/stargate-k8s-router:stargate-k8s-router-image_layer"],
119120
tags = ["stargate"],
120121
visibility = ["//visibility:public"],
121122
)
@@ -132,3 +133,15 @@ sh_test(
132133
],
133134
data = [":image_layer"],
134135
)
136+
137+
# Composite-image guard. Inspect the assembled OCI layout so removing the
138+
# router's extra layer fails this test.
139+
sh_test(
140+
name = "image_router_binary_test",
141+
srcs = ["//src/libraries/rust/stargate/tools/ci:test-oci-image-contains-path.sh"],
142+
args = [
143+
"$(location :image)",
144+
"/usr/local/bin/stargate-k8s-router",
145+
],
146+
data = [":image"],
147+
)

src/libraries/rust/stargate/tools/ci/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
exports_files(
55
[
66
"image_entrypoint_mode_test.sh",
7+
"test-oci-image-contains-path.sh",
78
],
89
visibility = ["//visibility:public"],
910
)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env bash
2+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
set -euo pipefail
6+
7+
if [[ $# -ne 2 ]]; then
8+
echo "usage: $0 <oci-image-layout> <path>" >&2
9+
exit 2
10+
fi
11+
12+
image_layout="$1"
13+
image_path="${2#/}"
14+
15+
if [[ ! -f "${image_layout}/index.json" || ! -d "${image_layout}/blobs/sha256" ]]; then
16+
echo "${image_layout} is not an OCI image layout" >&2
17+
exit 1
18+
fi
19+
20+
while IFS= read -r -d '' blob; do
21+
if entries="$(tar -tf "${blob}" 2>/dev/null)"; then
22+
while IFS= read -r entry; do
23+
entry="${entry#./}"
24+
entry="${entry#/}"
25+
if [[ "${entry}" == "${image_path}" ]]; then
26+
exit 0
27+
fi
28+
done <<< "${entries}"
29+
fi
30+
# rules_oci may symlink blob files to their source layers. Select those links
31+
# directly without following symlinked directories outside the blob tree.
32+
done < <(find "${image_layout}/blobs/sha256" \( -type f -o -type l \) -print0)
33+
34+
echo "missing /${image_path} in ${image_layout}" >&2
35+
exit 1

0 commit comments

Comments
 (0)