Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # ============================================================ | |
| # 节点端 Docker 镜像自动构建并发布到 GHCR | |
| # ============================================================ | |
| # 触发条件: | |
| # 1. 推送到 main 分支且 node/ 目录有变更 | |
| # 2. 推送 v* 格式的 tag(如 v1.0.0) | |
| # 3. 手动触发 | |
| # | |
| # 发布产物: | |
| # - ghcr.io/<owner>/serverstatus-node:latest (main 分支) | |
| # - ghcr.io/<owner>/serverstatus-node:<tag> (版本 tag,如 v1.0.0) | |
| # - ghcr.io/<owner>/serverstatus-node:1.0 (主次版本号) | |
| # - ghcr.io/<owner>/serverstatus-node:sha-<short> (commit SHA 前12位) | |
| # ============================================================ | |
| name: Build & Publish Node Docker Image | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - master | |
| paths: | |
| - "node/**" | |
| - ".github/workflows/docker-node.yml" | |
| tags: | |
| - "v*" | |
| workflow_dispatch: | |
| inputs: | |
| reason: | |
| description: "构建原因" | |
| required: false | |
| default: "manual" | |
| env: | |
| REGISTRY: ghcr.io | |
| # 镜像名:小写仓库所有者 + 仓库名 + -node | |
| # GitHub Actions 中 ${{ github.repository }} 格式为 owner/repo | |
| IMAGE_NAME: ${{ github.repository }}-node | |
| # 同一分支/tag 的新构建取消旧的 | |
| concurrency: | |
| group: docker-node-${{ github.ref }} | |
| cancel-in-progress: true | |
| # GHCR 推送需要写入 packages 权限 | |
| permissions: | |
| contents: read | |
| packages: write | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| steps: | |
| # ---------------------------------------------------- | |
| # 1. 检出代码 | |
| # ---------------------------------------------------- | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| # ---------------------------------------------------- | |
| # 2. 提取镜像元数据(tags + labels) | |
| # ---------------------------------------------------- | |
| - name: Extract metadata | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
| # 生成的 tag 策略: | |
| # type=raw: main 分支 → latest | |
| # type=semver: v1.0.0 → 1.0.0, 1.0, 1 | |
| # type=sha: 每次构建 → sha-abc123def456 | |
| tags: | | |
| type=raw,value=latest,enable={{is_default_branch}} | |
| type=semver,pattern={{version}} | |
| type=semver,pattern={{major}}.{{minor}} | |
| type=semver,pattern={{major}} | |
| type=sha,prefix=sha-,format=short | |
| labels: | | |
| org.opencontainers.image.title=MC服务器状态监测-节点端 | |
| org.opencontainers.image.description=Minecraft Server Status Monitor - Node | |
| org.opencontainers.image.licenses=MIT | |
| # ---------------------------------------------------- | |
| # 3. 登录 GHCR | |
| # ---------------------------------------------------- | |
| - name: Log in to GHCR | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| # ---------------------------------------------------- | |
| # 4. 设置 Docker Buildx(支持多平台 + 缓存) | |
| # ---------------------------------------------------- | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| # ---------------------------------------------------- | |
| # 5. 构建并推送镜像 | |
| # ---------------------------------------------------- | |
| - name: Build and push | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: node/Dockerfile | |
| platforms: linux/amd64,linux/arm64 | |
| push: true | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| # GitHub Actions 缓存加速后续构建 | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| # 构建参数透传 | |
| build-args: | | |
| BUILD_DATE=${{ steps.meta.outputs.date }} | |
| # ---------------------------------------------------- | |
| # 6. 输出镜像摘要 | |
| # ---------------------------------------------------- | |
| - name: Image digest | |
| run: | | |
| echo "✅ 镜像构建并推送成功" | |
| echo "" | |
| echo "镜像地址:" | |
| echo " ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}" | |
| echo "" | |
| echo "Tags:" | |
| echo "${{ steps.meta.outputs.tags }}" | sed 's/^/ /' | |
| echo "" | |
| echo "Digest:" | |
| echo " ${{ steps.meta.outputs.digest }}" |