-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathretag-image.sh
More file actions
51 lines (41 loc) · 1.85 KB
/
retag-image.sh
File metadata and controls
51 lines (41 loc) · 1.85 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
#!/usr/bin/env sh
#
IMAGE="${1}"
COMMIT="${2}"
ENV_TAG="${3:-prod}"
ACCOUNT="576546042567"
REGION="us-west-2"
ECR_URL=${ACCOUNT}.dkr.ecr.${REGION}.amazonaws.com
# printf "ECR_URL: %s" $ECR_URL
# check parameter argument for expected value
if [ "X$IMAGE" = "X" ]; then
echo "ERROR! Unexpected ECR image/repository specified: '$IMAGE'"
# echo "Please specify an image name, such as go/builder, for example"
echo "usage: retag-image.sh {image} {commit} {tag}"
echo "example: retag-image.sh data/analytics 6be9acf6 infra"
exit 20
fi
# check parameter argument for expected value
if [ "X$COMMIT" = "X" ]; then
echo "ERROR! No commit id recognized."
echo "Please provide a valid 8 character Commit ID, which would have been published from a CI job."
echo "usage: retag-image.sh {image} {commit} {tag}"
echo "example: retag-image.sh data/analytics 6be9acf6 infra"
exit 31
fi
# check parameter argument for expected value
if [ "$ENV_TAG" = "dev" ] || [ "$ENV_TAG" = "infra" ] || [ "$ENV_TAG" = "stage" ] || [ "$ENV_TAG" = "prod" ]; then
echo "Ready to retag $IMAGE:$COMMIT with environment tag $ENV_TAG"
else
echo "Warning! Unexpected tag specified: '$ENV_TAG'"
echo "Proceeding to retag $IMAGE:$COMMIT as $ENV_TAG"
fi
# Login to ECR; presumes you have local AWS API credentials setup. This likely need to be modified to work well with aws-vault or similar
aws ecr get-login-password | docker login ${ECR_URL} --username AWS --password-stdin
MANIFEST=$(aws ecr batch-get-image --region $REGION --repository-name $IMAGE --image-ids imageTag=$COMMIT --query 'images[].imageManifest' --output text)
if [ "X$MANIFEST" = "X" ]; then
echo "Error: IMAGE:TAG -NOT- found in ECR : $IMAGE:$COMMIT"
else
echo "OK: ECR IMAGE:TAG matched : $IMAGE:$COMMIT"
aws ecr put-image --region $REGION --repository-name $IMAGE --image-tag $ENV_TAG --image-manifest "$MANIFEST" # || :
fi