Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating build script to use Google Artifact Registry (SCP-5153) #2187

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions bin/build_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,19 @@ function main {
# upcoming release, e.g. 1.20.0.
# More context: https://github.com/broadinstitute/single_cell_portal_core/pull/1552#discussion_r910424433
# TODO: (SCP-4496): Move production-related GCR images out of staging project

# Google Artifact Registry (GAR) formats Docker image names differently than the canonical Container Registry format
# both refer to the same image digest and will work with 'docker pull', but the GCR names do not work with any
# 'gcloud artifacts docker' commands
# for example:
# GCR name: gcr.io/broad-singlecellportal-staging/single-cell-portal
# GAR name: us-docker.pkg.dev/broad-singlecellportal-staging/gcr.io/single-cell-portal
VERSION_TAG=$(extract_release_tag "0")
IMAGE_NAME='gcr.io/broad-singlecellportal-staging/single-cell-portal'
REPO='gcr.io'
PROJECT='broad-singlecellportal-staging'
IMAGE='single-cell-portal'
GAR_NAME="us-docker.pkg.dev/$PROJECT/$REPO/$IMAGE"
IMAGE_NAME="$REPO/$PROJECT/$IMAGE"
GCLOUD_ALIAS='gcloud'
while getopts "v:g:h" OPTION; do
case $OPTION in
Expand All @@ -50,7 +61,7 @@ function main {
done

# skip building a tagged release if it already exists, unless this is the development branch
EXISTING_DIGEST=$($GCLOUD_ALIAS container images list-tags $IMAGE_NAME --filter="tags:$VERSION_TAG" --format='get(digest)')
EXISTING_DIGEST=$($GCLOUD_ALIAS artifacts docker images list $GAR_NAME --include-tags --filter="tags=$VERSION_TAG" --format='get(version)')
if [[ "$VERSION_TAG" != 'development' ]] && [[ -n "$EXISTING_DIGEST" ]]; then
exit_with_error_message "unable to build $VERSION_TAG as it already exists with digest $EXISTING_DIGEST"
fi
Expand All @@ -63,10 +74,10 @@ function main {
echo "*** PUSH COMPLETE ***"
# pushing an image with the same tag as an existing one (which will happen each time with 'development') can leave
# behind an untagged image that needs to be deleted - these can be found with --filter='-tags:*'
UNTAGGED=$($GCLOUD_ALIAS container images list-tags $IMAGE_NAME --filter="-tags:*" --format="get(digest)")
UNTAGGED=$($GCLOUD_ALIAS artifacts docker images list $GAR_NAME --include-tags --filter="-tags:*" --format="get(version)")
if [[ -n "$UNTAGGED" ]]; then
echo "*** DELETING UNTAGGED IMAGE DIGEST $UNTAGGED ***"
$GCLOUD_ALIAS container images delete $IMAGE_NAME@$UNTAGGED --quiet || exit_with_error_message "could not delete image $UNTAGGED"
$GCLOUD_ALIAS artifacts docker images delete $GAR_NAME@$UNTAGGED --quiet || exit_with_error_message "could not delete image $UNTAGGED"
echo "*** UNTAGGED IMAGE $UNTAGGED SUCCESSFULLY DELETED ***"
fi
}
Expand Down
Loading