|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# ELASTICSEARCH CONFIDENTIAL |
| 4 | +# __________________ |
| 5 | +# |
| 6 | +# Copyright Elasticsearch B.V. All rights reserved. |
| 7 | +# |
| 8 | +# NOTICE: All information contained herein is, and remains |
| 9 | +# the property of Elasticsearch B.V. and its suppliers, if any. |
| 10 | +# The intellectual and technical concepts contained herein |
| 11 | +# are proprietary to Elasticsearch B.V. and its suppliers and |
| 12 | +# may be covered by U.S. and Foreign Patents, patents in |
| 13 | +# process, and are protected by trade secret or copyright |
| 14 | +# law. Dissemination of this information or reproduction of |
| 15 | +# this material is strictly forbidden unless prior written |
| 16 | +# permission is obtained from Elasticsearch B.V. |
| 17 | + |
| 18 | +set -euo pipefail |
| 19 | + |
| 20 | +PRIVATE_REPO="docker.elastic.co/observability-ci/ecp-elastic-agent-service" |
| 21 | +REQUIRED_ARCHITECTURES=("amd64" "arm64") |
| 22 | + |
| 23 | +_SELF=$(dirname "$0") |
| 24 | +source "${_SELF}/../common.sh" |
| 25 | + |
| 26 | +setup_extract_sha() { |
| 27 | + # Ensure repo is available - redirect output to /dev/null |
| 28 | + if [ ! -d "serverless-gitops" ]; then |
| 29 | + git clone --depth 1 [email protected]:elastic/serverless-gitops.git |
| 30 | + else |
| 31 | + (cd serverless-gitops && git pull) |
| 32 | + fi |
| 33 | +} |
| 34 | + |
| 35 | +extract_sha() { |
| 36 | + local env=$1 |
| 37 | + |
| 38 | + # Extract first matching SHA for the environment pattern |
| 39 | + yq eval ".services.agentless.versions | with_entries(select(.key | test(\"^${env}.*\"))) | to_entries | .[0].value // \"\"" serverless-gitops/services/agentless/versions.yaml |
| 40 | +} |
| 41 | + |
| 42 | +echo "--- :docker: Validating Docker image architectures" |
| 43 | + |
| 44 | +# Check environment variable |
| 45 | +if [ -z "${ENVIRONMENT:-}" ]; then |
| 46 | + echo "ENVIRONMENT variable is not set" |
| 47 | + exit 1 |
| 48 | +fi |
| 49 | + |
| 50 | +setup_extract_sha |
| 51 | + |
| 52 | +# Extract the SHA for the specified environment |
| 53 | +COMMIT_SHA=$(extract_sha "$ENVIRONMENT") |
| 54 | + |
| 55 | +if [ -z "$COMMIT_SHA" ]; then |
| 56 | + echo "No SHA found for environment: $ENVIRONMENT" |
| 57 | + exit 1 |
| 58 | +fi |
| 59 | + |
| 60 | +DOCKER_TAG="git-${COMMIT_SHA}" |
| 61 | +PRIVATE_IMAGE="${PRIVATE_REPO}:${DOCKER_TAG}" |
| 62 | + |
| 63 | +echo "Environment: ${ENVIRONMENT}" |
| 64 | +echo "Commit SHA: ${COMMIT_SHA}" |
| 65 | +echo "Validating image: ${PRIVATE_IMAGE}" |
| 66 | + |
| 67 | +# Inspect the manifest to get architecture information |
| 68 | +echo "--- :mag: Inspecting image manifest" |
| 69 | +MANIFEST_OUTPUT=$(docker manifest inspect "$PRIVATE_IMAGE" 2>&1) || { |
| 70 | + echo "Failed to inspect manifest for image: ${PRIVATE_IMAGE}" |
| 71 | + echo "Error: ${MANIFEST_OUTPUT}" |
| 72 | + exit 1 |
| 73 | +} |
| 74 | + |
| 75 | +echo "Manifest retrieved successfully" |
| 76 | + |
| 77 | +# Extract architectures from the manifest |
| 78 | +FOUND_ARCHITECTURES=$(echo "$MANIFEST_OUTPUT" | jq -r '.manifests[]?.platform.architecture // empty' | sort -u) |
| 79 | + |
| 80 | +if [ -z "$FOUND_ARCHITECTURES" ]; then |
| 81 | + echo "No architectures found in manifest. This might be a single-architecture image." |
| 82 | + echo "Manifest content:" |
| 83 | + echo "$MANIFEST_OUTPUT" | jq . |
| 84 | + exit 1 |
| 85 | +fi |
| 86 | + |
| 87 | +echo "Found architectures in image:" |
| 88 | +echo "$FOUND_ARCHITECTURES" |
| 89 | + |
| 90 | +# Validate that all required architectures are present |
| 91 | +echo "--- :white_check_mark: Validating required architectures" |
| 92 | +MISSING_ARCHITECTURES=() |
| 93 | + |
| 94 | +for arch in "${REQUIRED_ARCHITECTURES[@]}"; do |
| 95 | + if echo "$FOUND_ARCHITECTURES" | grep -qw "$arch"; then |
| 96 | + echo "✓ Architecture '$arch' is present" |
| 97 | + else |
| 98 | + echo "✗ Architecture '$arch' is MISSING" |
| 99 | + MISSING_ARCHITECTURES+=("$arch") |
| 100 | + fi |
| 101 | +done |
| 102 | + |
| 103 | +if [ ${#MISSING_ARCHITECTURES[@]} -gt 0 ]; then |
| 104 | + echo "" |
| 105 | + echo "ERROR: Image ${PRIVATE_IMAGE} is missing required architectures: ${MISSING_ARCHITECTURES[*]}" |
| 106 | + exit 1 |
| 107 | +fi |
| 108 | + |
| 109 | +echo "" |
| 110 | +echo "SUCCESS: Image ${PRIVATE_IMAGE} contains all required architectures (${REQUIRED_ARCHITECTURES[*]})" |
| 111 | + |
0 commit comments