Skip to content

Commit 234e69d

Browse files
authored
fix(e2e): refresh latest sandbox image for docker runs (#1928)
This fixes an issue where you may run e.g. `mise run e2e:python`, then after Python is upgraded in mise.toml, subsequent runs of `e2e:python` fail because the Python version is out of sync. Signed-off-by: Kris Hicks <khicks@nvidia.com>
1 parent 4c75b85 commit 234e69d

1 file changed

Lines changed: 49 additions & 7 deletions

File tree

e2e/with-docker-gateway.sh

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@
1313
#
1414
# HTTPS endpoint-only mode is intentionally unsupported here. Use a named
1515
# gateway config when mTLS materials are needed.
16+
#
17+
# Sandbox image overrides:
18+
# OPENSHELL_E2E_DOCKER_SANDBOX_IMAGE=...
19+
# OPENSHELL_E2E_DOCKER_SANDBOX_IMAGE_PULL_POLICY=Always|IfNotPresent|Never
20+
#
21+
# The default community sandbox image uses :latest. This wrapper refreshes it
22+
# before starting the gateway, while the Docker driver defaults to IfNotPresent
23+
# so local Dockerfile-built images remain usable.
1624

1725
set -euo pipefail
1826

@@ -342,6 +350,41 @@ ensure_docker_supervisor_image() {
342350
exit 2
343351
}
344352

353+
image_uses_latest_tag() {
354+
local image=$1
355+
local last_component
356+
357+
# Digest references are immutable even if the tag portion says latest.
358+
if [[ "${image}" == *@* ]]; then
359+
return 1
360+
fi
361+
362+
last_component="${image##*/}"
363+
# Docker treats an omitted tag as :latest.
364+
if [[ "${last_component}" != *:* ]]; then
365+
return 0
366+
fi
367+
368+
[[ "${last_component}" == *:latest ]]
369+
}
370+
371+
ensure_sandbox_image_available() {
372+
local image=$1
373+
374+
if image_uses_latest_tag "${image}"; then
375+
echo "Refreshing latest sandbox image ${image}..."
376+
docker_pull_with_retry "${image}"
377+
return
378+
fi
379+
380+
if docker image inspect "${image}" >/dev/null 2>&1; then
381+
return
382+
fi
383+
384+
echo "Pulling ${image}..."
385+
docker_pull_with_retry "${image}"
386+
}
387+
345388
DAEMON_ARCH="$(normalize_arch "$(docker info --format '{{.Architecture}}' 2>/dev/null || true)")"
346389
SUPERVISOR_TARGET="$(linux_target_triple "${DAEMON_ARCH}")"
347390
HOST_OS="$(uname -s)"
@@ -386,12 +429,10 @@ fi
386429

387430
DEFAULT_SANDBOX_IMAGE="ghcr.io/nvidia/openshell-community/sandboxes/base:latest"
388431
SANDBOX_IMAGE="${OPENSHELL_E2E_DOCKER_SANDBOX_IMAGE:-${OPENSHELL_SANDBOX_IMAGE:-${DEFAULT_SANDBOX_IMAGE}}}"
389-
if ! docker image inspect "${SANDBOX_IMAGE}" >/dev/null 2>&1; then
390-
echo "Pulling ${SANDBOX_IMAGE}..."
391-
if ! docker_pull_with_retry "${SANDBOX_IMAGE}"; then
392-
echo "ERROR: sandbox image '${SANDBOX_IMAGE}' is not available." >&2
393-
exit 2
394-
fi
432+
SANDBOX_IMAGE_PULL_POLICY="${OPENSHELL_E2E_DOCKER_SANDBOX_IMAGE_PULL_POLICY:-${OPENSHELL_SANDBOX_IMAGE_PULL_POLICY:-IfNotPresent}}"
433+
if ! ensure_sandbox_image_available "${SANDBOX_IMAGE}"; then
434+
echo "ERROR: sandbox image '${SANDBOX_IMAGE}' is not available." >&2
435+
exit 2
395436
fi
396437

397438
PKI_DIR="${WORKDIR}/pki"
@@ -420,6 +461,7 @@ else
420461
fi
421462

422463
echo "Starting openshell-gateway on port ${HOST_PORT} (namespace: ${E2E_NAMESPACE})..."
464+
echo "Using sandbox image: ${SANDBOX_IMAGE} (pull policy: ${SANDBOX_IMAGE_PULL_POLICY})"
423465
e2e_generate_gateway_jwt "${JWT_DIR}"
424466

425467
# Driver-specific options moved from CLI flags into a TOML config table
@@ -446,7 +488,7 @@ GATEWAY_CONFIG="${STATE_DIR}/gateway.toml"
446488
printf 'network_name = %s\n' "$(toml_string "${DOCKER_NETWORK_NAME}")"
447489
printf 'grpc_endpoint = %s\n' "$(toml_string "${GATEWAY_ENDPOINT}")"
448490
printf 'default_image = %s\n' "$(toml_string "${SANDBOX_IMAGE}")"
449-
printf 'image_pull_policy = "IfNotPresent"\n'
491+
printf 'image_pull_policy = %s\n' "$(toml_string "${SANDBOX_IMAGE_PULL_POLICY}")"
450492
printf 'guest_tls_ca = %s\n' "$(toml_string "${PKI_DIR}/ca.crt")"
451493
printf 'guest_tls_cert = %s\n' "$(toml_string "${PKI_DIR}/client/tls.crt")"
452494
printf 'guest_tls_key = %s\n' "$(toml_string "${PKI_DIR}/client/tls.key")"

0 commit comments

Comments
 (0)