From 26fc0e7e64f057a066b55b7eb583dc5a346ad4f4 Mon Sep 17 00:00:00 2001 From: Meng Zhang Date: Thu, 31 Aug 2023 09:35:29 +0800 Subject: [PATCH] chore: improve tags with docker/metadata action --- .github/workflows/docker.yml | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 3443c98..12ce882 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -53,17 +53,26 @@ jobs: run: | echo "IMAGE_NAME=${GITHUB_REPOSITORY,,}" >>${GITHUB_ENV} - - name: Generate tag name - env: - REF_NAME: ${{ github.ref_name }} - run: | - echo "TAG_NAME=$(echo $REF_NAME | sed 's/main/nightly/g' | sed 's/^v//g')" >>${GITHUB_ENV} - - uses: int128/docker-build-cache-config-action@v1 id: cache with: image: ghcr.io/${{ env.IMAGE_NAME }}/cache + - name: Docker meta + id: meta + uses: docker/metadata-action@v4 + with: + # list of Docker images to use as base name for tags + images: | + ghcr.io/${{ env.IMAGE_NAME }} + ${{ env.IMAGE_NAME }} + # generate Docker tags based on the following events/attributes + tags: | + type=schedule,pattern=nightly + type=schedule,pattern={{date 'YYYYMMDD'}} + type=match,pattern=^v\d+.\d+.\d+$,value=latest + type=match,pattern=v(.*) + # Build and push Docker image with Buildx (don't push on PR) # https://github.com/docker/build-push-action - name: Build and push Docker image @@ -73,9 +82,7 @@ jobs: file: Dockerfile push: true context: . - tags: | - ghcr.io/${{ env.IMAGE_NAME }}:${{ env.TAG_NAME }} - ${{ env.IMAGE_NAME }}:${{ env.TAG_NAME }} + tags: ${{ steps.meta.outputs.tags }} cache-from: ${{ steps.cache.outputs.cache-from }} cache-to: ${{ steps.cache.outputs.cache-to }}