ci: Gitea Actions deploy via self-hosted runner
Deploy dev / deploy (push) Failing after 0s

This commit is contained in:
Azmat@qq.com
2026-09-23 15:41:46 +08:00
parent 806d6bf62a
commit a477177bab
3 changed files with 85 additions and 2 deletions
+20
View File
@@ -0,0 +1,20 @@
# push → Gitea Actions(本机 Act Runner)→ docker compose 部署
name: Deploy dev
on:
push:
branches:
- dev
jobs:
deploy:
# 与服务器 act_runner 注册的 label 一致(host = 直接在宿主机跑,能用本机 docker)
runs-on: yingqing
steps:
- name: Deploy on server
run: |
set -euo pipefail
test -x /opt/AirShelf/scripts/deploy-dev.sh
/opt/AirShelf/scripts/deploy-dev.sh
echo "deploy finished"
cd /opt/AirShelf && git log -1 --oneline && docker compose ps
+2 -2
View File
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
# push → Gitea Webhook → 本脚本:仅部署 dev 到本机 Docker Compose
# 部署 dev 到本机 Docker Compose(可由 Gitea Actions 或 Webhook 调用)
set -euo pipefail
APP_DIR="${APP_DIR:-/opt/AirShelf}"
@@ -27,7 +27,7 @@ fi
exit 1
fi
# .env 在仓库里被跟踪,pull 会覆盖服务器上的生产配置;先备份再还原
# .env 在仓库里被跟踪,pull 会覆盖服务器生产配置;先备份再还原
ENV_BACKUP=""
if [[ -f "$ENV_FILE" ]]; then
ENV_BACKUP="$(mktemp)"
+63
View File
@@ -0,0 +1,63 @@
#!/usr/bin/env bash
# 在部署机上一键安装 Gitea Act Runner(仅需执行一次)
# 用法:
# export GITEA_URL=https://gitea.yueqing.online
# export RUNNER_TOKEN=从Gitea复制的注册Token
# bash scripts/install-act-runner.sh
set -euo pipefail
GITEA_URL="${GITEA_URL:?请设置 GITEA_URL,例如 https://gitea.yueqing.online}"
RUNNER_TOKEN="${RUNNER_TOKEN:?请设置 RUNNER_TOKENGitea → 仓库/站点 Actions → Runners → 创建)}"
RUNNER_NAME="${RUNNER_NAME:-yingqing-ecs}"
LABELS="${LABELS:-yingqing:host}"
INSTALL_DIR="${INSTALL_DIR:-/opt/act_runner}"
mkdir -p "$INSTALL_DIR"
cd "$INSTALL_DIR"
ARCH="$(uname -m)"
case "$ARCH" in
x86_64|amd64) ARCH=amd64 ;;
aarch64|arm64) ARCH=arm64 ;;
*) echo "不支持的架构: $ARCH"; exit 1 ;;
esac
VER="${ACT_RUNNER_VERSION:-0.2.11}"
BIN_URL="https://gitea.com/gitea/act_runner/releases/download/v${VER}/act_runner-${VER}-linux-${ARCH}"
echo "下载 act_runner v${VER} ..."
curl -fL "$BIN_URL" -o act_runner
chmod +x act_runner
if [[ ! -f .runner ]]; then
echo "注册 Runner ..."
./act_runner register --no-interactive \
--instance "$GITEA_URL" \
--token "$RUNNER_TOKEN" \
--name "$RUNNER_NAME" \
--labels "$LABELS"
fi
cat >/etc/systemd/system/act_runner.service <<UNIT
[Unit]
Description=Gitea Act Runner
After=network.target docker.service
Wants=docker.service
[Service]
Type=simple
WorkingDirectory=${INSTALL_DIR}
ExecStart=${INSTALL_DIR}/act_runner daemon
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
UNIT
systemctl daemon-reload
systemctl enable --now act_runner
systemctl --no-pager --full status act_runner || true
echo
echo "完成。在 Gitea → Actions → Runners 应看到「${RUNNER_NAME}」在线,label: ${LABELS}"
echo "可停掉旧的 webhook(避免重复部署):systemctl disable --now airshelf-webhook"