From dd94f229f84f082e45929656e639e835f23ec8f7 Mon Sep 17 00:00:00 2001 From: suyiiyii Date: Tue, 21 Jan 2025 10:39:02 +0800 Subject: [PATCH] =?UTF-8?q?ci(docker):=20=E5=8F=8C=E5=B9=B3=E5=8F=B0?= =?UTF-8?q?=E5=8F=91=E5=B8=83=20Docker=20=E9=95=9C=E5=83=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 Gitea 注册表作为第二个镜像发布平台 - 实现了在 GitHub Actions 中登录 Gitea 注册表并发布镜像 - 保留了原有的 GitHub Container Registry 发布流程 --- .github/workflows/docker-publish.yml | 35 +++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 50e885d..141d38b 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -16,6 +16,7 @@ on: env: # Use docker.io for Docker Hub if empty REGISTRY: ghcr.io + REGISTRY2: git.suyiiyii.top # github.repository as / IMAGE_NAME: ${{ github.repository }} @@ -74,7 +75,7 @@ jobs: # https://github.com/docker/build-push-action - name: Build and push Docker image id: build-and-push - uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0 + uses: docker/build-push-action@0565240e2d4rab88bba5387d719585280857ece09 # v5.0.0 with: context: app/${{ matrix.service }}/. push: ${{ github.event_name != 'pull_request' }} @@ -83,6 +84,38 @@ jobs: cache-from: type=gha cache-to: type=gha,mode=max + + # Login against a Docker registry except on PR + # https://github.com/docker/login-action + - name: Log into registry ${{ env.REGISTRY2 }} + if: github.event_name != 'pull_request' + uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0 + with: + registry: ${{ env.REGISTRY2 }} + username: ${{ github.actor }} + password: ${{ secrets.GITEATOKEN }} + + # Extract metadata (tags, labels) for Docker + # https://github.com/docker/metadata-action + - name: Extract Docker metadata + id: meta-for-gitea + uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0 + with: + images: ${{ env.REGISTRY2 }}/${{ env.IMAGE_NAME }}-${{ matrix.service }} + + # 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 + id: build-and-push-for-gitea + uses: docker/build-push-action@0565240e2d4rab88bba5387d719585280857ece09 # v5.0.0 + with: + context: app/${{ matrix.service }}/. + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta-for-gitea.outputs.tags }} + labels: ${{ steps.meta-for-gitea.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max + # Sign the resulting Docker image digest except on PRs. # This will only write to the public Rekor transparency log when the Docker # repository is public to avoid leaking data. If you would like to publish