From 756da1054c8a44e8a4d89e1b4ef7b0e274d29beb Mon Sep 17 00:00:00 2001 From: Mayo Takanashi Date: Mon, 3 Feb 2025 15:21:32 +0900 Subject: [PATCH 1/4] chore: add Git commit sha to container tags --- .github/workflows/main.yml | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 277adeb..0945887 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -42,9 +42,6 @@ jobs: - name: Checkout the source code uses: actions/checkout@v4 - - name: Build the Docker image - run: docker build -t ghcr.io/${{ github.repository }}/${{ matrix.image }}:latest ${{ matrix.image }}/ - - name: Authenticate with GitHub Container Registry uses: docker/login-action@v3 with: @@ -53,6 +50,11 @@ jobs: password: ${{ secrets.GITHUB_TOKEN }} if: github.event_name == 'push' && github.ref == 'refs/heads/master' - - name: Upload the Docker image to GitHub Container Registry - run: docker push ghcr.io/${{ github.repository }}/${{ matrix.image }}:latest - if: github.event_name == 'push' && github.ref == 'refs/heads/master' + - name: Build and push + uses: docker/build-push-action@v6 + with: + context: ${{ matrix.image }}/ + push: github.event_name == 'push' && github.ref == 'refs/heads/master' + tags: | + ghcr.io/${{ github.repository }}/${{ matrix.image }}:latest + ghcr.io/${{ github.repository }}/${{ matrix.image }}:${{ github.sha }} From 21ac9c4e7d4cd8aaca73197644e5706db24fadba Mon Sep 17 00:00:00 2001 From: Mayo Takanashi Date: Mon, 3 Feb 2025 15:40:51 +0900 Subject: [PATCH 2/4] Fix expression --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0945887..bdecb64 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -54,7 +54,7 @@ jobs: uses: docker/build-push-action@v6 with: context: ${{ matrix.image }}/ - push: github.event_name == 'push' && github.ref == 'refs/heads/master' + push: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }} tags: | ghcr.io/${{ github.repository }}/${{ matrix.image }}:latest ghcr.io/${{ github.repository }}/${{ matrix.image }}:${{ github.sha }} From 05b30885308e06bb6f8978cfd404a356e08c8052 Mon Sep 17 00:00:00 2001 From: Mayo Takanashi Date: Mon, 3 Feb 2025 15:56:11 +0900 Subject: [PATCH 3/4] Use metadata instead of tags --- .github/workflows/main.yml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index bdecb64..627bc4c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -50,11 +50,16 @@ jobs: password: ${{ secrets.GITHUB_TOKEN }} if: github.event_name == 'push' && github.ref == 'refs/heads/master' + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: ghcr.io/${{ github.repository }}/${{ matrix.image }}:latest + - name: Build and push uses: docker/build-push-action@v6 with: context: ${{ matrix.image }}/ push: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }} - tags: | - ghcr.io/${{ github.repository }}/${{ matrix.image }}:latest - ghcr.io/${{ github.repository }}/${{ matrix.image }}:${{ github.sha }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} From c968c2e7379b65bd329f806aff687e259d85b3fa Mon Sep 17 00:00:00 2001 From: Mayo Takanashi Date: Mon, 3 Feb 2025 15:57:12 +0900 Subject: [PATCH 4/4] Remove latest suffix as it already has --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 627bc4c..ed46a83 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -54,7 +54,7 @@ jobs: id: meta uses: docker/metadata-action@v5 with: - images: ghcr.io/${{ github.repository }}/${{ matrix.image }}:latest + images: ghcr.io/${{ github.repository }}/${{ matrix.image }} - name: Build and push uses: docker/build-push-action@v6