Skip to content

Commit 72889ae

Browse files
brivudhilmathy
andauthored
feat: add profile to tag image (#322)
* Added aws profile to tag_image (#318) Co-authored-by: Brian Vu <[email protected]> * refactor: rename variables to orb standards * fix: rename parameter * fix: replace env subst with eval * fix: add profile_name to job --------- Co-authored-by: Mathivanan Palanisamy <[email protected]>
1 parent 2bca68e commit 72889ae

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

.circleci/test-deploy.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ jobs:
5050
skip_when_tags_exist: <<parameters.skip_when_tags_exist>>
5151
source_tag: <<parameters.source_tag>>
5252
target_tag: <<parameters.target_tag>>
53+
profile_name: <<parameters.profile_name>>
5354
build-test-then-push-with-buildx:
5455
machine:
5556
image: ubuntu-2204:2022.07.1

src/commands/tag_image.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ parameters:
2121
description: Whether to skip tagging an image if any specified tags already exist
2222
type: boolean
2323

24+
profile_name:
25+
default: "default"
26+
description: AWS profile to use
27+
type: string
28+
2429
steps:
2530
- run:
2631
name: <<parameters.target_tag>> tag to <<parameters.repo>>:<<parameters.source_tag>>
@@ -29,4 +34,5 @@ steps:
2934
AWS_ECR_STR_SOURCE_TAG: <<parameters.source_tag>>
3035
AWS_ECR_STR_TARGET_TAG: <<parameters.target_tag>>
3136
AWS_ECR_BOOL_SKIP_WHEN_TAGS_EXIST: <<parameters.skip_when_tags_exist>>
37+
AWS_ECR_STR_AWS_PROFILE: <<parameters.profile_name>>
3238
command: <<include(scripts/tag_image.sh)>>

src/scripts/tag_image.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,26 @@
22
AWS_ECR_EVAL_REPO="$(eval echo "${AWS_ECR_STR_REPO}")"
33
AWS_ECR_EVAL_SOURCE_TAG="$(eval echo "${AWS_ECR_STR_SOURCE_TAG}")"
44
AWS_ECR_EVAL_TARGET_TAG="$(eval echo "${AWS_ECR_STR_TARGET_TAG}")"
5+
AWS_ECR_EVAL_AWS_PROFILE="$(eval echo "${AWS_ECR_STR_AWS_PROFILE}")"
56

67
# pull the image manifest from ECR
78
set -x
8-
MANIFEST="$(aws ecr batch-get-image --repository-name "${AWS_ECR_EVAL_REPO}" --image-ids imageTag="${AWS_ECR_EVAL_SOURCE_TAG}" --query 'images[].imageManifest' --output text)"
9-
EXISTING_TAGS="$(aws ecr list-images --repository-name "${AWS_ECR_EVAL_REPO}" --filter "tagStatus=TAGGED")"
9+
MANIFEST="$(aws ecr batch-get-image --repository-name "${AWS_ECR_EVAL_REPO}" --image-ids imageTag="${AWS_ECR_EVAL_SOURCE_TAG}" --query 'images[].imageManifest' --output text --profile "${AWS_ECR_EVAL_AWS_PROFILE}")"
10+
EXISTING_TAGS="$(aws ecr list-images --repository-name "${AWS_ECR_EVAL_REPO}" --filter "tagStatus=TAGGED" --profile "${AWS_ECR_EVAL_AWS_PROFILE}")"
1011
IFS="," read -ra ECR_TAGS <<<"${AWS_ECR_EVAL_TARGET_TAG}"
1112

1213
for tag in "${ECR_TAGS[@]}"; do
1314
# if skip_when_tags_exist is true
1415
if [ "${AWS_ECR_BOOL_SKIP_WHEN_TAGS_EXIST}" -eq 1 ]; then
1516
# tag image if tag does not exist
1617
if ! echo "${EXISTING_TAGS}" | grep "${tag}"; then
17-
aws ecr put-image --repository-name "${AWS_ECR_EVAL_REPO}" --image-tag "${tag}" --image-manifest "${MANIFEST}"
18+
aws ecr put-image --repository-name "${AWS_ECR_EVAL_REPO}" --image-tag "${tag}" --image-manifest "${MANIFEST}" --profile "${AWS_ECR_EVAL_AWS_PROFILE}"
1819
else
1920
echo "Tag \"${tag}\" already exists and will be skipped."
2021
fi
2122
# tag image when skip_when_tags_exist is false
2223
else
23-
aws ecr put-image --repository-name "${AWS_ECR_EVAL_REPO}" --image-tag "${tag}" --image-manifest "${MANIFEST}"
24+
aws ecr put-image --repository-name "${AWS_ECR_EVAL_REPO}" --image-tag "${tag}" --image-manifest "${MANIFEST}" --profile "${AWS_ECR_EVAL_AWS_PROFILE}"
2425
fi
2526
done
2627
set +x

0 commit comments

Comments
 (0)