From 9afbe422c6c46a9babca3a4fcb4ef180480c3790 Mon Sep 17 00:00:00 2001 From: Eric Maydeck <126706864+emaydeck-mozilla@users.noreply.github.com> Date: Mon, 23 Sep 2024 16:41:11 -0600 Subject: [PATCH] chore: prefer git tag for docker image tag (#768) We should prefer to use a tag for images over the default branch when applicable. Also, since we're filtering by the default branch in the workflow, we don't need to validate the branch name in the job. --- .circleci/config.yml | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 85154f4c9..7cd0f4b44 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -382,13 +382,19 @@ jobs: - run: name: Restore Docker image cache command: docker load -i /tmp/cache/docker.tar + # This is the easiest way to tag multiple images using different + # conditions for the GAR_TAG variable in the smallest amount of code. + # + # You can find other jobs and commands you can use with this orb that + # include tagging here: + # https://circleci.com/developer/orbs/orb/circleci/gcp-gcr - run: name: Tag image command: | - if [ "${CIRCLE_BRANCH}" == "master" ]; then - echo 'export GAR_TAG=master' >> $BASH_ENV - elif [ ! -z "${CIRCLE_TAG}" ]; then - echo "export GAR_TAG=$CIRCLE_TAG" >> $BASH_ENV + if [ ! -z "${CIRCLE_TAG}" ]; then + echo "export GAR_TAG=${CIRCLE_TAG}" >> $BASH_ENV + else + echo "export GAR_TAG=${CIRCLE_BRANCH}" >> $BASH_ENV fi echo "export GAR_IMAGE=\"<>/${GCP_GAR_PROJECT_ID}/${GCP_GAR_REPO}/<>\"" >> $BASH_ENV source $BASH_ENV