first commit

This commit is contained in:
2026-11-18 02:05:15 +08:00
commit 3abb7c0a7b
17 changed files with 1798 additions and 0 deletions
+76
View File
@@ -0,0 +1,76 @@
> 本文作者:丁辉
# Actions 工作流说明
`workflows/containerd-bundle.yml` 一份文件同时兼容 Gitea Actions 与 GitHub Actions: Gitea 的
`WORKFLOW_DIRS` 默认为 `.gitea/workflows,.github/workflows` 并取第一个存在的目录, 本仓库没有
`.gitea`, 因此两边都能读到。
## 流水线介绍
| 步骤 | 动作 |
| :--: | :----------------------------------------------------------: |
| 1 | 拉取仓库 |
| 2 | 读 `.github/bundle-files.txt` 的唯一一行, 作为整包文件名与版本号 |
| 3 | 调 `scripts/download-containerd.sh --all` 下载并校验安装包, 已存在且校验通过的自动跳过 |
| 4 | 在 `packages/` 生成 `SHA256SUMS`, 把项目本体与 `packages` 打成整包, 临时目录随打随删 |
| 5 | 非 github.com 时按版本号建 Release 并上传整包附件, 附件已存在则跳过 |
| 6 | github.com 时同样按版本号建 Release, 用 gh 上传整包附件 |
## 触发方式
| 方式 | 说明 |
| :------: | :----------------------------------------------------------: |
| 手动运行 | 仓库 Actions 页面选择 `containerd bundle`, 可选输入 `force_download=true` 强制重新下载 |
| 标签触发 | 推送 `v*` 标签 |
## 前置条件
| 项 | 要求 |
| :-----------------------: | :---------------------------------------------------------------------------------------: |
| runner | 标签需匹配 `runs-on: ubuntu-latest`, 且能访问 github.com |
| `RELEASE_TOKEN` | Gitea 访问令牌, 至少 `write:repository` |
| `REGISTRY_USER` | 上传账号, 未配置时使用触发人 |
| `GITHUB_TOKEN` | Github 访问令牌 |
## 版本获取
| 位置 | 作用 |
| :------------------------: | :----------------------------------------------------: |
| `vars/containerd.yml` | 决定下载哪个版本的安装包, 由下载脚本读取 |
| `.github/bundle-files.txt` | 决定整包文件名, 只写一行, 版本号自己填, 流水线原样读取 |
> 必须以 `.tar.gz` 结尾, 注释行会被忽略.
## Release 与附件
Release 的标签名就是版本号。
同名 Release 已存在时直接复用, 附件同名则跳过,。
## 包内结构
打包时排除 `.git`, `.github`, 其余原样保留。
```
Ansible-Containerd-bundle-<版本号>.tar.gz
└── Ansible-Containerd/
├── containerd.yml
├── containerd-uninstall.yml
├── ansible.cfg
├── hosts.ini
├── README.md
├── callback_plugins/
├── configs/
├── scripts/
├── templates/
├── vars/
└── packages/
├── containerd-*-linux-amd64.tar.gz
├── runc.amd64
├── cni-plugins-linux-amd64-v*.tgz
├── crictl-v*-linux-amd64.tar.gz
├── nerdctl-*-linux-amd64.tar.gz
└── SHA256SUMS
```
+3
View File
@@ -0,0 +1,3 @@
# 只写一行整包文件名, 版本号由你填写, 流水线运行时直接读取此行.
# 包内为 packages 目录与 SHA256SUMS, 安装包下载版本仍以 vars/containerd.yml 为准.
ansible-containerd-bundle-2.4.2-amd64.tar.gz
+153
View File
@@ -0,0 +1,153 @@
# 兼容 Gitea Actions 与 GitHub Actions, 使用说明见 .github/README.md
# 整包文件名由 .github/bundle-files.txt 一行内容决定, 上传落到仓库 Release 附件
name: containerd bundle
on:
workflow_dispatch:
inputs:
force_download:
description: "重新下载已存在的安装包, 填 true"
required: false
default: "false"
push:
tags:
- "v*"
env:
PACKAGE_NAME: Ansible-Containerd-bundle
jobs:
bundle:
runs-on: ubuntu-latest
timeout-minutes: 90
permissions:
contents: write
steps:
- name: 1.拉取仓库
uses: actions/checkout@v4
- name: 2.读取整包文件名
run: |
set -euo pipefail
BUNDLE_FILE=$(grep -v -E '^[[:space:]]*#|^[[:space:]]*$' .github/bundle-files.txt | head -n 1 | tr -d '\r' | sed -E 's/^[[:space:]]+//; s/[[:space:]]+$//')
if [ -z "${BUNDLE_FILE}" ]; then
echo "bundle-files.txt 为空, 请写入一行整包文件名"
exit 1
fi
case "${BUNDLE_FILE}" in
*.tar.gz) ;;
*)
echo "整包文件名必须以 .tar.gz 结尾: ${BUNDLE_FILE}"
exit 1
;;
esac
VERSION="${BUNDLE_FILE%.tar.gz}"
VERSION="${VERSION#${PACKAGE_NAME}-}"
mkdir -p dist
{
echo "BUNDLE_FILE=${BUNDLE_FILE}"
echo "VERSION=${VERSION}"
} > dist/build.env
echo "整包: ${BUNDLE_FILE}"
echo "版本: ${VERSION}"
- name: 3.下载并校验安装包
env:
FORCE_DOWNLOAD: ${{ inputs.force_download }}
run: |
set -euo pipefail
if [ "${FORCE_DOWNLOAD:-false}" = "true" ]; then
bash scripts/download-containerd.sh --all --force
else
bash scripts/download-containerd.sh --all
fi
- name: 4.生成校验文件并打出离线整包
run: |
set -euo pipefail
source dist/build.env
rm -f packages/SHA256SUMS
( cd packages && sha256sum * ) > dist/SHA256SUMS
cp dist/SHA256SUMS packages/SHA256SUMS
STAGE="dist/Ansible-Containerd"
rm -rf "${STAGE}"
mkdir -p "${STAGE}"
tar -cf - --exclude=./.git --exclude=./.github --exclude=./dist --exclude=./packages . | tar -xf - -C "${STAGE}"
cp -a packages "${STAGE}/packages"
tar -czf "dist/${BUNDLE_FILE}" -C dist Ansible-Containerd
rm -rf "${STAGE}"
ls -lh "dist/${BUNDLE_FILE}"
echo "包内条目数: $(tar -tzf "dist/${BUNDLE_FILE}" | wc -l)"
- name: 5.上传整包到仓库 Release
if: ${{ !contains(github.server_url, 'github.com') }}
env:
RELEASE_TOKEN: ${{ secrets.RELEASE_TOKEN }}
REGISTRY_USER: ${{ secrets.REGISTRY_USER }}
run: |
set -euo pipefail
source dist/build.env
API="${GITHUB_SERVER_URL}/api/v1/repos/${GITHUB_REPOSITORY}"
USER_NAME="${REGISTRY_USER:-${GITHUB_ACTOR}}"
TOKEN_VALUE="${RELEASE_TOKEN}"
if [ -z "${TOKEN_VALUE}" ]; then
echo "缺少令牌: 请配置 secrets.RELEASE_TOKEN"
exit 1
fi
AUTH="${USER_NAME}:${TOKEN_VALUE}"
REL_JSON="dist/release.json"
CODE=$(curl -s -o "${REL_JSON}" -w '%{http_code}' -u "${AUTH}" "${API}/releases/tags/${VERSION}")
if [ "${CODE}" = "200" ]; then
echo "Release 已存在: ${VERSION}"
else
echo "创建 Release: ${VERSION}"
CODE=$(curl -s -o "${REL_JSON}" -w '%{http_code}' -u "${AUTH}" \
-H 'Content-Type: application/json' \
-d "{\"tag_name\":\"${VERSION}\",\"name\":\"Containerd 离线安装包 ${VERSION}\",\"draft\":false,\"prerelease\":false}" \
"${API}/releases")
if [ "${CODE}" != "201" ] && [ "${CODE}" != "200" ]; then
echo "创建 Release 失败, HTTP ${CODE}"
cat "${REL_JSON}"
exit 1
fi
fi
REL_ID=$(grep -o '"id":[0-9]*' "${REL_JSON}" | head -n 1 | cut -d: -f2)
if [ -z "${REL_ID}" ]; then
echo "未能解析 Release id"
cat "${REL_JSON}"
exit 1
fi
echo "Release id: ${REL_ID}"
ASSETS=$(curl -s -u "${AUTH}" "${API}/releases/${REL_ID}/assets")
if printf '%s' "${ASSETS}" | grep -q "\"name\":\"${BUNDLE_FILE}\""; then
echo "附件已存在, 跳过: ${BUNDLE_FILE}"
exit 0
fi
CODE=$(curl -s -o dist/upload.json -w '%{http_code}' -X POST -u "${AUTH}" \
-F "attachment=@dist/${BUNDLE_FILE}" \
"${API}/releases/${REL_ID}/assets?name=${BUNDLE_FILE}")
if [ "${CODE}" != "201" ]; then
echo "上传附件失败, HTTP ${CODE}"
cat dist/upload.json
exit 1
fi
echo "已上传附件: ${BUNDLE_FILE}"
- name: 6.发布到 GitHub Release
if: ${{ contains(github.server_url, 'github.com') }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
source dist/build.env
if gh release view "${VERSION}" >/dev/null 2>&1; then
echo "Release 已存在: ${VERSION}"
else
gh release create "${VERSION}" --title "Containerd 离线安装包 ${VERSION}" --notes "包含项目本体与全部二进制安装包, 解压即可离线使用"
fi
if gh release view "${VERSION}" --json assets --jq '.assets[].name' | grep -qx "${BUNDLE_FILE}"; then
echo "附件已存在, 跳过: ${BUNDLE_FILE}"
exit 0
fi
gh release upload "${VERSION}" "dist/${BUNDLE_FILE}"
echo "已上传附件: ${BUNDLE_FILE}"