Add deploy pipeline SpacetimeDB auto migration
Some checks failed
CI / verify (pull_request) Has been cancelled
Some checks failed
CI / verify (pull_request) Has been cancelled
This commit is contained in:
@@ -5,20 +5,24 @@ set -euo pipefail
|
||||
usage() {
|
||||
cat <<'EOF'
|
||||
用法:
|
||||
./scripts/jenkins-deploy-release.sh --source-dir /path/to/build/123 --deploy-dir /var/lib/jenkins/deploy/Genarrative --web-port 25001 [--clear-database] [--hook-with-sudo]
|
||||
./scripts/jenkins-deploy-release.sh --source-dir /path/to/build/123 --deploy-dir /var/lib/jenkins/deploy/Genarrative --web-port 25001 [--clear-database] [--no-migrate-on-conflict] [--migration-dir /path/to/migrations] [--hook-with-sudo]
|
||||
|
||||
说明:
|
||||
1. 如果部署目录已有旧版本且存在 stop.sh,则先执行旧版本 stop.sh。
|
||||
2. 仅删除并替换发布产物文件或目录,保留部署目录中的运行数据目录。
|
||||
3. 把指定发布目录中的白名单产物复制覆盖到部署目录。
|
||||
4. 如指定 --clear-database,则以清库模式执行新版本 start.sh。
|
||||
5. 最后执行新版本 start.sh。
|
||||
5. 默认允许新版本 start.sh 在 schema 冲突时自动导出、清库发布、导入回灌。
|
||||
6. 最后执行新版本 start.sh。
|
||||
|
||||
参数:
|
||||
--source-dir <path> 必填,待部署的发布目录,例如 build/123
|
||||
--deploy-dir <path> 必填,固定部署目录,例如 /var/lib/jenkins/deploy/Genarrative
|
||||
--web-port <port> 必填,本次部署后静态网站监听端口
|
||||
--clear-database 可选,启动新版本时追加 --clear-database
|
||||
--migrate-on-conflict 可选,普通发布遇到 schema 冲突时自动迁移,默认启用
|
||||
--no-migrate-on-conflict 可选,禁用 schema 冲突自动迁移
|
||||
--migration-dir <path> 可选,自动迁移 JSON 输出目录,默认部署目录内 database-migrations/<database>
|
||||
--hook-with-sudo 可选,仅对 start.sh/stop.sh 使用 sudo -n 执行
|
||||
EOF
|
||||
}
|
||||
@@ -106,13 +110,17 @@ SOURCE_DIR=""
|
||||
DEPLOY_DIR=""
|
||||
WEB_PORT=""
|
||||
CLEAR_DATABASE="0"
|
||||
MIGRATE_ON_CONFLICT="true"
|
||||
MIGRATION_DIR=""
|
||||
HOOK_WITH_SUDO="0"
|
||||
DEPLOY_ITEMS=(
|
||||
".env"
|
||||
".env.local"
|
||||
"README.md"
|
||||
"api-server"
|
||||
"migration-bootstrap-secret.txt"
|
||||
"spacetime_module.wasm"
|
||||
"scripts"
|
||||
"start.sh"
|
||||
"stop.sh"
|
||||
"web"
|
||||
@@ -141,6 +149,18 @@ while [[ $# -gt 0 ]]; do
|
||||
CLEAR_DATABASE="1"
|
||||
shift
|
||||
;;
|
||||
--migrate-on-conflict)
|
||||
MIGRATE_ON_CONFLICT="true"
|
||||
shift
|
||||
;;
|
||||
--no-migrate-on-conflict)
|
||||
MIGRATE_ON_CONFLICT="false"
|
||||
shift
|
||||
;;
|
||||
--migration-dir)
|
||||
MIGRATION_DIR="${2:?缺少 --migration-dir 的值}"
|
||||
shift 2
|
||||
;;
|
||||
--hook-with-sudo)
|
||||
HOOK_WITH_SUDO="1"
|
||||
shift
|
||||
@@ -211,6 +231,15 @@ else
|
||||
echo "[jenkins-deploy] 部署目录无可执行 stop.sh,跳过停服"
|
||||
fi
|
||||
|
||||
if [[ -f "${DEPLOY_DIR}/migration-bootstrap-secret.txt" ]]; then
|
||||
mkdir -p "${DEPLOY_DIR}/run"
|
||||
cp "${DEPLOY_DIR}/migration-bootstrap-secret.txt" "${DEPLOY_DIR}/run/migration-bootstrap-secret.previous.txt"
|
||||
chmod 600 "${DEPLOY_DIR}/run/migration-bootstrap-secret.previous.txt" 2>/dev/null || true
|
||||
echo "[jenkins-deploy] 已保存旧模块迁移引导密钥,用于 schema 冲突时导出旧库。"
|
||||
else
|
||||
rm -f "${DEPLOY_DIR}/run/migration-bootstrap-secret.previous.txt" 2>/dev/null || true
|
||||
fi
|
||||
|
||||
echo "[jenkins-deploy] 清空部署目录: ${DEPLOY_DIR}"
|
||||
for item in "${DEPLOY_ITEMS[@]}"; do
|
||||
if [[ -e "${DEPLOY_DIR}/${item}" ]]; then
|
||||
@@ -241,6 +270,8 @@ fi
|
||||
|
||||
normalize_release_env_files "${DEPLOY_DIR}"
|
||||
write_env_override "${DEPLOY_DIR}/.env.local" "GENARRATIVE_WEB_PORT" "${WEB_PORT}"
|
||||
write_env_override "${DEPLOY_DIR}/.env.local" "GENARRATIVE_SPACETIME_MIGRATE_ON_CONFLICT" "${MIGRATE_ON_CONFLICT}"
|
||||
write_env_override "${DEPLOY_DIR}/.env.local" "GENARRATIVE_SPACETIME_MIGRATION_DIR" "${MIGRATION_DIR}"
|
||||
|
||||
echo "[jenkins-deploy] 启动新版本: ${DEPLOY_DIR}"
|
||||
if [[ "${CLEAR_DATABASE}" == "1" ]]; then
|
||||
|
||||
Reference in New Issue
Block a user