-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathecr-image-sync.sh
More file actions
executable file
·68 lines (54 loc) · 2.09 KB
/
ecr-image-sync.sh
File metadata and controls
executable file
·68 lines (54 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/bash
# ECR Image Sync Script
# Usage: ./ecr-image-sync.sh
set -e
# List of images to sync (add your images here)
IMAGES=(
"bitnamilegacy/redis:8.2.1-debian-12-r0"
"bitnamilegacy/postgresql:17.5.0-debian-12-r8"
"bitnamilegacy/clickhouse:25.2.1-debian-12-r0"
"bitnamilegacy/valkey:8.0.2-debian-12-r2"
"bitnamilegacy/zookeeper:3.9.3-debian-12-r8"
"bitnamilegacy/minio:2024.12.18-debian-12-r1"
)
# Prompt for AWS configuration
read -p "Enter AWS Region: " AWS_REGION
read -p "Enter AWS Account ID: " AWS_ACCOUNT_ID
read -p "Enter Public ECR Registry Alias: " ECR_REGISTRY_ALIAS
echo "Configuration:"
echo " AWS Region: $AWS_REGION"
echo " AWS Account ID: $AWS_ACCOUNT_ID"
echo " ECR Registry Alias: $ECR_REGISTRY_ALIAS"
echo ""
# Login to public ECR (always uses us-east-1 for public ECR)
echo "Logging into public ECR..."
aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws
# Function to process each image
process_image() {
local image=$1
local repo_name=$(echo $image | cut -d':' -f1 | sed 's/.*\///')
local tag=$(echo $image | cut -d':' -f2)
echo "Processing: $image"
echo " Repository: $repo_name"
echo " Tag: $tag"
# Check if ECR repository exists, create if not
if ! aws ecr-public describe-repositories --repository-names $repo_name --region us-east-1 2>/dev/null; then
echo " Creating ECR repository: $repo_name"
aws ecr-public create-repository --repository-name $repo_name --region us-east-1
else
echo " ECR repository exists: $repo_name"
fi
# Use buildx imagetools to copy multi-arch image with manifest list
local ecr_image="public.ecr.aws/$ECR_REGISTRY_ALIAS/$repo_name:$tag"
echo " Copying multi-arch image to: $ecr_image"
docker buildx imagetools create --tag $ecr_image $image
echo " ✓ Completed: $image"
echo ""
}
# Process all images in the list
echo "Processing ${#IMAGES[@]} images..."
echo ""
for image in "${IMAGES[@]}"; do
process_image "$image"
done
echo "All images processed successfully!"