From ccc1521cb05646c05630c889cd2f3400fd934c70 Mon Sep 17 00:00:00 2001 From: Ariel Gentile Date: Tue, 16 Jul 2024 08:51:49 -0300 Subject: [PATCH] ci: fix image tags for main branch Signed-off-by: Ariel Gentile --- .github/workflows/cd.yml | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index ad0c87f..f6ae98a 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -9,7 +9,8 @@ on: env: DH_USERNAME: ${{secrets.DOCKER_HUB_LOGIN}} DH_TOKEN: ${{secrets.DOCKER_HUB_PWD}} - IMAGE_NAME: '2060-service-agent' + IMAGE_NAME: '2060-service-agent' + IMAGE_TAG: ${{ github.ref == 'refs/heads/main' && 'dev' || github.ref }} jobs: build: @@ -70,24 +71,24 @@ jobs: - name: Build Docker image if: steps.semantic.outputs.new-release-published == 'true' run: | - docker build -f Dockerfile -t $DH_USERNAME/$IMAGE_NAME:${GITHUB_REF##*/} . + docker build -f Dockerfile -t $DH_USERNAME/$IMAGE_NAME:$IMAGE_TAG . - name: Add tags to Docker image and push to Docker Hub if: steps.semantic.outputs.new-release-published == 'true' run: | - docker tag $DH_USERNAME/$IMAGE_NAME:${GITHUB_REF##*/} $DH_USERNAME/$IMAGE_NAME:v${RELEASE_MAJOR}-${GITHUB_REF##*/} - docker tag $DH_USERNAME/$IMAGE_NAME:${GITHUB_REF##*/} $DH_USERNAME/$IMAGE_NAME:v${RELEASE_MAJOR}.${RELEASE_MINOR}-${GITHUB_REF##*/} - docker tag $DH_USERNAME/$IMAGE_NAME:${GITHUB_REF##*/} $DH_USERNAME/$IMAGE_NAME:v${RELEASE_MAJOR}.${RELEASE_MINOR}.${RELEASE_PATCH:0:1}-${GITHUB_REF##*/} - docker tag $DH_USERNAME/$IMAGE_NAME:${GITHUB_REF##*/} $DH_USERNAME/$IMAGE_NAME:v$RELEASE_VERSION - docker push $DH_USERNAME/$IMAGE_NAME:${GITHUB_REF##*/} - docker push $DH_USERNAME/$IMAGE_NAME:v$RELEASE_MAJOR-${GITHUB_REF##*/} - docker push $DH_USERNAME/$IMAGE_NAME:v$RELEASE_MAJOR.$RELEASE_MINOR-${GITHUB_REF##*/} - docker push $DH_USERNAME/$IMAGE_NAME:v$RELEASE_MAJOR.$RELEASE_MINOR.${RELEASE_PATCH:0:1}-${GITHUB_REF##*/} + docker tag $DH_USERNAME/$IMAGE_NAME:$IMAGE_TAG $DH_USERNAME/$IMAGE_NAME:v${RELEASE_MAJOR}-$IMAGE_TAG + docker tag $DH_USERNAME/$IMAGE_NAME:$IMAGE_TAG $DH_USERNAME/$IMAGE_NAME:v${RELEASE_MAJOR}.${RELEASE_MINOR}-$IMAGE_TAG + docker tag $DH_USERNAME/$IMAGE_NAME:$IMAGE_TAG $DH_USERNAME/$IMAGE_NAME:v${RELEASE_MAJOR}.${RELEASE_MINOR}.${RELEASE_PATCH:0:1}-$IMAGE_TAG + docker tag $DH_USERNAME/$IMAGE_NAME:$IMAGE_TAG $DH_USERNAME/$IMAGE_NAME:v$RELEASE_VERSION + docker push $DH_USERNAME/$IMAGE_NAME:$IMAGE_TAG + docker push $DH_USERNAME/$IMAGE_NAME:v$RELEASE_MAJOR-$IMAGE_TAG + docker push $DH_USERNAME/$IMAGE_NAME:v$RELEASE_MAJOR.$RELEASE_MINOR-$IMAGE_TAG + docker push $DH_USERNAME/$IMAGE_NAME:v$RELEASE_MAJOR.$RELEASE_MINOR.${RELEASE_PATCH:0:1}-$IMAGE_TAG docker push $DH_USERNAME/$IMAGE_NAME:v$RELEASE_VERSION - - name: Add tags to Docker image and push to Docker Hub (specific to main) - if: github.ref == 'refs/heads/main' && steps.semantic.outputs.new-release-published == 'true' + - name: Add tags to Docker image and push to Docker Hub (specific to releases) + if: github.ref == 'refs/heads/release' && steps.semantic.outputs.new-release-published == 'true' run: | docker tag $DH_USERNAME/$IMAGE_NAME:${GITHUB_REF##*/} $DH_USERNAME/$IMAGE_NAME:v$RELEASE_MAJOR docker tag $DH_USERNAME/$IMAGE_NAME:${GITHUB_REF##*/} $DH_USERNAME/$IMAGE_NAME:v$RELEASE_MAJOR.$RELEASE_MINOR