ci deploy (src a15d1aa)

This commit is contained in:
2026-06-11 17:23:33 +08:00
committed by gitea-actions
commit cfb4fb7e99
5 changed files with 147 additions and 0 deletions

1
.gitattributes vendored Normal file
View File

@ -0,0 +1 @@
* -text

45
app-entry.sh Normal file
View File

@ -0,0 +1,45 @@
#!/bin/sh
# sgame-admin-server 容器守护入口alpine 容器内由 busybox sh 执行)。
# /repo 是 gitsync 容器同步下来的部署仓(只读挂载),里面有:
# server — linux/amd64 静态二进制(前端已 embed时区已内嵌
# config.yaml — 基础配置(敏感项全部由环境变量覆盖)
# app-entry.sh — 本脚本
# 逻辑:启动 server → 每 10s 比对仓库里二进制的 md5 → 变了就杀进程重启。
# 进程崩溃同样会回到循环顶部自动拉起。
BIN=/repo/server
RUN=/tmp/server.run
echo "[entry] waiting for $BIN ..."
while [ ! -f "$BIN" ]; do sleep 2; done
while true; do
# 等 gitsync 的 checkout 落定:两次校验和一致才启动
SUM=$(md5sum "$BIN" | cut -d' ' -f1)
sleep 1
SUM2=$(md5sum "$BIN" | cut -d' ' -f1)
if [ "$SUM" != "$SUM2" ]; then
continue
fi
# 跑 /tmp 副本而不是 /repo 原件,避免 git reset 覆盖运行中的可执行文件
cp "$BIN" "$RUN"
chmod +x "$RUN"
echo "[entry] starting server (md5 $SUM)"
"$RUN" -config /repo/config.yaml &
PID=$!
while kill -0 "$PID" 2>/dev/null; do
sleep 10
NEW=$(md5sum "$BIN" 2>/dev/null | cut -d' ' -f1)
if [ -n "$NEW" ] && [ "$NEW" != "$SUM" ]; then
echo "[entry] new binary detected, restarting"
kill "$PID"
wait "$PID" 2>/dev/null
break
fi
done
echo "[entry] server exited, relaunching in 2s"
sleep 2
done

44
ci-runner-entry.sh Normal file
View File

@ -0,0 +1,44 @@
#!/bin/bash
# Gitea Actions runner 容器入口(在 node:20-bookworm 镜像内执行)。
# NAS compose 的 ci-runner 服务启动时从公开产物仓 curl 本脚本执行——
# 改本文件 + 发版 + 重启 ci-runner 容器即可更新 runner 逻辑。
# /data 是持久卷Go 工具链、模块/构建缓存、act_runner 注册状态都在里面,
# 容器重建不丢。需要环境变量 RUNNER_REG_TOKEN仅首次注册时使用
set -e
# runner v1.x 要求 go>=1.261.26 向下兼容编译 go.mod 1.25 的项目
GO_VERSION=1.26.4
# v1.x 起模块改名 gitea.com/gitea/runner旧名 act_runner 装不上),二进制名也是 runner
RUNNER_VERSION=v1.0.8
export GOPATH=/data/gopath
export GOMODCACHE=/data/gomod
export GOCACHE=/data/gocache
export GOPROXY=https://goproxy.cn,direct
export PATH=/data/go/bin:$GOPATH/bin:$PATH
if [ ! -x /data/go/bin/go ]; then
echo "[ci-runner] downloading go $GO_VERSION ..."
curl -fsSL -o /tmp/go.tgz "https://mirrors.aliyun.com/golang/go${GO_VERSION}.linux-amd64.tar.gz"
tar -C /data -xzf /tmp/go.tgz
rm /tmp/go.tgz
fi
if [ ! -x "$GOPATH/bin/runner" ]; then
echo "[ci-runner] installing gitea runner $RUNNER_VERSION ..."
go install "gitea.com/gitea/runner@${RUNNER_VERSION}"
fi
mkdir -p /data/runner
cd /data/runner
if [ ! -f .runner ]; then
echo "[ci-runner] registering ..."
runner register --no-interactive \
--instance https://git.xindiegaming.top \
--token "$RUNNER_REG_TOKEN" \
--name nas-runner \
--labels nas:host
fi
echo "[ci-runner] daemon up"
exec runner daemon

57
config.yaml Normal file
View File

@ -0,0 +1,57 @@
server:
port: 8090
log_level: info # debug, info, warn, error留空默认 info
tls_cert: "" # TLS 证书路径(留空则以 HTTP 启动;生产由 Caddy 终结 TLS
tls_key: ""
# timezone: "Asia/Shanghai" # 可选 IANA 时区,决定看板"按日"统计边界与前端时间显示;留空默认 Asia/Shanghai
# 后台自身库admins 表)。默认部署与 game_db 同一 MySQL 实例、不同 schema。
admin_db:
host: 127.0.0.1
port: 3306
database: sgame_admin
username: sgame
password: "change-me"
max_open_conns: 10
max_idle_conns: 5
# 游戏数据库feedbacks / events / devices / daily_active由玩家上报 API 写入)
game_db:
host: 127.0.0.1
port: 3306
database: sgame_game
username: sgame
password: "change-me"
max_open_conns: 10
max_idle_conns: 5
redis:
addr: 127.0.0.1:6379
password: ""
db: 0
pool_size: 10
jwt:
secret: "admin-secret-change-in-production"
expire_hours: 24
# 首次启动时若 admins 表为空,用以下信息创建超级管理员(纯密码登录,必须设置 password
init_admin:
name: "超级管理员"
phone: "13800000000"
password: ""
# 玩家侧公开上报 API/api/v1/events|heartbeat|feedback
ingest:
app_key: "" # 客户端内置的 X-App-Key留空 = 关闭上报路由503
upload_dir: "data/uploads" # 反馈截图落盘目录Docker 部署用 INGEST_UPLOAD_DIR=/data/uploads
max_screenshot_kb: 2048 # 单张截图上限
events_per_min: 10 # 按 IP 限流:事件批/分钟
feedback_per_10min: 5 # 按 IP 限流:反馈/10分钟
heartbeat_per_min: 2 # 按 IP 限流:心跳/分钟
events_retention_days: 90 # 原始事件保留天数(已汇总进 daily_stats 后批量清理0=永久保留)
# 所有字段均可被环境变量覆盖Docker 部署用),见 internal/config/config.go envBindings
# SERVER_PORT TZ ADMIN_DB_HOST/PORT/DATABASE/USERNAME/PASSWORD
# GAME_DB_HOST/PORT/DATABASE/USERNAME/PASSWORD REDIS_ADDR/PASSWORD/DB
# JWT_SECRET INIT_ADMIN_NAME/PHONE/PASSWORD INGEST_APP_KEY INGEST_UPLOAD_DIR

BIN
server Normal file

Binary file not shown.