github.com/smartcontractkit/chainlink-testing-framework/libs@v0.0.0-20240227141906-ec710b4eb1a3/scripts/update_mirrors.sh (about) 1 #!/bin/bash 2 3 SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) 4 5 cd "$SCRIPT_DIR"/../ || exit 1 6 7 # Check if an argument is provided 8 if [ $# -eq 0 ]; then 9 echo "Usage: $0 <ecr-registry-url>" 10 exit 1 11 fi 12 13 # The first argument is the ECR registry URL 14 ECR_REGISTRY_URL="$1" 15 16 # Function to check if the image exists in ECR 17 check_image_in_ecr() { 18 local docker_image="$1" 19 local repository_name image_tag 20 21 # Extract the repository name and tag from the docker image string 22 repository_name=$(echo "$docker_image" | cut -d: -f1) 23 image_tag=$(echo "$docker_image" | cut -d: -f2) 24 25 # If the image tag is empty, it means the image name did not include a tag, and we'll use "latest" by default 26 if [[ -z "$image_tag" ]]; then 27 image_tag="latest" 28 fi 29 30 # The repository name in ECR is just the part before the colon, we don't need to replace it with an underscore 31 if aws ecr describe-images --repository-name "$repository_name" --image-ids imageTag="$image_tag" > /dev/null 2>&1; then 32 return 0 # Image exists 33 else 34 return 1 # Image does not exist 35 fi 36 } 37 38 # Function to pull, tag, and push the image to ECR 39 pull_tag_push() { 40 local docker_image=$1 41 local ecr_image="$ECR_REGISTRY_URL/${docker_image}" 42 43 # Pull the image from Docker Hub 44 docker pull "$docker_image" 45 46 # Tag the image for ECR 47 docker tag "$docker_image" "$ecr_image" 48 49 # Push the image to ECR 50 docker push "$ecr_image" 51 } 52 53 # Read the JSON file into a bash array 54 docker_images=() 55 while IFS= read -r line; do 56 docker_images+=("$line") 57 done < <(jq -r '.[]' ./mirror/mirror.json) 58 59 # Iterate over the images 60 for docker_image in "${docker_images[@]}"; do 61 echo "---" 62 echo "Checking if $docker_image exists in ECR..." 63 64 # Check if the image exists in ECR 65 if ! check_image_in_ecr "$docker_image"; then 66 echo "$docker_image does not exist in ECR. Mirroring image..." 67 # Pull, tag, and push the image to ECR 68 pull_tag_push "$docker_image" 69 else 70 echo "$docker_image already exists in ECR. Skipping..." 71 fi 72 done 73 74 echo "Mirroring process completed."