Skip to content

Commit

Permalink
- Improved ECR Deploy Script to tag the destination image with the sa…
Browse files Browse the repository at this point in the history
…me tags as the source.
  • Loading branch information
gitwater committed Apr 14, 2021
1 parent 69affcc commit 932af07
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/paco/application/ec2_launch_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1833,6 +1833,7 @@ def lb_scriptmanager_ecr_deploy(self, resource, scripts):
ecr_deploy_name=ecr_deploy_name,
source_repo_name=source_ecr_obj.repository_name,
source_repo_domain=f'{source_account_id}.dkr.ecr.{source_env.region}.amazonaws.com',
source_repo_account_id=source_account_id,
idx=repo_idx,
source_tag=repository.source_tag,
dest_repo_name=dest_ecr_obj.repository_name,
Expand Down
12 changes: 12 additions & 0 deletions src/paco/application/reseng_deploymentpipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
{ecr_deploy_name}_SOURCE_REPO_NAME_{idx}='{source_repo_name}'
{ecr_deploy_name}_SOURCE_REPO_DOMAIN_{idx}='{source_repo_domain}'
{ecr_deploy_name}_SOURCE_REPO_URI_{idx}="${{{ecr_deploy_name}_SOURCE_REPO_DOMAIN_{idx}}}/"
{ecr_deploy_name}_SOURCE_REPO_ACCOUNT_{idx}="{source_repo_account_id}"
{ecr_deploy_name}_SOURCE_TAG_{idx}='{source_tag}'
{ecr_deploy_name}_DEST_REPO_NAME_{idx}='{dest_repo_name}'
{ecr_deploy_name}_DEST_REPO_DOMAIN_{idx}='{dest_repo_domain}'
Expand Down Expand Up @@ -172,6 +173,7 @@
SOURCE_REPO_NAME=${ECR_DEPLOY_LIST[$I]}_SOURCE_REPO_NAME_$J
SOURCE_REPO_DOMAIN=${ECR_DEPLOY_LIST[$I]}_SOURCE_REPO_DOMAIN_$J
SOURCE_REPO_URI=${ECR_DEPLOY_LIST[$I]}_SOURCE_REPO_URI_$J
SOURCE_REPO_ACCOUNT=${ECR_DEPLOY_LIST[$I]}_SOURCE_REPO_ACCOUNT_$J
SOURCE_DEPLOY_TAG=${ECR_DEPLOY_LIST[$I]}_SOURCE_TAG_$J
if [ "${OVERRIDE_SOURCE_DEPLOY_TAG}" != "" ] ; then
SOURCE_DEPLOY_TAG="OVERRIDE_SOURCE_DEPLOY_TAG"
Expand All @@ -182,6 +184,16 @@
DEST_DEPLOY_TAG=${ECR_DEPLOY_LIST[$I]}_DEST_TAG_$J
DEST_REPO_URI=${ECR_DEPLOY_LIST[$I]}_DEST_REPO_URI_$J
JQ_QUERY=".imageDetails[] | select(.imageTags != null) | select(.imageTags | contains([\\\"${!SOURCE_DEPLOY_TAG}\\\"])) | .imageTags | join(\\\" \\\")"
SOURCE_REPO_TAGS=$(aws ecr describe-images --registry-id ${!SOURCE_REPO_ACCOUNT} --repository-name ${!SOURCE_REPO_NAME} | jq -c "${JQ_QUERY}" | tr -d '"')
for SOURCE_TAG in $(echo $SOURCE_REPO_TAGS)
do
if [ "$SOURCE_TAG" == "${!DEST_DEPLOY_TAG}" ] ; then
continue
fi
run_command "" "docker tag ${!SOURCE_REPO_URI}${!SOURCE_REPO_NAME}:${!SOURCE_DEPLOY_TAG} ${!DEST_REPO_URI}${!DEST_REPO_NAME}:${SOURCE_TAG}"
ec2lm_async_run "" "docker push ${!DEST_REPO_URI}${!DEST_REPO_NAME}:${SOURCE_TAG}"
done
run_command "" "docker tag ${!SOURCE_REPO_URI}${!SOURCE_REPO_NAME}:${!SOURCE_DEPLOY_TAG} ${!DEST_REPO_URI}${!DEST_REPO_NAME}:${!DEST_DEPLOY_TAG}"
ec2lm_async_run "" "docker push ${!DEST_REPO_URI}${!DEST_REPO_NAME}:${!DEST_DEPLOY_TAG}"
done
Expand Down

0 comments on commit 932af07

Please sign in to comment.