- 固定 Docker 与测试镜像使用 Node.js 24 trixie slim 基础镜像。 - 安装 Chromium 所需系统运行库,并清理 apt 索引、缓存和临时文件,降低最终镜像体积。 - 增加 Chromium 实际启动、服务健康检查以及 Go 和前端测试门禁,门禁通过后才发布镜像标签。 - 修复 v1.2.3 版本标签触发,自动构建版本镜像、各平台安装包并创建 GitHub Release。 - 完善版本产物校验、SHA256SUMS 校验和以及正式版本标签规则。 - 将 Linux、Windows、macOS 和 Docker 的 Playwright runtime 缓存改为独立恢复与立即保存。 - 修复 Chromium runtime 校验中的绝对路径问题,并补充平台与安装器源码缓存键。 - 同步更新发布文档、打包规范和前端路由测试断言。
319 lines
11 KiB
YAML
319 lines
11 KiB
YAML
name: 构建并发布 Docker 镜像
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
- codex/desktop-packaging
|
|
tags:
|
|
- 'v*.*.*'
|
|
workflow_dispatch:
|
|
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
|
|
concurrency:
|
|
group: docker-publish-${{ github.ref }}
|
|
cancel-in-progress: true
|
|
|
|
jobs:
|
|
verify:
|
|
name: Docker 发布测试门禁
|
|
runs-on: ubuntu-24.04
|
|
steps:
|
|
- name: 校验版本标签
|
|
if: startsWith(github.ref, 'refs/tags/')
|
|
shell: bash
|
|
run: |
|
|
set -Eeuo pipefail
|
|
if [[ ! "$GITHUB_REF_NAME" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
|
|
echo "版本标签必须符合 v1.2.3 格式:$GITHUB_REF_NAME" >&2
|
|
exit 1
|
|
fi
|
|
|
|
- name: 检出代码
|
|
uses: actions/checkout@v6
|
|
|
|
- name: 配置 Go
|
|
uses: actions/setup-go@v7
|
|
with:
|
|
go-version-file: go.mod
|
|
cache: true
|
|
|
|
- name: 配置 Node.js
|
|
uses: actions/setup-node@v6
|
|
with:
|
|
node-version: 24
|
|
cache: npm
|
|
cache-dependency-path: frontend/package-lock.json
|
|
|
|
- name: 验证前端
|
|
shell: bash
|
|
run: |
|
|
set -Eeuo pipefail
|
|
npm ci --prefix frontend
|
|
npm run typecheck --prefix frontend
|
|
npm test --prefix frontend
|
|
npm run build --prefix frontend
|
|
|
|
- name: 验证 Go 服务
|
|
run: |
|
|
go vet ./...
|
|
go test ./...
|
|
|
|
build:
|
|
name: 构建镜像 (${{ matrix.arch }})
|
|
needs: verify
|
|
runs-on: ${{ matrix.runner }}
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
include:
|
|
- arch: amd64
|
|
runner: ubuntu-24.04
|
|
platform: linux/amd64
|
|
playwright_platform: debian13-x64
|
|
- arch: arm64
|
|
runner: ubuntu-24.04-arm
|
|
platform: linux/arm64
|
|
playwright_platform: debian13-arm64
|
|
steps:
|
|
- name: 检出代码
|
|
uses: actions/checkout@v6
|
|
|
|
- name: 校验 runner 原生架构
|
|
shell: bash
|
|
env:
|
|
EXPECTED_ARCH: ${{ matrix.arch }}
|
|
run: |
|
|
set -Eeuo pipefail
|
|
case "$(uname -m)" in
|
|
x86_64) actual_arch=amd64 ;;
|
|
aarch64|arm64) actual_arch=arm64 ;;
|
|
*) echo "不支持的 runner 架构:$(uname -m)" >&2; exit 1 ;;
|
|
esac
|
|
if [ "$actual_arch" != "$EXPECTED_ARCH" ]; then
|
|
echo "runner 架构 $actual_arch 与目标架构 $EXPECTED_ARCH 不一致,拒绝使用模拟器构建。" >&2
|
|
exit 1
|
|
fi
|
|
|
|
- name: 配置 Go
|
|
uses: actions/setup-go@v7
|
|
with:
|
|
go-version-file: go.mod
|
|
cache: true
|
|
|
|
- name: 配置 Node.js
|
|
uses: actions/setup-node@v6
|
|
with:
|
|
node-version: 24
|
|
|
|
- name: 恢复 Docker Chromium runtime 缓存
|
|
id: cache-docker-playwright
|
|
uses: actions/cache/restore@v5
|
|
with:
|
|
path: .docker/playwright-runtime/${{ matrix.arch }}
|
|
key: ydisks-playwright-runtime-v6-docker-${{ matrix.arch }}-${{ matrix.playwright_platform }}-${{ hashFiles('go.mod', 'go.sum', 'cmd/browser-install/**') }}
|
|
|
|
- name: 准备 Docker Chromium runtime
|
|
if: steps.cache-docker-playwright.outputs.cache-hit != 'true'
|
|
shell: bash
|
|
env:
|
|
GOARCH: ${{ matrix.arch }}
|
|
PLAYWRIGHT_HOST_PLATFORM_OVERRIDE: ${{ matrix.playwright_platform }}
|
|
run: |
|
|
set -Eeuo pipefail
|
|
mkdir -p ".docker/playwright-runtime/$GOARCH/playwright-driver" ".docker/playwright-runtime/$GOARCH/playwright-browsers"
|
|
GOOS=linux GOARCH="$GOARCH" CGO_ENABLED=0 go build \
|
|
-trimpath -ldflags='-s -w' \
|
|
-o "$RUNNER_TEMP/browser-install" ./cmd/browser-install
|
|
"$RUNNER_TEMP/browser-install" \
|
|
-driver-dir "$PWD/.docker/playwright-runtime/$GOARCH/playwright-driver" \
|
|
-browser-dir "$PWD/.docker/playwright-runtime/$GOARCH/playwright-browsers"
|
|
|
|
- name: 校验 Docker Chromium runtime
|
|
shell: bash
|
|
env:
|
|
GOARCH: ${{ matrix.arch }}
|
|
run: |
|
|
set -Eeuo pipefail
|
|
runtime_dir=".docker/playwright-runtime/$GOARCH"
|
|
test -x "$runtime_dir/playwright-driver/node"
|
|
test -f "$runtime_dir/playwright-driver/package/cli.js"
|
|
chromium_path="$(find "$runtime_dir/playwright-browsers" -type f \
|
|
\( -name chrome -o -name headless_shell -o -name chrome-headless-shell \) -perm -111 -print -quit)"
|
|
test -n "$chromium_path"
|
|
chromium_revision="$(RUNTIME_SPEC="$PWD/$runtime_dir/playwright-driver/package/browsers.json" node -e 'const b=require(process.env.RUNTIME_SPEC).browsers; console.log(b.find(x=>x.name==="chromium").revision)')"
|
|
headless_revision="$(RUNTIME_SPEC="$PWD/$runtime_dir/playwright-driver/package/browsers.json" node -e 'const b=require(process.env.RUNTIME_SPEC).browsers; console.log(b.find(x=>x.name==="chromium-headless-shell").revision)')"
|
|
test -d "$runtime_dir/playwright-browsers/chromium-$chromium_revision"
|
|
test -d "$runtime_dir/playwright-browsers/chromium_headless_shell-$headless_revision"
|
|
|
|
- name: 保存 Docker Chromium runtime 缓存
|
|
if: steps.cache-docker-playwright.outputs.cache-hit != 'true'
|
|
uses: actions/cache/save@v5
|
|
with:
|
|
path: .docker/playwright-runtime/${{ matrix.arch }}
|
|
key: ${{ steps.cache-docker-playwright.outputs.cache-primary-key }}
|
|
|
|
- name: 配置 Docker Buildx
|
|
uses: docker/setup-buildx-action@v4
|
|
|
|
- name: 登录 GitHub Container Registry
|
|
uses: docker/login-action@v4
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: 生成小写镜像名称
|
|
id: image
|
|
shell: bash
|
|
run: echo "name=ghcr.io/${GITHUB_REPOSITORY,,}" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: 构建并推送原生架构摘要
|
|
id: build
|
|
uses: docker/build-push-action@v7
|
|
with:
|
|
context: .
|
|
file: Dockerfile.debian13
|
|
platforms: ${{ matrix.platform }}
|
|
outputs: type=image,name=${{ steps.image.outputs.name }},push-by-digest=true,name-canonical=true,push=true
|
|
cache-from: type=gha,scope=ydisks-docker-${{ matrix.arch }}
|
|
cache-to: type=gha,mode=max,scope=ydisks-docker-${{ matrix.arch }}
|
|
provenance: mode=max
|
|
sbom: true
|
|
|
|
- name: 验证待发布镜像中的 Chromium 与服务
|
|
shell: bash
|
|
env:
|
|
IMAGE_NAME: ${{ steps.image.outputs.name }}
|
|
IMAGE_DIGEST: ${{ steps.build.outputs.digest }}
|
|
run: |
|
|
set -Eeuo pipefail
|
|
image_ref="$IMAGE_NAME@$IMAGE_DIGEST"
|
|
docker pull "$image_ref"
|
|
|
|
docker run --rm --entrypoint sh "$image_ref" -ec '
|
|
chromium_path="$(find /ms-playwright/chromium-* -type f \
|
|
-name chrome -perm -111 -print -quit)"
|
|
test -n "$chromium_path"
|
|
timeout 45 "$chromium_path" \
|
|
--headless --no-sandbox --disable-gpu --disable-dev-shm-usage \
|
|
--dump-dom about:blank | grep -q "<html"
|
|
'
|
|
|
|
container_id="$(docker run -d -p 127.0.0.1::59188 "$image_ref")"
|
|
cleanup() {
|
|
docker logs "$container_id" || true
|
|
docker rm -f "$container_id" >/dev/null 2>&1 || true
|
|
}
|
|
trap cleanup EXIT
|
|
host_port="$(docker port "$container_id" 59188/tcp | sed -n 's/.*://p' | head -n 1)"
|
|
test -n "$host_port"
|
|
for attempt in $(seq 1 60); do
|
|
if health="$(curl --fail --silent --show-error "http://127.0.0.1:$host_port/health" 2>/dev/null)"; then
|
|
printf '%s' "$health" | grep -q '"status":"ok"'
|
|
printf '%s' "$health" | grep -q '"database":"ok"'
|
|
exit 0
|
|
fi
|
|
if ! docker inspect -f '{{.State.Running}}' "$container_id" | grep -q true; then
|
|
echo '待发布镜像中的服务提前退出。' >&2
|
|
exit 1
|
|
fi
|
|
sleep 1
|
|
done
|
|
echo '待发布镜像未能在 60 秒内通过健康检查。' >&2
|
|
exit 1
|
|
|
|
- name: 保存镜像摘要
|
|
shell: bash
|
|
env:
|
|
IMAGE_DIGEST: ${{ steps.build.outputs.digest }}
|
|
run: |
|
|
set -Eeuo pipefail
|
|
mkdir -p dist/digests
|
|
touch "dist/digests/${IMAGE_DIGEST#sha256:}"
|
|
|
|
- name: 上传镜像摘要
|
|
uses: actions/upload-artifact@v7
|
|
with:
|
|
name: ydisks-docker-digest-${{ matrix.arch }}
|
|
path: dist/digests/*
|
|
if-no-files-found: error
|
|
retention-days: 1
|
|
|
|
publish:
|
|
name: 合并多架构镜像
|
|
needs: build
|
|
runs-on: ubuntu-24.04
|
|
steps:
|
|
- name: 配置 Docker Buildx
|
|
uses: docker/setup-buildx-action@v4
|
|
|
|
- name: 下载镜像摘要
|
|
uses: actions/download-artifact@v8
|
|
with:
|
|
pattern: ydisks-docker-digest-*
|
|
path: dist/digests
|
|
merge-multiple: true
|
|
|
|
- name: 登录 GitHub Container Registry
|
|
uses: docker/login-action@v4
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: 生成小写镜像名称
|
|
id: image
|
|
shell: bash
|
|
run: echo "name=ghcr.io/${GITHUB_REPOSITORY,,}" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: 生成镜像标签
|
|
id: meta
|
|
uses: docker/metadata-action@v6
|
|
with:
|
|
images: ${{ steps.image.outputs.name }}
|
|
tags: |
|
|
type=ref,event=tag
|
|
type=semver,pattern={{version}}
|
|
type=semver,pattern={{major}}.{{minor}}
|
|
type=sha,format=long
|
|
type=raw,value=main,enable=${{ github.ref == 'refs/heads/main' }}
|
|
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
|
|
type=raw,value=desktop-packaging,enable=${{ github.ref == 'refs/heads/codex/desktop-packaging' }}
|
|
type=raw,value=alpha,enable=${{ github.ref == 'refs/heads/codex/desktop-packaging' }}
|
|
|
|
- name: 创建并推送多架构 manifest
|
|
shell: bash
|
|
env:
|
|
IMAGE_NAME: ${{ steps.image.outputs.name }}
|
|
IMAGE_TAGS: ${{ steps.meta.outputs.tags }}
|
|
run: |
|
|
set -Eeuo pipefail
|
|
mapfile -t digest_files < <(find dist/digests -maxdepth 1 -type f -print | sort)
|
|
if [ "${#digest_files[@]}" -ne 2 ]; then
|
|
echo "预期 2 个镜像摘要,实际 ${#digest_files[@]} 个。" >&2
|
|
exit 1
|
|
fi
|
|
digest_args=()
|
|
for digest_file in "${digest_files[@]}"; do
|
|
digest_args+=("$IMAGE_NAME@sha256:$(basename "$digest_file")")
|
|
done
|
|
tag_args=()
|
|
while IFS= read -r tag; do
|
|
[ -n "$tag" ] && tag_args+=(--tag "$tag")
|
|
done <<< "$IMAGE_TAGS"
|
|
docker buildx imagetools create "${tag_args[@]}" "${digest_args[@]}"
|
|
|
|
- name: 检查多架构 manifest
|
|
shell: bash
|
|
env:
|
|
IMAGE_TAGS: ${{ steps.meta.outputs.tags }}
|
|
run: |
|
|
set -Eeuo pipefail
|
|
first_tag="$(printf '%s\n' "$IMAGE_TAGS" | sed -n '/./{p;q;}')"
|
|
test -n "$first_tag"
|
|
docker buildx imagetools inspect "$first_tag"
|