Skip to content

Commit

Permalink
Update ECR image tagging
Browse files Browse the repository at this point in the history
  • Loading branch information
farski committed Jun 6, 2024
1 parent b0d3678 commit d14e8d5
Showing 1 changed file with 29 additions and 16 deletions.
45 changes: 29 additions & 16 deletions ci/utility/post_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@ push_to_ecr() {
fi
set -e

# e.g., github/prx/porter
image_name="${safe_ecr_repo_name}"

# e.g., 123456789012.dkr.ecr.us-east-1.amazonaws.com
ecr_domain="${PRX_AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com"

# This is always just the Git commit hash
# e.g., de67a8d77768093b20a9ae961a78313a3c0ef096
commit_image_tag="${PRX_COMMIT}"
# e.g., github/prx/porter:de67a8d77768093b20a9ae961a78313a3c0ef096
commit_tagged_image_name="${image_name}:${commit_image_tag}"
# 123456789012.dkr.ecr.us-east-1.amazonaws.com/github/prx/porter:de67a8d77768093b20a9ae961a78313a3c0ef096
commit_full_image_uri="${ecr_domain}/${commit_tagged_image_name}"

# PRX_CI_PUBLISH is the indicator that production artifacts should
# be published. If it is present, the image tag should be the Git
# hash of the commit that triggered this build. (This is true even
Expand All @@ -51,31 +65,30 @@ push_to_ecr() {
# tag should include a `prerelease-` prefix.
if [ "$PRX_CI_PUBLISH" = "true" ]
then
# e.g., de67a8d77768093b20a9ae961a78313a3c0ef096
image_tag="${PRX_COMMIT}"
# e.g., release-de67a8d77768093b20a9ae961a78313a3c0ef096
prefix_image_tag="release-${PRX_COMMIT}"
else
# e.g., prerelease-de67a8d77768093b20a9ae961a78313a3c0ef096
image_tag="prerelease-${PRX_COMMIT}"
prefix_image_tag="prerelease-${PRX_COMMIT}"
fi

# e.g., github/prx/porter
image_name="${safe_ecr_repo_name}"
# e.g., github/prx/porter:de67a8d77768093b20a9ae961a78313a3c0ef096
tagged_image_name="${image_name}:${image_tag}"

ecr_domain="${PRX_AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com"

full_image_uri="${ecr_domain}/${tagged_image_name}"
# e.g., github/prx/porter:release-de67a8d77768093b20a9ae961a78313a3c0ef096
prefix_tagged_image_name="${image_name}:${prefix_image_tag}"
# 123456789012.dkr.ecr.us-east-1.amazonaws.com/github/prx/porter:release-de67a8d77768093b20a9ae961a78313a3c0ef096
prefix_full_image_uri="${ecr_domain}/${prefix_tagged_image_name}"

# Export a variable whose name is the LABEL from the Dockerfile,
# and whose value is the full image name with tag
# e.g., if there's a LABEL org.prx.spire.publish.docker="WEB_SERVER"
# this would set WEB_SERVER=1234.dkr.ecr.us-eas-1.amazonaws.com...
declare -gx "$label"="$tagged_image_name"

echo "> Pushing image $image_id to ECR $full_image_uri"
docker tag $image_id $full_image_uri
docker push $full_image_uri
declare -gx "$label"="$commit_tagged_image_name"

echo "> Pushing image $image_id to ECR $commit_full_image_uri"
docker tag $image_id $commit_full_image_uri
docker push $commit_full_image_uri
echo "> Pushing image $image_id to ECR $prefix_full_image_uri"
docker tag $image_id $prefix_full_image_uri
docker push $prefix_full_image_uri
echo "< Finished publishing Docker image"
done
fi
Expand Down

0 comments on commit d14e8d5

Please sign in to comment.