Skip to content

Commit a8c357e

Browse files
authored
Validate tags in smoke test (#1602)
* Validate tags in smoke test * fix variant tag issue for java and java-8 * fix for java8
1 parent fc286a9 commit a8c357e

File tree

3 files changed

+136
-0
lines changed

3 files changed

+136
-0
lines changed

.github/actions/smoke-test/action.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ inputs:
88
description: 'Threshold (in GB) to validate that the image size does not excced this limit'
99
required: false
1010
default: 14
11+
validate-tags:
12+
description: 'Validate that base image tags exist upstream before building'
13+
required: false
14+
default: 'true'
1115

1216
runs:
1317
using: composite
@@ -23,6 +27,8 @@ runs:
2327
- name: Build image
2428
id: build_image
2529
shell: bash
30+
env:
31+
INPUT_VALIDATE_TAGS: ${{ inputs.validate-tags }}
2632
run: ${{ github.action_path }}/build.sh ${{ inputs.image }}
2733

2834
- name: Test image

.github/actions/smoke-test/build.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
#!/bin/bash
22
IMAGE="$1"
3+
VALIDATE_TAGS="${INPUT_VALIDATE_TAGS:-true}"
34

45
set -e
56

67
export DOCKER_BUILDKIT=1
78
echo "(*) Installing @devcontainer/cli"
89
npm install -g @devcontainers/cli
910

11+
# Validate base image tags before building (if enabled)
12+
if [[ "$VALIDATE_TAGS" == "true" ]]; then
13+
echo "(*) Validating base image tags for ${IMAGE}..."
14+
"$(dirname "$0")/validate-tags.sh" "$IMAGE"
15+
else
16+
echo "(*) Skipping tag validation (validate-tags=false)"
17+
fi
18+
1019
id_label="test-container=${IMAGE}"
1120
id_image="${IMAGE}-test-image"
1221
echo "(*) Building image - ${IMAGE}"
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
#!/bin/bash
2+
3+
# Script to validate that all base image tags in manifest.json exist upstream
4+
set -e
5+
6+
IMAGE="$1"
7+
MANIFEST_FILE="src/${IMAGE}/manifest.json"
8+
9+
if [[ ! -f "$MANIFEST_FILE" ]]; then
10+
echo "ERROR: Manifest file not found: $MANIFEST_FILE"
11+
exit 1
12+
fi
13+
14+
echo "(*) Validating base image tags for ${IMAGE}..."
15+
16+
# Extract base image pattern from manifest.json
17+
BASE_IMAGE=$(jq -r '.dependencies.image // empty' "$MANIFEST_FILE")
18+
19+
if [[ -z "$BASE_IMAGE" ]]; then
20+
echo "WARNING: No base image found in dependencies.image, skipping validation"
21+
exit 0
22+
fi
23+
24+
echo "Base image pattern: $BASE_IMAGE"
25+
26+
# Extract variants from manifest.json (may be empty)
27+
VARIANTS=$(jq -r '.variants[]?' "$MANIFEST_FILE" 2>/dev/null || true)
28+
29+
# Track validation results
30+
INVALID_TAGS=()
31+
VALID_TAGS=()
32+
33+
# Function to check if a Docker image tag exists
34+
check_image_exists() {
35+
local image_tag="$1"
36+
echo " Checking: $image_tag"
37+
38+
if docker manifest inspect "$image_tag" > /dev/null 2>&1; then
39+
echo " ✓ Valid"
40+
return 0
41+
else
42+
echo " ✗ Invalid - tag does not exist"
43+
return 1
44+
fi
45+
}
46+
47+
# Check if this image has variants
48+
if [[ -n "$VARIANTS" ]]; then
49+
echo "Found variants, validating each one..."
50+
# Check each variant
51+
for variant in $VARIANTS; do
52+
image_tag="$BASE_IMAGE"
53+
54+
# Replace ${VARIANT} placeholder with actual variant
55+
image_tag=$(echo "$image_tag" | sed "s/\${VARIANT}/$variant/g")
56+
57+
# Check if there are variantBuildArgs for this variant
58+
VARIANT_BUILD_ARGS=$(jq -r ".build.variantBuildArgs.\"$variant\" // empty" "$MANIFEST_FILE" 2>/dev/null)
59+
60+
if [[ -n "$VARIANT_BUILD_ARGS" && "$VARIANT_BUILD_ARGS" != "empty" && "$VARIANT_BUILD_ARGS" != "null" ]]; then
61+
echo " Found build args for variant: $variant"
62+
# Extract build args and replace placeholders
63+
while IFS= read -r build_arg; do
64+
if [[ -n "$build_arg" ]]; then
65+
arg_name=$(echo "$build_arg" | cut -d':' -f1 | tr -d '"')
66+
arg_value=$(echo "$build_arg" | cut -d':' -f2- | tr -d '"' | sed 's/^[[:space:]]*//' | sed 's/[[:space:]]*$//')
67+
image_tag=$(echo "$image_tag" | sed "s/\${$arg_name}/$arg_value/g")
68+
fi
69+
done < <(echo "$VARIANT_BUILD_ARGS" | jq -r 'to_entries[] | "\(.key):\(.value)"' 2>/dev/null)
70+
elif [[ "$image_tag" == *'${BASE_IMAGE_VERSION_CODENAME}'* ]]; then
71+
echo " Using variant name '$variant' as BASE_IMAGE_VERSION_CODENAME"
72+
image_tag=$(echo "$image_tag" | sed "s/\${BASE_IMAGE_VERSION_CODENAME}/$variant/g")
73+
fi
74+
75+
if check_image_exists "$image_tag"; then
76+
VALID_TAGS+=("$variant")
77+
else
78+
INVALID_TAGS+=("$variant")
79+
fi
80+
done
81+
else
82+
echo "No variants found, validating single base image..."
83+
if check_image_exists "$BASE_IMAGE"; then
84+
VALID_TAGS+=("base")
85+
else
86+
INVALID_TAGS+=("base")
87+
fi
88+
fi
89+
90+
# Report results
91+
echo ""
92+
echo "=== Validation Results ==="
93+
echo "Valid $(if [[ -n "$VARIANTS" ]]; then echo "variants"; else echo "base images"; fi) (${#VALID_TAGS[@]}):"
94+
95+
for tag in "${VALID_TAGS[@]}"; do
96+
if [[ "$tag" == "base" ]]; then
97+
echo "$BASE_IMAGE"
98+
else
99+
echo "$tag"
100+
fi
101+
done
102+
103+
if [[ ${#INVALID_TAGS[@]} -gt 0 ]]; then
104+
echo ""
105+
echo "Invalid $(if [[ -n "$VARIANTS" ]]; then echo "variants"; else echo "base images"; fi) (${#INVALID_TAGS[@]}):"
106+
107+
for tag in "${INVALID_TAGS[@]}"; do
108+
if [[ "$tag" == "base" ]]; then
109+
echo "$BASE_IMAGE"
110+
else
111+
echo "$tag"
112+
fi
113+
done
114+
echo ""
115+
echo "ERROR: Found ${#INVALID_TAGS[@]} invalid base image tags!"
116+
echo "Please verify these tags exist upstream before proceeding."
117+
exit 1
118+
fi
119+
120+
echo ""
121+
echo "✓ All base image tags are valid!"

0 commit comments

Comments
 (0)