Files
jkooe 665baa0831 docs: 补充「发布与更新」章节,归档 act_runner 安装脚本
- README 新增第 12 节:发版流程(打 tag)、必需 secrets、签名硬约束、
  应用内更新原理、runner 要求(host 模式复用现成 JDK/SDK)
- scripts/install-runner.sh:act_runner 安装与注册(host 模式),
  参数化 GITEA_URL / REG_TOKEN / LABELS,装成 systemd 服务
2026-11-09 17:32:01 +08:00

105 lines
3.7 KiB
Bash
Executable File
Raw Permalink 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.
#!/bin/bash
# =============================================================================
# 在 Gitea 服务器(123.206.124.151)上安装 act_runner
#
# 为什么用 host 模式(label = self-hosted:host)而不是 Docker 容器模式:
# 这台机器本来就是这个项目的构建机(build.sh 里写死了 /opt/jdk17、
# /opt/android-sdk、/opt/gradle/gradle-8.5),Android SDK 已经装好了。
# 容器模式下 job 跑在 node:16 镜像里,没有 JDK/Android SDK,还得自己
# 构建一个 2GB+ 的 Android 镜像;host 模式直接复用现成环境,零额外体积。
#
# 用法:
# 1) 先拿到 registration token(见文件末尾说明)
# 2) REG_TOKEN=xxxx bash install-runner.sh
# =============================================================================
set -euo pipefail
GITEA_URL="${GITEA_URL:-http://123.206.124.151:3000}"
REG_TOKEN="${REG_TOKEN:-}"
RUNNER_NAME="${RUNNER_NAME:-tencent2}"
LABELS="${LABELS:-self-hosted:host}"
WORK="${WORK:-/opt/act_runner}"
if [ -z "$REG_TOKEN" ]; then
echo "缺少 REG_TOKEN。获取方式:"
echo " Gitea → 站点管理 → Actions → Runners → 创建 Runner / 复制注册令牌"
echo " 或 API: curl -H 'Authorization: token <ADMIN_TOKEN>' \\"
echo " $GITEA_URL/api/v1/admin/actions/runners/registration-token -X POST"
echo
echo "然后:REG_TOKEN=<令牌> bash $0"
exit 1
fi
echo "=== 1/4 检查宿主机构建环境(host 模式要靠它)==="
missing=0
for p in /opt/jdk17 /opt/android-sdk /opt/gradle; do
if [ -d "$p" ]; then echo " ✓ $p"; else echo " ✗ $p 不存在"; missing=1; fi
done
if [ "$missing" = "1" ]; then
echo
echo "警告:上面缺失的路径会导致构建失败。若实际路径不同,"
echo " 请确认 workflow 里「准备构建环境」步骤的探测列表覆盖到了。"
fi
echo "=== 2/4 下载 act_runner ==="
mkdir -p "$WORK" && cd "$WORK"
ARCH=$(uname -m)
case "$ARCH" in
x86_64|amd64) RA_ARCH=amd64 ;;
aarch64|arm64) RA_ARCH=arm64 ;;
*) echo "不支持的架构:$ARCH"; exit 1 ;;
esac
if [ ! -x ./act_runner ]; then
# 优先 gitea.com(官方分发),失败回退 GitHub
curl -fL --retry 3 -o act_runner \
"https://gitea.com/gitea/act_runner/releases/latest/download/act_runner-linux-$RA_ARCH" \
|| curl -fL --retry 3 -o act_runner \
"https://github.com/gitea/act_runner/releases/latest/download/act_runner-linux-$RA_ARCH"
chmod +x act_runner
fi
./act_runner --version || true
echo "=== 3/4 注册到 $GITEA_URL ==="
# host 模式:job 直接在宿主机执行,标签形如 self-hosted:host
if [ -f .runner ]; then
echo " 已存在 .runner 配置,跳过注册(如需重新注册请先删除 $WORK/.runner)"
rm -f "$WORK/.runner"
echo " 已删除旧配置,重新注册…"
fi
./act_runner register --no-interactive \
--instance "$GITEA_URL" \
--token "$REG_TOKEN" \
--name "$RUNNER_NAME" \
--labels "$LABELS"
echo "=== 4/4 安装为 systemd 服务并启动 ==="
if command -v systemctl >/dev/null 2>&1; then
cat > /etc/systemd/system/gitea-act-runner.service <<EOF
[Unit]
Description=Gitea Actions Runner (host mode)
After=network.target
[Service]
Type=simple
WorkingDirectory=$WORK
ExecStart=$WORK/act_runner daemon
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable --now gitea-act-runner
sleep 2
systemctl --no-pager --lines=15 status gitea-act-runner || true
else
echo " 没有 systemd,前台启动以便观察(Ctrl+C 退出后需自行守护):"
exec ./act_runner daemon
fi
echo
echo "=== 完成 ==="
echo "回 Gitea 确认:$GITEA_URL/-/admin/actions/runners 应能看到 $RUNNER_NAME(idle)"
echo "然后重新跑构建:推送新 tag,或在仓库 Actions 页面点 Re-run。"