From 856c7f57117b605b6ad0694ad5f294e69916bfce Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Thu, 23 Mar 2023 13:45:51 -0300 Subject: [PATCH] ci(docker): Push Docker tag for commit hash (#28578) --- .github/workflows/ci.yml | 66 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 61 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5419e2439c64..1ed47a605ea8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -453,6 +453,11 @@ jobs: echo "gh-image-name=${GH_IMAGE_NAME}" >> $GITHUB_OUTPUT + DOCKER_TAG_SHA="sha-${GITHUB_SHA:0:7}" + + echo "DOCKER_TAG_SHA: ${DOCKER_TAG_SHA}" + echo "gh-docker-tag-sha=${DOCKER_TAG_SHA}" >> $GITHUB_OUTPUT + - name: Pull Docker image run: docker pull ${{ steps.gh-docker.outputs.gh-image-name }} @@ -470,13 +475,14 @@ jobs: DOCKER_TAG="${DOCKER_TAG}-${{ matrix.release }}" fi; - echo "IMAGE_NAME: $IMAGE_NAME" - echo "DOCKER_TAG: $DOCKER_TAG" + PUBLISHED_TAGS=() # tag and push the specific tag version docker tag ${{ steps.gh-docker.outputs.gh-image-name }} $IMAGE_NAME:$DOCKER_TAG docker push $IMAGE_NAME:$DOCKER_TAG + PUBLISHED_TAGS+=("$IMAGE_NAME:$DOCKER_TAG") + if [[ $GITHUB_REF == refs/tags/* ]]; then RELEASE="${{ needs.release-versions.outputs.release }}" @@ -490,13 +496,38 @@ jobs: if [[ '${{ needs.release-versions.outputs.latest-release }}' == $GITHUB_REF_NAME ]]; then docker tag ${{ steps.gh-docker.outputs.gh-image-name }} $IMAGE_NAME:$RELEASE docker push $IMAGE_NAME:$RELEASE + + PUBLISHED_TAGS+=("$IMAGE_NAME:$RELEASE") fi else docker tag ${{ steps.gh-docker.outputs.gh-image-name }} $IMAGE_NAME:$RELEASE docker push $IMAGE_NAME:$RELEASE + + PUBLISHED_TAGS+=("$IMAGE_NAME:$RELEASE") fi fi + # commit hash + TAG_SHA="${{ steps.gh-docker.outputs.gh-docker-tag-sha }}" + + # append the variant name to docker tag + if [[ '${{ matrix.release }}' = 'alpine' ]]; then + TAG_SHA="${TAG_SHA}-${{ matrix.release }}" + fi; + + docker tag ${{ steps.gh-docker.outputs.gh-image-name }} $IMAGE_NAME:$TAG_SHA + docker push $IMAGE_NAME:$TAG_SHA + + PUBLISHED_TAGS+=("$IMAGE_NAME:$TAG_SHA") + + echo "::group::Published tags" + + for TAG in ${PUBLISHED_TAGS[@]}; do + echo $TAG + done + + echo "::endgroup::" + services-docker-image-publish: name: 🚀 Publish Docker Image (services) runs-on: ubuntu-20.04 @@ -529,6 +560,11 @@ jobs: echo "gh-image-name=${GH_IMAGE_NAME}" >> $GITHUB_OUTPUT + DOCKER_TAG_SHA="sha-${GITHUB_SHA:0:7}" + + echo "DOCKER_TAG_SHA: ${DOCKER_TAG_SHA}" + echo "gh-docker-tag-sha=${DOCKER_TAG_SHA}" >> $GITHUB_OUTPUT + - name: Pull Docker image run: docker pull ${{ steps.gh-docker.outputs.gh-image-name }} @@ -539,24 +575,44 @@ jobs: # 'develop' or 'tag' DOCKER_TAG=$GITHUB_REF_NAME - echo "DH_IMAGE_NAME: $DH_IMAGE_NAME" - echo "DOCKER_TAG: $DOCKER_TAG" + PUBLISHED_TAGS=() # tag and push the specific tag version docker tag ${{ steps.gh-docker.outputs.gh-image-name }} $DH_IMAGE_NAME:$DOCKER_TAG docker push $DH_IMAGE_NAME:$DOCKER_TAG + PUBLISHED_TAGS+=("$DH_IMAGE_NAME:$DOCKER_TAG") + if [[ $GITHUB_REF == refs/tags/* ]]; then RELEASE="${{ needs.release-versions.outputs.release }}" - echo "RELEASE: $RELEASE" if [[ $RELEASE == 'latest' ]]; then if [[ '${{ needs.release-versions.outputs.latest-release }}' == $GITHUB_REF_NAME ]]; then docker tag ${{ steps.gh-docker.outputs.gh-image-name }} $DH_IMAGE_NAME:$RELEASE docker push $DH_IMAGE_NAME:$RELEASE + + PUBLISHED_TAGS+=("$DH_IMAGE_NAME:$RELEASE") fi else docker tag ${{ steps.gh-docker.outputs.gh-image-name }} $DH_IMAGE_NAME:$RELEASE docker push $DH_IMAGE_NAME:$RELEASE + + PUBLISHED_TAGS+=("$DH_IMAGE_NAME:$RELEASE") fi fi + + # commit hash + TAG_SHA="${{ steps.gh-docker.outputs.gh-docker-tag-sha }}" + + docker tag ${{ steps.gh-docker.outputs.gh-image-name }} $DH_IMAGE_NAME:$TAG_SHA + docker push $DH_IMAGE_NAME:$TAG_SHA + + PUBLISHED_TAGS+=("$DH_IMAGE_NAME:$TAG_SHA") + + echo "::group::Published tags" + + for TAG in ${LERO[@]}; do + echo $TAG + done + + echo "::endgroup::"