From f6bd32490350e46c47442fd5096ac648c4ed3991 Mon Sep 17 00:00:00 2001 From: TatLead Date: Sun, 3 Nov 2024 07:10:21 +0800 Subject: [PATCH] Create docker-publish.yml --- .github/workflows/docker-publish.yml | 54 ++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 .github/workflows/docker-publish.yml diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 0000000..86b72e6 --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -0,0 +1,54 @@ +name: Publish Docker Image (GPR) + +on: + workflow_dispatch: + schedule: + - cron: '0 0 * * *' + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Check if tag exists + if: github.event_name != 'workflow_dispatch' + id: tag-exists + run: | + if docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.TAG }}; then + echo "TAG_EXISTS=true" >> $GITHUB_ENV + fi + + - name: Log in to the Container registry + if: env.TAG_EXISTS == 'false' || github.event_name == 'workflow_dispatch' + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + if: env.TAG_EXISTS == 'false' || github.event_name == 'workflow_dispatch' + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Push Docker image + if: env.TAG_EXISTS == 'false' || github.event_name == 'workflow_dispatch' + uses: docker/build-push-action@v6 + with: + context: . + push: true + provenance: false + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + annotations: ${{ steps.meta.outputs.annotations }}