ci: 自动构建并推送镜像到 ghcr.io(含设为 public + 匿名拉取校验)

This commit is contained in:
personal82555 committed 2026-10-08 20:22:00 +08:00
1 parent abe18d008e
commit 127d14e9b4
1 file changed
+57
+57
View File
@@ -0,0 +1,57 @@
name: Publish Docker image to GHCR
on:
push:
branches: [master]
paths:
- 'Dockerfile'
- 'server.js'
- 'package.json'
- 'app/**'
- '.github/workflows/docker-publish.yml'
workflow_dispatch:
permissions:
contents: read
packages: write
jobs:
build-push:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: |
ghcr.io/${{ github.repository_owner }}/moyu-qile:latest
ghcr.io/${{ github.repository_owner }}/moyu-qile:${{ github.run_number }}
ghcr.io/${{ github.repository_owner }}/moyu-qile:20261008
- name: Make package public (anonymous pull)
continue-on-error: true
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh api -X PATCH "/user/packages/container/moyu-qile" -f visibility=public \
&& echo "✅ 已设为 public" \
|| echo "⚠️ 未能通过 API 设为 public(若匿名拉取失败,需在 GitHub → Packages → moyu-qile 手动改为 Public)"
- name: Verify anonymous pull
continue-on-error: true
run: |
docker logout ghcr.io
docker manifest inspect ghcr.io/${{ github.repository_owner }}/moyu-qile:latest >/dev/null \
&& echo "✅ 匿名可拉取(public 生效)" \
|| echo "⚠️ 匿名仍不可拉取(包还是 private)"