预构建Gitea CI工具链镜像
Project CI / Frontend tests (pull_request) Failing after 1m38s
Project CI / Repository checks (pull_request) Failing after 1m38s
Project CI / Native shell tests (pull_request) Failing after 13s
Project CI / Backend tests (pull_request) Failing after 3m23s

固定Node、Rust、Chrome与系统依赖并生成内容寻址镜像
四个CI任务改用genarrative-ci并保留独立npm ci
补充镜像构建装载导出和运行时沙箱校验脚本
同步开发运维文档与项目共享记忆
This commit is contained in:
2026-07-22 14:58:05 +08:00
parent 52ade75007
commit 2e02c28d0a
10 changed files with 398 additions and 224 deletions
+57
View File
@@ -0,0 +1,57 @@
#!/usr/bin/env bash
set -euo pipefail
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)"
expected_toolchain="$(
sed -n 's/^channel = "\([^"]*\)"/\1/p' "${repo_root}/rust-toolchain.toml"
)"
test -n "${expected_toolchain}"
[[ "$(node --version)" == v22.* ]]
rustup toolchain list | rg -q "^${expected_toolchain}(-[^ ]+)?( |$)"
[[ "$(rustup run "${expected_toolchain}" rustc --version)" == "rustc ${expected_toolchain} "* ]]
test "$(readlink -f "$(command -v node)")" = "/usr/local/lib/genarrative-node/bin/node"
test "$(rustup show home)" = "/usr/local/rustup"
for trusted_command in cargo rustc rustdoc rustfmt rustup; do
test "$(command -v "${trusted_command}")" = "/usr/local/bin/${trusted_command}"
done
for command_name in \
bwrap \
cargo \
clang \
cmake \
curl \
ffmpeg \
file \
google-chrome \
lld \
npm \
patchelf \
pkg-config \
rg \
rustfmt \
rustup \
wget; do
command -v "${command_name}" >/dev/null
done
pkg-config --exists \
ayatana-appindicator3-0.1 \
libcurl \
openssl \
webkit2gtk-4.1
node --version
npm --version
rustup run "${expected_toolchain}" rustc --version
rustup run "${expected_toolchain}" cargo --version
rustup run "${expected_toolchain}" rustfmt --version
google-chrome --version
bwrap --version
ffmpeg -version | head -n 1
if [[ "${GENARRATIVE_GITEA_CI_CHECK_RUNTIME:-0}" == '1' ]]; then
bash "${repo_root}/scripts/check-gitea-ci-job-runtime.sh"
fi
+39
View File
@@ -0,0 +1,39 @@
#!/usr/bin/env bash
set -euo pipefail
bwrap_args=(
--die-with-parent
--unshare-all
--unshare-user
--disable-userns
--assert-userns-disabled
--cap-drop ALL
--clearenv
--ro-bind /usr /usr
)
for merged_path in /bin /sbin /lib /lib64; do
if [[ -L "${merged_path}" ]]; then
bwrap_args+=(--symlink "$(readlink "${merged_path}")" "${merged_path}")
fi
done
bwrap_args+=(
--proc /proc
--dev /dev
--tmpfs /tmp
--
/usr/bin/true
)
bwrap "${bwrap_args[@]}"
chrome_output="$(
timeout 30 google-chrome \
--headless=new \
--no-sandbox \
--disable-dev-shm-usage \
--disable-gpu \
--dump-dom \
'data:text/html,<title>genarrative-ci</title>' \
2>/dev/null
)"
rg -q '<title>genarrative-ci</title>' <<< "${chrome_output}"
+99
View File
@@ -0,0 +1,99 @@
#!/usr/bin/env bash
set -euo pipefail
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)"
dockerfile="${repo_root}/deploy/container/gitea-ci-job.Dockerfile"
build_context="${repo_root}/deploy/container"
image_tag="${GENARRATIVE_GITEA_CI_IMAGE_TAG:-genarrative/gitea-project-ci:20260722.1}"
runner_container="${GENARRATIVE_GITEA_RUNNER_CONTAINER:-gitea-runner}"
usage() {
cat <<'EOF'
用法:
bash scripts/gitea-ci-job-image.sh build
bash scripts/gitea-ci-job-image.sh verify [镜像引用]
bash scripts/gitea-ci-job-image.sh load-runner [镜像引用]
bash scripts/gitea-ci-job-image.sh export <归档路径> [镜像引用]
环境变量:
GENARRATIVE_GITEA_CI_IMAGE_TAG 覆盖本地构建 tag
GENARRATIVE_GITEA_RUNNER_CONTAINER 覆盖 Runner 容器名
EOF
}
image_id() {
docker image inspect --format '{{.Id}}' "$1"
}
verify_image() {
local image_ref="$1"
docker run --rm \
--mount "type=bind,src=${repo_root}/scripts,dst=/usr/local/scripts,readonly" \
--mount "type=bind,src=${repo_root}/scripts/check-gitea-ci-job-image.sh,dst=/usr/local/bin/check-gitea-ci-job-image.sh,readonly" \
--mount "type=bind,src=${repo_root}/rust-toolchain.toml,dst=/usr/local/rust-toolchain.toml,readonly" \
"${image_ref}" \
bash /usr/local/bin/check-gitea-ci-job-image.sh
}
command_name="${1:-}"
case "${command_name}" in
build)
image_revision="$(sha256sum "${dockerfile}")"
image_revision="${image_revision%% *}"
docker build \
--pull=false \
--build-arg "IMAGE_REVISION=${image_revision}" \
--file "${dockerfile}" \
--tag "${image_tag}" \
"${build_context}"
verify_image "${image_tag}"
printf 'image_tag=%s\n' "${image_tag}"
printf 'image_id=%s\n' "$(image_id "${image_tag}")"
;;
verify)
image_ref="${2:-${image_tag}}"
verify_image "${image_ref}"
printf 'image_ref=%s\n' "${image_ref}"
printf 'image_id=%s\n' "$(image_id "${image_ref}")"
;;
load-runner)
image_ref="${2:-${image_tag}}"
verify_image "${image_ref}"
expected_image_id="$(image_id "${image_ref}")"
docker save "${image_ref}" | docker exec -i "${runner_container}" docker load
loaded_image_id="$(
docker exec "${runner_container}" \
docker image inspect --format '{{.Id}}' "${image_ref}"
)"
test "${loaded_image_id}" = "${expected_image_id}"
docker exec -i "${runner_container}" \
docker run --rm --interactive \
--security-opt seccomp=unconfined \
--security-opt systempaths=unconfined \
"${loaded_image_id}" bash -s \
< "${repo_root}/scripts/check-gitea-ci-job-runtime.sh"
printf 'runner_image_tag=%s\n' "${image_ref}"
printf 'runner_image_id=%s\n' "${loaded_image_id}"
printf 'runner_label_image=docker://%s\n' "${loaded_image_id}"
;;
export)
archive_path="${2:-}"
image_ref="${3:-${image_tag}}"
test -n "${archive_path}"
verify_image "${image_ref}"
docker save "${image_ref}" | zstd --threads=0 --ultra -10 -o "${archive_path}"
archive_dir="$(cd "$(dirname "${archive_path}")" && pwd -P)"
archive_name="$(basename "${archive_path}")"
(
cd "${archive_dir}"
sha256sum "${archive_name}" > "${archive_name}.sha256"
)
printf 'archive=%s\n' "${archive_path}"
printf 'image_id=%s\n' "$(image_id "${image_ref}")"
;;
*)
usage >&2
exit 2
;;
esac