# 在 main 分支上构建图形端镜像并发布到 GitHub Container Registry(ghcr.io)。 # # 关键点:厂商 deb 不入库,CI 里用 scripts/fetch-client-deb.sh 从官方下载站取包并按 # md5 校验(命中 actions/cache 时跳过 60 MB 下载)。镜像只有 amd64 版本(厂商包是 # 海光麒麟 amd64),所以固定 platforms: linux/amd64。 # # - push 到 main → ghcr.io//:latest + :1.1.3.1010701 + :sha-xxxxxxx # - push tag v1.2.3 → 额外打 :1.2.3 / :1.2 # - PR → 只构建不推(load 到 runner 上跑冒烟检查) # - 手动 workflow_dispatch → 同上,按分支走 name: Build & Publish on: push: branches: [main] tags: ["v*"] pull_request: branches: [main] workflow_dispatch: permissions: contents: read packages: write concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: ${{ github.event_name == 'pull_request' }} env: IMAGE: ghcr.io/${{ github.repository }} # 与 Dockerfile 里 LABEL org.opencontainers.image.version 保持一致 CLIENT_VERSION: "1.1.3.1010701" CLIENT_DEB: vendor/KYLIN-X86_SDWANClient_Setup.deb CLIENT_MD5: 49e3472a779e62be596117e4cefaee4a jobs: image: name: Build linux/amd64 image runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 - name: Cache vendor deb id: deb-cache uses: actions/cache@v4 with: path: ${{ env.CLIENT_DEB }} key: vendor-deb-${{ env.CLIENT_VERSION }}-${{ env.CLIENT_MD5 }} - name: Fetch vendor deb if: steps.deb-cache.outputs.cache-hit != 'true' run: ./scripts/fetch-client-deb.sh - name: Verify vendor deb run: | set -euo pipefail got=$(md5sum "$CLIENT_DEB" | awk '{print $1}') echo "vendor deb md5=$got" [ "$got" = "$CLIENT_MD5" ] || { echo "md5 与官方不一致" >&2; exit 1; } if [ -f "$CLIENT_DEB.sha256" ]; then ( cd vendor && sha256sum -c "$(basename "$CLIENT_DEB").sha256" ) else echo "无 sha256 文件(缓存命中时正常),跳过" fi - name: Set up Buildx uses: docker/setup-buildx-action@v3 - name: Log in to GHCR if: github.event_name != 'pull_request' uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Docker metadata id: meta uses: docker/metadata-action@v5 with: images: ${{ env.IMAGE }} tags: | type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }} type=raw,value=${{ env.CLIENT_VERSION }} type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}} type=sha,format=short,prefix=sha- - name: Build and push id: build uses: docker/build-push-action@v6 with: context: . file: ./Dockerfile platforms: linux/amd64 # PR 只构建并 load 到 runner,main/tag 才推 push: ${{ github.event_name != 'pull_request' }} load: ${{ 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 provenance: true sbom: true - name: Smoke test image if: github.event_name == 'pull_request' run: | set -euo pipefail image=$(printf '%s\n' "${{ steps.meta.outputs.tags }}" | head -n1) docker run --rm --entrypoint bash "$image" -c ' set -e test -x /opt/sslvpnclient/files/bin/sslvpn test -x /usr/local/bin/secgate-entrypoint.sh fc-list | grep -qi sourcehan command -v Xvfb x11vnc openbox websockify microsocks >/dev/null ' echo "冒烟检查通过:$image" - name: Summary run: | { echo "### ${{ steps.meta.outputs.version }}" echo echo '```' printf '%s\n' "${{ steps.meta.outputs.tags }}" echo '```' echo echo "digest: \`${{ steps.build.outputs.digest }}\`" } >> "$GITHUB_STEP_SUMMARY"