Fix server deploy: rsync submodules, local chatbotApp build, deploy flow.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Macbook
2026-07-23 13:46:25 +09:00
parent b23e96c412
commit 48a2e5815f
5 changed files with 150 additions and 38 deletions
+47 -30
View File
@@ -12,9 +12,6 @@ BRANCH="${BRANCH:-main}"
DEPLOY_LOG="${DEPLOY_LOG:-/Volumes/ADATA/logs/deploy/exAichatbot_agent.log}"
LOG_TAG="[exAichatbot_agent-deploy]"
# 레거시 bare repo (Gitea 미사용 시)
# GIT_DIR=/Volumes/ADATA/git/exAichatbot_agent.git
export PATH="/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/Applications/Docker.app/Contents/Resources/bin:${PATH:-/usr/bin:/bin}"
mkdir -p "$(dirname "$DEPLOY_LOG")"
@@ -34,47 +31,63 @@ fi
echo $$ > "$LOCK_FILE"
trap 'rm -f "$LOCK_FILE"; log "락 해제"' EXIT
for arg in "$@"; do
case "$arg" in
--start-only) START_ONLY=true ;;
esac
done
START_ONLY="${START_ONLY:-false}"
log "======================================================"
log " exAichatbot Agent 2.0 배포 시작"
log " GIT_DIR : $GIT_DIR"
log " WORK_TREE : $WORK_TREE"
log " BRANCH : $BRANCH"
log " START_ONLY: $START_ONLY"
log "======================================================"
[[ -d "$GIT_DIR" ]] || fail "GIT_DIR 없음: $GIT_DIR"
mkdir -p "$WORK_TREE"
chmod +x "$WORK_TREE/server-dev/"*.sh 2>/dev/null || true
chmod +x "$WORK_TREE/git_fetch_all.sh" 2>/dev/null || true
chmod +x "$WORK_TREE/chatbotApp-chatbot2.0-agent/build.sh" 2>/dev/null || true
sync_worktree_submodules() {
local tree="$1"
local path ready=0
for path in chatbotApp-chatbot2.0-agent chatbotApi-chatbot2.0-agent \
exAiChatBot-chatbot2.0-agent kakaoChatbotSkill-chatbot2.0-agent; do
if [[ -f "${tree}/${path}/build.gradle" ]] || [[ -f "${tree}/${path}/build.sh" ]] \
|| [[ -f "${tree}/${path}/docker/service-slim.Dockerfile" ]]; then
ready=$((ready + 1))
fi
done
if [[ ${ready} -ge 4 ]]; then
log "submodule 소스 이미 존재 (rsync 또는 clone 완료) — GitHub fetch 생략"
if [[ -f "${tree}/server-dev/docker-compose.rag.server.yml" ]]; then
cp "${tree}/server-dev/docker-compose.rag.server.yml" \
"${tree}/exAiChatBot-chatbot2.0-agent/docker-compose.server.yml" 2>/dev/null || true
fi
return 0
fi
if [[ -x "${tree}/git_fetch_all.sh" ]]; then
log "GitHub submodule 동기화 (git_fetch_all.sh --init)..."
MONOREPO_GIT_DIR="${GIT_DIR}" "${tree}/git_fetch_all.sh" --init || log "[WARN] git_fetch_all 실패 — 로컬 rsync 필요"
else
log "[WARN] git_fetch_all.sh 없음 — 로컬 rsync 필요"
fi
}
log "[Phase 1] stop-all-server.sh"
"$WORK_TREE/server-dev/stop-all-server.sh" --keep-caddy || true
ensure_worktree_git() {
local tree="$1"
local git_dir="$2"
if [[ ! -e "${tree}/.git" ]]; then
echo "gitdir: ${git_dir}" > "${tree}/.git"
log "work tree .git 연결: ${tree}"
fi
}
sync_worktree_submodules() {
local tree="$1"
ensure_worktree_git "${tree}" "${GIT_DIR}"
if [[ -x "${tree}/git_fetch_all.sh" ]]; then
log "GitHub submodule 동기화 (git_fetch_all.sh --init)..."
"${tree}/git_fetch_all.sh" --init || log "[WARN] git_fetch_all 실패"
else
log "git submodule update --init --recursive"
git -C "${tree}" submodule sync --recursive 2>/dev/null || true
git -C "${tree}" submodule update --init --recursive || log "[WARN] submodule update 실패"
fi
}
log "[Phase 2] checkout + GitHub submodule"
git --work-tree="$WORK_TREE" --git-dir="$GIT_DIR" checkout -f "$BRANCH"
sync_worktree_submodules "$WORK_TREE"
if ! $START_ONLY; then
log "[Phase 2] checkout + GitHub submodule"
git --work-tree="$WORK_TREE" --git-dir="$GIT_DIR" checkout -f "$BRANCH"
rm -f "$WORK_TREE/.git"
sync_worktree_submodules "$WORK_TREE"
fi
log "[Phase 3] .env 준비"
ENV_FILE="$WORK_TREE/exAiChatBot-chatbot2.0-agent/.env"
@@ -83,8 +96,12 @@ if [[ ! -f "$ENV_FILE" ]]; then
log ".env 생성 (env.exdev-server.template)"
fi
log "[Phase 4] start-all-server.sh (빌드 + 기동, push 생략)"
"$WORK_TREE/server-dev/start-all-server.sh" --skip-legacy-stop --no-pull --no-push
log "[Phase 4] start-all-server.sh (기동)"
START_ARGS=(--skip-legacy-stop --no-pull --no-push)
if $START_ONLY || [[ -f "$WORK_TREE/chatbotApp-chatbot2.0-agent/public/index.html" ]]; then
START_ARGS+=(--no-build)
fi
"$WORK_TREE/server-dev/start-all-server.sh" "${START_ARGS[@]}"
COMMIT="$(git --git-dir="$GIT_DIR" rev-parse --short HEAD 2>/dev/null || echo unknown)"
log "======================================================"