Merge branch 'codex/backend-rewrite-spacetimedb' of http://82.157.175.59:3000/GenarrativeAI/Genarrative into codex/backend-rewrite-spacetimedb
This commit is contained in:
@@ -21,6 +21,10 @@ usage() {
|
||||
--api-port <port> api-server 端口,默认 8082
|
||||
--web-port <port> 静态网站端口,默认 3000
|
||||
--spacetime-port <port> SpacetimeDB 端口,默认 3101
|
||||
--ssh-key <path> 上传使用的 SSH 私钥,默认 ~\.ssh\dsk.pem
|
||||
--remote <user@host> 上传目标 SSH 主机,默认 ubuntu@82.157.175.59
|
||||
--remote-dir <path> 上传目标目录,默认 /home/ubuntu/genarrative
|
||||
--skip-upload 只生成本地发布包,不上传服务器
|
||||
--skip-web-build 跳过 Vite 构建,仅用于调试
|
||||
--skip-api-build 跳过 api-server 构建,仅用于调试
|
||||
--skip-spacetime-build 跳过 wasm 构建,仅用于调试
|
||||
@@ -53,6 +57,34 @@ copy_required_file() {
|
||||
cp "${source_path}" "${target_path}"
|
||||
}
|
||||
|
||||
normalize_local_path_for_bash() {
|
||||
local value="$1"
|
||||
|
||||
if [[ "${value}" == "~"* ]]; then
|
||||
local rest="${value:1}"
|
||||
rest="${rest#\\}"
|
||||
rest="${rest#/}"
|
||||
rest="${rest//\\//}"
|
||||
printf "%s/%s" "${HOME}" "${rest}"
|
||||
return
|
||||
fi
|
||||
|
||||
if [[ "${value}" =~ ^([A-Za-z]):\\(.*)$ ]]; then
|
||||
local drive
|
||||
drive="$(printf "%s" "${BASH_REMATCH[1]}" | tr '[:upper:]' '[:lower:]')"
|
||||
local rest="${BASH_REMATCH[2]//\\//}"
|
||||
printf "/%s/%s" "${drive}" "${rest}"
|
||||
return
|
||||
fi
|
||||
|
||||
printf "%s" "${value}"
|
||||
}
|
||||
|
||||
remote_shell_quote() {
|
||||
local value="$1"
|
||||
printf "'%s'" "$(printf "%s" "${value}" | sed "s/'/'\\\\''/g")"
|
||||
}
|
||||
|
||||
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
|
||||
REPO_ROOT="$(cd -- "${SCRIPT_DIR}/.." && pwd)"
|
||||
SERVER_RS_DIR="${REPO_ROOT}/server-rs"
|
||||
@@ -65,6 +97,10 @@ WEB_HOST="0.0.0.0"
|
||||
WEB_PORT="3000"
|
||||
SPACETIME_HOST="127.0.0.1"
|
||||
SPACETIME_PORT="3101"
|
||||
SSH_KEY='~\.ssh\dsk.pem'
|
||||
REMOTE_TARGET="ubuntu@82.157.175.59"
|
||||
REMOTE_DIR="/home/ubuntu/genarrative"
|
||||
UPLOAD_ENABLED=1
|
||||
SKIP_WEB_BUILD=0
|
||||
SKIP_API_BUILD=0
|
||||
SKIP_SPACETIME_BUILD=0
|
||||
@@ -108,6 +144,22 @@ while [[ $# -gt 0 ]]; do
|
||||
SPACETIME_PORT="${2:?缺少 --spacetime-port 的值}"
|
||||
shift 2
|
||||
;;
|
||||
--ssh-key)
|
||||
SSH_KEY="${2:?缺少 --ssh-key 的值}"
|
||||
shift 2
|
||||
;;
|
||||
--remote)
|
||||
REMOTE_TARGET="${2:?缺少 --remote 的值}"
|
||||
shift 2
|
||||
;;
|
||||
--remote-dir)
|
||||
REMOTE_DIR="${2:?缺少 --remote-dir 的值}"
|
||||
shift 2
|
||||
;;
|
||||
--skip-upload)
|
||||
UPLOAD_ENABLED=0
|
||||
shift
|
||||
;;
|
||||
--skip-web-build)
|
||||
SKIP_WEB_BUILD=1
|
||||
shift
|
||||
@@ -159,6 +211,19 @@ if [[ "${SKIP_WEB_BUILD}" -ne 1 ]]; then
|
||||
require_command npm
|
||||
fi
|
||||
|
||||
NORMALIZED_SSH_KEY="$(normalize_local_path_for_bash "${SSH_KEY}")"
|
||||
|
||||
if [[ "${UPLOAD_ENABLED}" -eq 1 ]]; then
|
||||
require_command ssh
|
||||
require_command scp
|
||||
|
||||
if [[ ! -f "${NORMALIZED_SSH_KEY}" ]]; then
|
||||
echo "[deploy:rust] SSH 私钥不存在: ${SSH_KEY}" >&2
|
||||
echo "[deploy:rust] Git Bash 解析路径: ${NORMALIZED_SSH_KEY}" >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
mkdir -p "${WEB_DIR}"
|
||||
|
||||
echo "[deploy:rust] 发布包目录: ${TARGET_DIR}"
|
||||
@@ -535,4 +600,13 @@ cat >"${TARGET_DIR}/README.md" <<EOF
|
||||
EOF
|
||||
|
||||
BUILD_COMPLETED=1
|
||||
|
||||
if [[ "${UPLOAD_ENABLED}" -eq 1 ]]; then
|
||||
echo "[deploy:rust] 创建远端目录: ${REMOTE_TARGET}:${REMOTE_DIR}"
|
||||
ssh -i "${NORMALIZED_SSH_KEY}" "${REMOTE_TARGET}" "mkdir -p $(remote_shell_quote "${REMOTE_DIR}")"
|
||||
|
||||
echo "[deploy:rust] 上传发布包: ${TARGET_DIR} -> ${REMOTE_TARGET}:${REMOTE_DIR}/"
|
||||
scp -r -i "${NORMALIZED_SSH_KEY}" "${TARGET_DIR}" "${REMOTE_TARGET}:${REMOTE_DIR}/"
|
||||
fi
|
||||
|
||||
echo "[deploy:rust] 完成: ${TARGET_DIR}"
|
||||
|
||||
Reference in New Issue
Block a user