diff --git a/scripts/build-mobile-apk.sh b/scripts/build-mobile-apk.sh index 708fcad..c1c0459 100755 --- a/scripts/build-mobile-apk.sh +++ b/scripts/build-mobile-apk.sh @@ -57,8 +57,13 @@ fi log "google-services.json 확인" "$ROOT/scripts/ensure-android-google-services.sh" +if [[ ! -d "$ROOT/node_modules/vite" ]]; then + log "npm ci (root dependencies)" + (cd "$ROOT" && npm ci --ignore-scripts 2>/dev/null || npm install) +fi + log "cap:sync" -npm run cap:sync +(cd "$ROOT/app" && npm run build && bash ../scripts/ensure-android-google-services.sh && npx cap sync) log "assembleRelease" (cd "$ROOT/app/android" && ./gradlew assembleRelease --no-daemon) diff --git a/scripts/server-install-mobile-jenkins.sh b/scripts/server-install-mobile-jenkins.sh index 280e46c..6144676 100755 --- a/scripts/server-install-mobile-jenkins.sh +++ b/scripts/server-install-mobile-jenkins.sh @@ -19,7 +19,7 @@ mkdir -p "${JENKINS_HOME}/jobs/${JENKINS_JOB}" cat > "${JENKINS_HOME}/jobs/${JENKINS_JOB}/config.xml" << JENKINS_XML - GoldenChart Mobile — Capacitor Android APK + GoldenChart Mobile - Capacitor Android APK false diff --git a/scripts/server-setup-mobile-phase1.sh b/scripts/server-setup-mobile-phase1.sh new file mode 100755 index 0000000..6286bfe --- /dev/null +++ b/scripts/server-setup-mobile-phase1.sh @@ -0,0 +1,74 @@ +#!/usr/bin/env bash +# exdev 서버 — Phase 1 Mobile 배포 후 1회 설정 (hook·Jenkins·env·재시작) +set -euo pipefail + +export PATH="/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:${PATH:-/usr/bin:/bin}" +for prefix in "$HOME/homebrew" /opt/homebrew; do + [[ -x "$prefix/bin/brew" ]] && eval "$("$prefix/bin/brew" shellenv)" +done + +WORK_TREE="${WORK_TREE:-/Users/aidev/apps/goldenChart}" +GIT_HOOK="${GIT_HOOK:-/Volumes/ADATA/git/goldenChart.git/hooks/post-receive}" +ENV_FILE="${ENV_FILE:-$WORK_TREE/.env}" + +log() { echo "[server-setup-mobile] $*"; } + +upsert_env() { + local key="$1" val="$2" + if [[ -f "$ENV_FILE" ]] && grep -q "^${key}=" "$ENV_FILE" 2>/dev/null; then + sed -i '' "s|^${key}=.*|${key}=${val}|" "$ENV_FILE" + else + echo "${key}=${val}" >> "$ENV_FILE" + fi +} + +log "post-receive hook 업데이트" +cp "$WORK_TREE/scripts/post-receive" "$GIT_HOOK" +chmod +x "$GIT_HOOK" + +log "Mobile Jenkins job 설치" +chmod +x "$WORK_TREE/scripts/"*.sh +"$WORK_TREE/scripts/server-install-mobile-jenkins.sh" +MOBILE_JOB="${JENKINS_HOME:-$HOME/.jenkins}/jobs/goldenChart-Mobile-Pipeline" +mkdir -p "$MOBILE_JOB/builds" +echo 1 > "$MOBILE_JOB/nextBuildNumber" + +log ".env Mobile Jenkins 설정" +DESKTOP_USER="$(grep '^GC_DESKTOP_JENKINS_USER=' "$ENV_FILE" | cut -d= -f2- || true)" +DESKTOP_TOKEN="$(grep '^GC_DESKTOP_JENKINS_TOKEN=' "$ENV_FILE" | cut -d= -f2- || true)" + +upsert_env GC_MOBILE_JENKINS_ENABLED true +upsert_env GC_MOBILE_JENKINS_URL http://host.docker.internal:8090 +upsert_env GC_MOBILE_JENKINS_JOB goldenChart-Mobile-Pipeline +upsert_env GC_MOBILE_JENKINS_TRIGGER_TOKEN goldenchart-mobile-build +[[ -n "$DESKTOP_USER" ]] && upsert_env GC_MOBILE_JENKINS_USER "$DESKTOP_USER" +[[ -n "$DESKTOP_TOKEN" ]] && upsert_env GC_MOBILE_JENKINS_TOKEN "$DESKTOP_TOKEN" + +if ! grep -q '^GC_MOBILE_APP_IOS_TESTFLIGHT_URL=' "$ENV_FILE" 2>/dev/null; then + echo '# TestFlight 초대 URL — App Store Connect에서 발급 후 설정' >> "$ENV_FILE" + echo 'GC_MOBILE_APP_IOS_TESTFLIGHT_URL=' >> "$ENV_FILE" +fi + +log "Docker backend·frontend 재빌드" +cd "$WORK_TREE" +docker compose up -d --build backend frontend + +log "Mobile Jenkins 빌드 트리거" +export GC_MOBILE_JENKINS_URL=http://127.0.0.1:8090 +export GC_MOBILE_JENKINS_USER="${DESKTOP_USER:-}" +export GC_MOBILE_JENKINS_TOKEN="${DESKTOP_TOKEN:-}" +"$WORK_TREE/scripts/trigger-mobile-jenkins-build.sh" || log "[WARN] Mobile Jenkins 트리거 실패" + +if command -v pod >/dev/null 2>&1 && [[ -f "$WORK_TREE/app/ios/App/Podfile" ]]; then + log "iOS pod install" + (cd "$WORK_TREE/app/ios/App" && pod install) || log "[WARN] pod install 실패" +else + log "CocoaPods 없음 — iOS 빌드는 brew install cocoapods 후 pod install" +fi + +log "API 확인" +sleep 4 +curl -fsSL http://127.0.0.1:8080/api/mobile-app/info 2>/dev/null | python3 -m json.tool 2>/dev/null || \ + curl -fsSL http://exdev.co.kr/api/mobile-app/info | python3 -m json.tool 2>/dev/null || true + +log "완료" diff --git a/scripts/trigger-desktop-jenkins-build.sh b/scripts/trigger-desktop-jenkins-build.sh index f31d7f5..0c9d477 100755 --- a/scripts/trigger-desktop-jenkins-build.sh +++ b/scripts/trigger-desktop-jenkins-build.sh @@ -13,21 +13,23 @@ log() { echo "$(date '+%Y-%m-%d %H:%M:%S') $LOG_TAG $*"; } JENKINS_URL="${JENKINS_URL%/}" JOB_API="${JENKINS_URL}/job/${JENKINS_JOB// /%20}" +COOKIE_JAR="$(mktemp)" +trap 'rm -f "$COOKIE_JAR"' EXIT curl_get() { + local auth=() if [[ -n "$JENKINS_USER" && -n "$JENKINS_TOKEN" ]]; then - curl -sf -u "${JENKINS_USER}:${JENKINS_TOKEN}" "$@" - else - curl -sf "$@" + auth=(-u "${JENKINS_USER}:${JENKINS_TOKEN}") fi + curl -sf "${auth[@]}" -c "$COOKIE_JAR" -b "$COOKIE_JAR" "$@" } curl_post() { + local auth=() if [[ -n "$JENKINS_USER" && -n "$JENKINS_TOKEN" ]]; then - curl -sf -X POST -u "${JENKINS_USER}:${JENKINS_TOKEN}" "$@" - else - curl -sf -X POST "$@" + auth=(-u "${JENKINS_USER}:${JENKINS_TOKEN}") fi + curl -sf "${auth[@]}" -c "$COOKIE_JAR" -b "$COOKIE_JAR" -X POST "$@" } log "Jenkins desktop build — $JENKINS_JOB @ $JENKINS_URL" diff --git a/scripts/trigger-mobile-jenkins-build.sh b/scripts/trigger-mobile-jenkins-build.sh index ea33209..c3371e9 100755 --- a/scripts/trigger-mobile-jenkins-build.sh +++ b/scripts/trigger-mobile-jenkins-build.sh @@ -13,21 +13,23 @@ log() { echo "$(date '+%Y-%m-%d %H:%M:%S') $LOG_TAG $*"; } JENKINS_URL="${JENKINS_URL%/}" JOB_API="${JENKINS_URL}/job/${JENKINS_JOB// /%20}" +COOKIE_JAR="$(mktemp)" +trap 'rm -f "$COOKIE_JAR"' EXIT curl_get() { + local auth=() if [[ -n "$JENKINS_USER" && -n "$JENKINS_TOKEN" ]]; then - curl -sf -u "${JENKINS_USER}:${JENKINS_TOKEN}" "$@" - else - curl -sf "$@" + auth=(-u "${JENKINS_USER}:${JENKINS_TOKEN}") fi + curl -sf "${auth[@]}" -c "$COOKIE_JAR" -b "$COOKIE_JAR" "$@" } curl_post() { + local auth=() if [[ -n "$JENKINS_USER" && -n "$JENKINS_TOKEN" ]]; then - curl -sf -X POST -u "${JENKINS_USER}:${JENKINS_TOKEN}" "$@" - else - curl -sf -X POST "$@" + auth=(-u "${JENKINS_USER}:${JENKINS_TOKEN}") fi + curl -sf "${auth[@]}" -c "$COOKIE_JAR" -b "$COOKIE_JAR" -X POST "$@" } log "Jenkins mobile build — $JENKINS_JOB @ $JENKINS_URL"