name: Build & Deploy on: push: branches: [main] jobs: build-and-deploy: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 - name: Install JDK 17 + Maven run: | apt-get update -qq apt-get install -y -qq openjdk-17-jdk-headless maven openssh-client > /dev/null 2>&1 java -version mvn --version - name: Build with Maven run: | mvn -B clean package -DskipTests \ -Dmaven.compiler.release=17 ls -lh target/vessel-batch-aggregation.jar - name: Deploy to production server env: DEPLOY_KEY: ${{ secrets.DEPLOY_SSH_KEY }} run: | # SSH 키 설정 mkdir -p ~/.ssh echo "$DEPLOY_KEY" > ~/.ssh/id_deploy chmod 600 ~/.ssh/id_deploy ssh-keyscan -p 32023 192.168.1.18 >> ~/.ssh/known_hosts 2>/dev/null || true SSH_CMD="ssh -p 32023 -i ~/.ssh/id_deploy -o StrictHostKeyChecking=no root@192.168.1.18" SCP_CMD="scp -P 32023 -i ~/.ssh/id_deploy -o StrictHostKeyChecking=no" # JAR 전송 echo "=== Uploading JAR ===" $SCP_CMD target/vessel-batch-aggregation.jar root@192.168.1.18:/home/apps/signal-batch/vessel-batch-aggregation.jar.new # 원자적 교체 + 서비스 재시작 echo "=== Deploying ===" $SSH_CMD bash -s << 'DEPLOY' set -e APP_DIR=/home/apps/signal-batch # 기존 JAR 백업 if [ -f $APP_DIR/vessel-batch-aggregation.jar ]; then cp $APP_DIR/vessel-batch-aggregation.jar $APP_DIR/backup/vessel-batch-aggregation.jar.$(date +%Y%m%d-%H%M%S) fi # 원자적 교체 mv $APP_DIR/vessel-batch-aggregation.jar.new $APP_DIR/vessel-batch-aggregation.jar # 백업 정리 (최근 5개만 유지) ls -t $APP_DIR/backup/vessel-batch-aggregation.jar.* 2>/dev/null | tail -n +6 | xargs rm -f 2>/dev/null || true # 서비스 재시작 systemctl restart signal-batch echo "Service restarted, waiting for startup..." # 시작 확인 (최대 90초 — 48GB 힙 AlwaysPreTouch) for i in $(seq 1 90); do if curl -sf http://localhost:18090/actuator/health > /dev/null 2>&1; then echo "Service started successfully (${i}s)" curl -s http://localhost:18090/actuator/health exit 0 fi sleep 1 done echo "WARNING: Startup timeout. Recent logs:" journalctl -u signal-batch --no-pager -n 50 exit 1 DEPLOY - name: Cleanup if: always() run: rm -f ~/.ssh/id_deploy