Files
secgate-vpn-docker/.github/workflows/docker.yml
T
yuez cf2bbbb3d9 feat(ci): main 分支构建镜像并发布到 GHCR
- .github/workflows/docker.yml:push main / tag v* 构建 linux/amd64 镜像推
  ghcr.io/zgs225/secgate-vpn-docker(latest、客户端版本、sha-、semver tag),
  PR 只构建 + 冒烟检查;厂商 deb 由 fetch-client-deb.sh 在 CI 取包并校验,按
  版本缓存
- compose/Makefile/deploy-nas.sh 默认镜像改为 ghcr.io,新增 make pull,
  NAS 部署优先 docker pull,失败再回退 save/load
- README/SECURITY/vendor 文档补充 GHCR 用法与包可见性说明
- Dockerfile 补 OCI source/url/licenses 标签
2026-11-13 16:12:38 +08:00

132 lines
4.3 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 在 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/<owner>/<repo>: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"