From f29e4b18d7ca53e94adc114ec0cc883c0febe8f2 Mon Sep 17 00:00:00 2001 From: vicnoah Date: Wed, 5 Nov 2025 16:55:09 +0800 Subject: [PATCH] =?UTF-8?q?ci(docker):=20=E6=B7=BB=E5=8A=A0Docker=E9=95=9C?= =?UTF-8?q?=E5=83=8F=E6=9E=84=E5=BB=BA=E5=92=8C=E6=8E=A8=E9=80=81=E7=9A=84?= =?UTF-8?q?GitHub=20Actions=E5=B7=A5=E4=BD=9C=E6=B5=81=20(#124)=20*=20ci(d?= =?UTF-8?q?ocker):=20=E6=B7=BB=E5=8A=A0Docker=E9=95=9C=E5=83=8F=E6=9E=84?= =?UTF-8?q?=E5=BB=BA=E5=92=8C=E6=8E=A8=E9=80=81=E7=9A=84GitHub=20Actions?= =?UTF-8?q?=E5=B7=A5=E4=BD=9C=E6=B5=81=20-=20=E6=94=AF=E6=8C=81=E5=9C=A8ma?= =?UTF-8?q?in=E5=92=8Cdevelop=E5=88=86=E6=94=AF=E5=8F=8A=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E6=A0=87=E7=AD=BE=E7=9A=84push=E4=BA=8B=E4=BB=B6=E8=A7=A6?= =?UTF-8?q?=E5=8F=91=20-=20=E6=94=AF=E6=8C=81Pull=20Request=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6=E5=8F=8A=E6=89=8B=E5=8A=A8=E8=A7=A6=E5=8F=91=E5=B7=A5?= =?UTF-8?q?=E4=BD=9C=E6=B5=81=20-=20=E9=85=8D=E7=BD=AE=E4=BA=86backend?= =?UTF-8?q?=E5=92=8Cfrontend=E4=B8=A4=E4=B8=AA=E9=95=9C=E5=83=8F=E7=9A=84?= =?UTF-8?q?=E6=9E=84=E5=BB=BA=E7=AD=96=E7=95=A5=20-=20=E4=BD=BF=E7=94=A8QE?= =?UTF-8?q?MU=E5=92=8CDocker=20Buildx=E5=AE=9E=E7=8E=B0=E5=A4=9A=E5=B9=B3?= =?UTF-8?q?=E5=8F=B0=E6=9E=84=E5=BB=BA=EF=BC=88amd64=E5=92=8Carm64?= =?UTF-8?q?=EF=BC=89=20-=20=E9=9B=86=E6=88=90GitHub=20Container=20Registry?= =?UTF-8?q?=E5=92=8CDocker=20Hub=E7=99=BB=E5=BD=95=20-=20=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E7=94=9F=E6=88=90=E9=95=9C=E5=83=8F=E5=85=83=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=92=8C=E5=A4=9A=E6=A0=87=E7=AD=BE=E6=94=AF=E6=8C=81?= =?UTF-8?q?=20-=20=E6=94=AF=E6=8C=81=E5=9F=BA=E4=BA=8EGitHub=20Actions?= =?UTF-8?q?=E7=BC=93=E5=AD=98=E6=8F=90=E5=8D=87=E6=9E=84=E5=BB=BA=E9=80=9F?= =?UTF-8?q?=E5=BA=A6=20-=20=E5=AE=9E=E7=8E=B0=E6=A0=B9=E6=8D=AE=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6=E7=B1=BB=E5=9E=8B=E8=87=AA=E5=8A=A8=E5=86=B3=E5=AE=9A?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E6=8E=A8=E9=80=81=E9=95=9C=E5=83=8F=20-=20?= =?UTF-8?q?=E8=BE=93=E5=87=BA=E6=9E=84=E5=BB=BA=E5=AE=8C=E6=88=90=E7=9A=84?= =?UTF-8?q?=E9=95=9C=E5=83=8F=E6=91=98=E8=A6=81=E4=BF=A1=E6=81=AF=20*=20Up?= =?UTF-8?q?date=20Docker=20Hub=20login=20condition=20in=20workflow=20*=20F?= =?UTF-8?q?ix=20Docker=20Hub=20login=20condition=20in=20workflow=20*=20Sim?= =?UTF-8?q?plify=20Docker=20Hub=20login=20step=20Removed=20conditional=20c?= =?UTF-8?q?heck=20for=20Docker=20Hub=20username.=20*=20Change=20branch=20n?= =?UTF-8?q?ames=20in=20Docker=20build=20workflow=20*=20Update=20docker-bui?= =?UTF-8?q?ld.yml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/docker-build.yml | 95 ++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 .github/workflows/docker-build.yml diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml new file mode 100644 index 00000000..84036674 --- /dev/null +++ b/.github/workflows/docker-build.yml @@ -0,0 +1,95 @@ +name: Build and Push Docker Images + +on: + push: + branches: + - main + - dev + tags: + - 'v*' + pull_request: + branches: + - main + - dev + workflow_dispatch: + +env: + REGISTRY_GHCR: ghcr.io + IMAGE_NAME_BACKEND: ${{ github.repository }}/nofx-backend + IMAGE_NAME_FRONTEND: ${{ github.repository }}/nofx-frontend + +jobs: + build-and-push: + runs-on: ubuntu-22.04 + permissions: + contents: read + packages: write + + strategy: + matrix: + include: + - name: backend + dockerfile: ./docker/Dockerfile.backend + image_suffix: backend + - name: frontend + dockerfile: ./docker/Dockerfile.frontend + image_suffix: frontend + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY_GHCR }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Log in to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + continue-on-error: true + + - name: Extract metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: | + ${{ env.REGISTRY_GHCR }}/${{ github.repository }}/nofx-${{ matrix.image_suffix }} + ${{ secrets.DOCKERHUB_USERNAME && format('{0}/nofx-{1}', secrets.DOCKERHUB_USERNAME, matrix.image_suffix) || '' }} + tags: | + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + type=sha,prefix={{branch}} + type=raw,value=latest,enable={{is_default_branch}} + + - name: Build and push ${{ matrix.name }} image + uses: docker/build-push-action@v5 + with: + context: . + file: ${{ matrix.dockerfile }} + platforms: linux/amd64,linux/arm64 + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max + build-args: | + BUILD_DATE=${{ github.event.head_commit.timestamp }} + VCS_REF=${{ github.sha }} + VERSION=${{ github.ref_name }} + + - name: Image digest + run: echo "Image digest for ${{ matrix.name }} - ${{ steps.meta.outputs.digest }}"