#!/usr/bin/env bash set -e export KUBECONFIG="${KUBECONFIG:-/home/chpark/.kube/config}" # root 실행 시엔 sudo 생략, 일반 유저면 비번으로 sudo if [ "$(id -u)" -eq 0 ]; then sudo_run() { bash -c "$1"; } else SUDO_PASS="${SUDO_PASS:-qlalfqjsgh11}" sudo_run() { echo "$SUDO_PASS" | sudo -S bash -c "$1"; } fi # CI(root) 환경에서 kubeconfig 없으면 k3s 것으로 대체 if [ ! -r "$KUBECONFIG" ]; then if [ -r /etc/rancher/k3s/k3s.yaml ]; then export KUBECONFIG=/etc/rancher/k3s/k3s.yaml fi fi cd /home/chpark if [ -d insurance/.git ]; then echo "[*] Updating insurance repo" cd insurance && git fetch origin && git reset --hard origin/master else rm -rf /home/chpark/insurance 2>/dev/null || true echo "[*] Cloning insurance repo" git clone https://git.junggomoa.com/chpark/insurance.git cd insurance fi echo "[*] Building web image" docker build \ --build-arg EXPO_PUBLIC_API_BASE=https://api.insurance.junggomoa.com \ --build-arg EXPO_PUBLIC_KAKAO_JS_KEY="${EXPO_PUBLIC_KAKAO_JS_KEY:-}" \ --build-arg EXPO_PUBLIC_NAVER_CLIENT_ID="${EXPO_PUBLIC_NAVER_CLIENT_ID:-}" \ -t localhost:5000/insurance/web:latest \ -f Dockerfile . echo "[*] Building api image" docker build -t localhost:5000/insurance/api:latest -f server/Dockerfile server echo "[*] Pushing to local registry" docker push localhost:5000/insurance/web:latest docker push localhost:5000/insurance/api:latest echo "[*] Applying Kubernetes manifests" kubectl apply -f deploy/k8s/namespace.yaml SECRETS_FILE=/home/chpark/.insurance-secrets if [ -r "$SECRETS_FILE" ]; then set -a; source "$SECRETS_FILE"; set +a fi POSTGRES_PASSWORD="${POSTGRES_PASSWORD:-$(openssl rand -hex 24)}" JWT_SECRET="${JWT_SECRET:-$(openssl rand -hex 32)}" cat > "$SECRETS_FILE" <&1 | head -3 || echo "[!] web 30200 not ready" curl -fsS http://127.0.0.1:30201/health 2>&1 | head -3 || echo "[!] api 30201 not ready" echo "" echo "🚀 Web: https://insurance.junggomoa.com" echo "🔌 API: https://api.insurance.junggomoa.com"