diff --git a/.gitea/workflows/deploy.yaml b/.gitea/workflows/deploy.yaml new file mode 100644 index 0000000..7d049ce --- /dev/null +++ b/.gitea/workflows/deploy.yaml @@ -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 diff --git a/scripts/deploy-dev.sh b/scripts/deploy-dev.sh index a18af00..6821965 100755 --- a/scripts/deploy-dev.sh +++ b/scripts/deploy-dev.sh @@ -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)" diff --git a/scripts/install-act-runner.sh b/scripts/install-act-runner.sh new file mode 100755 index 0000000..98278d4 --- /dev/null +++ b/scripts/install-act-runner.sh @@ -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_TOKEN(Gitea → 仓库/站点 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 <