From afdc70178eb2344ff020fafcdff44ae568f1418f Mon Sep 17 00:00:00 2001 From: Terra Field Date: Tue, 11 Jul 2023 16:15:36 -0700 Subject: [PATCH] docker tagging updates --- .circleci/config.yml | 4 ---- build-docker.sh | 34 +++++++++++++++++++++++++++++++--- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 98ecf62474..0223d9899e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -198,7 +198,6 @@ jobs: command: | set -x - export TAG="$(test "${CIRCLE_BRANCH}" == "main" && echo "" || echo "branch-")${BUILD_ID}" export ECR_HOST=702835727665.dkr.ecr.us-east-1.amazonaws.com export KO_DOCKER_REPO=${ECR_HOST} @@ -245,9 +244,6 @@ workflows: requires: - build_binaries - build_docker - filters: - branches: - only: main - publish_github: context: Honeycomb Secrets for Public Repos requires: diff --git a/build-docker.sh b/build-docker.sh index 0881024464..09671bae2f 100755 --- a/build-docker.sh +++ b/build-docker.sh @@ -1,14 +1,42 @@ +#!/usr/bin/env bash set -o nounset set -o pipefail set -o xtrace -TAGS="latest" +TAGS="" +# Check if CIRCLE_BRANCH is set and not empty +if [[ -n "${CIRCLE_BRANCH}" ]]; then + export TAGS="${CIRCLE_BUILD_NUM},branch-${CIRCLE_BRANCH}" +fi + +# We only want to tag main with latest on ECR +if [[ "${CIRCLE_BRANCH}" == "main" ]]; then + TAGS+=",latest" +fi + +# Local builds just get "dev" for version VERSION="dev" + +# If we are doing a dev build on circle, we will version it as the circleci buildnumber +if [[ -n "${CIRCLE_BUILD_NUM}" ]]; then + VERSION="${CIRCLE_BUILD_NUM}" +fi + +# if we're running off a git tag, it is a release which we tag with the versions as well as latest +# caution: this means if we ever release an update to a previous version, it will be marked latest +# it is probably best if people just use the major or minor version tags + if [[ -n ${CIRCLE_TAG:-} ]]; then # trim 'v' prefix if present VERSION=${CIRCLE_TAG#"v"} - # append version to image tags - TAGS+=",$VERSION" + + # Extract major, major.minor, and major.minor.patch versions + MAJOR_VERSION=${VERSION%%.*} + MINOR_VERSION=${VERSION%.*} + + # Append versions to image tags + # So 2.1.1 would be tagged with "2","2.1","2.1.1" + TAGS="$MAJOR_VERSION,$MINOR_VERSION,$VERSION,latest" fi unset GOOS