Files
IOT_SIM/deploy/update.sh
T
xuyueandClaude Opus 5.5 7cec273d58 第 2 阶段:账号与班级,作品保存在服务器
- SQLite(bun:sqlite,编号迁移):班级、用户、会话(只存令牌哈希)、作品
- 登录取代统一访问口令:老师账号由配置设定;接口和 WebSocket 都要登录;按 IP 限制输错次数
- 班级管理页:建班、改名、删除(有学生时不能删);上传 CSV 名单导入(兼容 GBK / UTF-8,
  识别表头,标出被 Excel 变成科学计数法的学号),密码留空生成 6 位数字;查看、重置密码,
  导出带密码的名单
- 学生作品自动保存到服务器(按账号和实验),显示保存状态;离开页面前立即保存
- 前端加路由:登录页、实验页、班级管理页
- 部署:TEACHER_PASSWORD 必填,数据库放在数据卷

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 17:36:11 +08:00

59 lines
2.0 KiB
Bash
Executable File
Raw 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.
#!/usr/bin/env bash
# 在服务器上执行:拉取代码、构建镜像、重启,等到编译服务就绪才算成功。
# GitHub Actions 测试通过后通过 SSH 调用它,也可以登录服务器手动执行。
# 用法:deploy/update.sh [提交号,默认 origin/main]
# 第一次部署前,按 deploy/README.md 在服务器上克隆仓库、准备好 .env
set -euo pipefail
# 整个脚本包在函数里:git reset 会在运行中替换本文件,bash 先读完函数再执行,不受影响
main() {
cd "$(dirname "$0")/.."
local ref=${1:-origin/main}
if [[ ! -f .env ]]; then
echo '还没有 .env:cp .env.example .env 后设置 TEACHER_PASSWORD'
exit 1
fi
echo "== 拉取代码"
# 代码从 origin(git.xuyue.cc)拉取。Actions 由推送到 GitHub 触发,
# 两个仓库推送有先后,这个提交可能还没到 origin,多等一会儿
for attempt in $(seq 10); do
git fetch --quiet origin
if git rev-parse --quiet --verify "$ref^{commit}" >/dev/null; then break; fi
if [[ $attempt == 10 ]]; then
echo "origin 上没有 $ref:先 git push origin main,再重新运行部署"
exit 1
fi
echo "origin 上还没有 $ref,10 秒后重试"
sleep 10
done
# 服务器上不改代码,配置都在 .env(不进 git,不受影响)
git checkout --quiet -B main
git reset --quiet --hard "$ref"
git log --oneline -1
echo "== 构建镜像并重启"
docker compose up -d --build --remove-orphans
docker image prune -f >/dev/null
# 等编译服务就绪;沙箱自检失败时部署失败
for _ in $(seq 60); do
logs=$(docker compose logs app 2>&1)
if grep -q '沙箱(bubblewrap)无法启动' <<<"$logs"; then
echo "$logs" | tail -5
exit 1
fi
if grep -q 'C# 编译服务已就绪' <<<"$logs"; then
echo '== 部署成功'
exit 0
fi
sleep 2
done
echo '== 120 秒内没有启动完成'
docker compose logs --tail 20 app
exit 1
}
main "$@"