|
332 | 332 | echo "Inspecting layer compression for tag: $TAG" |
333 | 333 | |
334 | 334 | docker buildx imagetools inspect --raw -- "$TAG" > manifest.json |
335 | | - if grep -q "tar+zstd" manifest.json; then |
336 | | - echo "::error::Image contains zstd-compressed layers! This is incompatible with legacy registries." |
337 | | - cat manifest.json | grep mediaType |
338 | | - exit 1 |
| 335 | + |
| 336 | + # Extract child digests (excluding attestation manifests) if it's a multi-arch manifest list / index |
| 337 | + DIGESTS=$(jq -r '.manifests[] | select((.platform.architecture // "") != "unknown" and (.annotations["vnd.docker.reference.type"] // "") != "attestation-manifest") | .digest' manifest.json 2>/dev/null || true) |
| 338 | + |
| 339 | + verify_manifest() { |
| 340 | + local file=$1 |
| 341 | + # Check if any layer does NOT end in gzip/tar+gzip/tar.gzip |
| 342 | + local invalid_layers |
| 343 | + invalid_layers=$(jq -r '.layers[].mediaType' "$file" | grep -v 'tar+gzip' | grep -v 'tar.gzip' || true) |
| 344 | + if [ -n "$invalid_layers" ]; then |
| 345 | + echo "::error::Found layers that are not gzip-compressed:" |
| 346 | + echo "$invalid_layers" |
| 347 | + exit 1 |
| 348 | + fi |
| 349 | + # Also verify we found at least one layer |
| 350 | + local layer_count |
| 351 | + layer_count=$(jq '.layers | length' "$file" 2>/dev/null || echo 0) |
| 352 | + if [ "$layer_count" -eq 0 ]; then |
| 353 | + echo "::error::No layers found in manifest!" |
| 354 | + exit 1 |
| 355 | + fi |
| 356 | + } |
| 357 | + |
| 358 | + if [ -n "$DIGESTS" ]; then |
| 359 | + echo "Multi-arch image list detected. Checking each platform manifest..." |
| 360 | + for digest in $DIGESTS; do |
| 361 | + echo "Inspecting child platform manifest: $digest" |
| 362 | + docker buildx imagetools inspect --raw -- "$TAG@$digest" > child_manifest.json |
| 363 | + verify_manifest child_manifest.json |
| 364 | + done |
| 365 | + else |
| 366 | + echo "Single-arch manifest detected. Checking manifest..." |
| 367 | + verify_manifest manifest.json |
339 | 368 | fi |
340 | 369 | echo "Success: All layers are uniformly compressed using gzip." |
341 | 370 |
|
|
391 | 420 | echo "Inspecting layer compression for tag: $TAG" |
392 | 421 | |
393 | 422 | docker buildx imagetools inspect --raw -- "$TAG" > manifest.json |
394 | | - if grep -q "tar+zstd" manifest.json; then |
395 | | - echo "::error::Image contains zstd-compressed layers! This is incompatible with legacy registries." |
396 | | - cat manifest.json | grep mediaType |
397 | | - exit 1 |
| 423 | + |
| 424 | + # Extract child digests (excluding attestation manifests) if it's a multi-arch manifest list / index |
| 425 | + DIGESTS=$(jq -r '.manifests[] | select((.platform.architecture // "") != "unknown" and (.annotations["vnd.docker.reference.type"] // "") != "attestation-manifest") | .digest' manifest.json 2>/dev/null || true) |
| 426 | + |
| 427 | + verify_manifest() { |
| 428 | + local file=$1 |
| 429 | + # Check if any layer does NOT end in gzip/tar+gzip/tar.gzip |
| 430 | + local invalid_layers |
| 431 | + invalid_layers=$(jq -r '.layers[].mediaType' "$file" | grep -v 'tar+gzip' | grep -v 'tar.gzip' || true) |
| 432 | + if [ -n "$invalid_layers" ]; then |
| 433 | + echo "::error::Found layers that are not gzip-compressed:" |
| 434 | + echo "$invalid_layers" |
| 435 | + exit 1 |
| 436 | + fi |
| 437 | + # Also verify we found at least one layer |
| 438 | + local layer_count |
| 439 | + layer_count=$(jq '.layers | length' "$file" 2>/dev/null || echo 0) |
| 440 | + if [ "$layer_count" -eq 0 ]; then |
| 441 | + echo "::error::No layers found in manifest!" |
| 442 | + exit 1 |
| 443 | + fi |
| 444 | + } |
| 445 | + |
| 446 | + if [ -n "$DIGESTS" ]; then |
| 447 | + echo "Multi-arch image list detected. Checking each platform manifest..." |
| 448 | + for digest in $DIGESTS; do |
| 449 | + echo "Inspecting child platform manifest: $digest" |
| 450 | + docker buildx imagetools inspect --raw -- "$TAG@$digest" > child_manifest.json |
| 451 | + verify_manifest child_manifest.json |
| 452 | + done |
| 453 | + else |
| 454 | + echo "Single-arch manifest detected. Checking manifest..." |
| 455 | + verify_manifest manifest.json |
398 | 456 | fi |
399 | 457 | echo "Success: All layers are uniformly compressed using gzip." |
400 | 458 | {{- if and $bv.DockerBaseImage (ne $bv.DockerBaseImage "distroless") }} |
|
0 commit comments