name: eapim-portal CI on: push: branches: - master - develop - stage - feats/ci-test jobs: build: runs-on: [self-hosted, linux, eapim-portal] env: JAVA_HOME: /apps/opts/jdk8 JAVA_HOME_TOMCAT: /apps/opts/jdk17 CATALINA_BASE: /prod/eapim/devportal CATALINA_HOME: /prod/eapim/apache-tomcat-9.0.116 CATALINA_PID: /prod/eapim/devportal/temp/catalina.pid DEPLOY_HTTP_PORT: "39130" defaults: run: working-directory: eapim-portal steps: - name: Checkout eapim-portal (this branch) # ref 미지정 — 트리거된 브랜치/commit(github.sha) 그대로 빌드. uses: http://172.30.1.50:3000/actions/checkout@v4 with: path: eapim-portal - name: Checkout elink-portal-common (master, dependency) # 의존 모듈은 항상 master 고정. working-directory: ${{ github.workspace }} run: | rm -rf elink-portal-common git clone --depth=1 --branch master \ http://oauth2:${{ secrets.CI_TOKEN }}@172.30.1.50:3000/djb-eapim/elink-portal-common.git \ elink-portal-common - name: Checkout elink-online-core-jpa (master, dependency) # 의존 모듈은 항상 master 고정. working-directory: ${{ github.workspace }} run: | mkdir -p eapim-online rm -rf eapim-online/elink-online-core-jpa git clone --depth=1 --branch master \ http://oauth2:${{ secrets.CI_TOKEN }}@172.30.1.50:3000/djb-eapim/elink-online-core-jpa.git \ eapim-online/elink-online-core-jpa - name: Verify toolchain run: | java -version gradle --version - name: Gradle build (no tests) run: gradle clean build -x test --no-daemon - name: Upload WAR artifacts uses: http://172.30.1.50:3000/actions/upload-artifact@v3 with: name: eapim-portal-wars-${{ github.sha }} path: | eapim-portal/build/libs/eapim-portal.war eapim-portal/build/libs/eapim-portal-boot.war if-no-files-found: error - name: Publish WAR to Gitea Generic Package working-directory: ${{ github.workspace }} env: GITEA_URL: http://172.30.1.50:3000 PKG_OWNER: djb-eapim PKG_NAME: eapim-portal run: | SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-7) VERSION="$(TZ=Asia/Seoul date +%Y-%m-%d-%H%M)-${SHORT_SHA}" BASE="$GITEA_URL/api/packages/$PKG_OWNER/generic/$PKG_NAME/$VERSION" echo "package version: $VERSION" echo "endpoint base : $BASE" for WAR in eapim-portal.war eapim-portal-boot.war; do SRC="eapim-portal/build/libs/$WAR" if [ ! -f "$SRC" ]; then echo "::error::missing artifact: $SRC" exit 1 fi HTTP=$(curl -sS -o "/tmp/pkg-upload-$WAR.log" -w '%{http_code}' \ --user "oauth2:${{ secrets.CI_TOKEN }}" \ --upload-file "$SRC" \ "$BASE/$WAR") if [ "$HTTP" != "201" ] && [ "$HTTP" != "200" ]; then echo "::error::upload failed for $WAR (HTTP $HTTP)" cat "/tmp/pkg-upload-$WAR.log" || true exit 1 fi echo " uploaded: $WAR (HTTP $HTTP)" done echo "published: $GITEA_URL/$PKG_OWNER/-/packages/generic/$PKG_NAME/$VERSION" - name: Stop tomcat (pre-clean) working-directory: ${{ github.workspace }} run: | # 1) systemd 관리 인스턴스 정지 (이번 워크플로가 띄운 것) systemctl --user stop eapim-portal 2>/dev/null || true # 2) systemd 외부 detached 인스턴스 (eapim-boot-start.sh 등) 정리 if [ -f "$CATALINA_PID" ] && kill -0 "$(cat $CATALINA_PID)" 2>/dev/null; then JAVA_HOME=$JAVA_HOME_TOMCAT "$CATALINA_HOME/bin/shutdown.sh" 30 -force || true for i in $(seq 1 30); do [ -f "$CATALINA_PID" ] && kill -0 "$(cat $CATALINA_PID)" 2>/dev/null || break sleep 1 done fi rm -f "$CATALINA_PID" - name: Deploy war as ROOT working-directory: ${{ github.workspace }} run: | DEPLOY_DIR="$CATALINA_BASE/webapps" rm -rf "$DEPLOY_DIR/ROOT" "$DEPLOY_DIR/ROOT.war" cp eapim-portal/build/libs/eapim-portal.war "$DEPLOY_DIR/ROOT.war" ls -la "$DEPLOY_DIR" - name: Start tomcat and readiness probe (timeout 120s) working-directory: ${{ github.workspace }} run: | LOG="$CATALINA_BASE/logs/catalina.$(date +%Y-%m-%d).log" BEFORE=0 [ -f "$LOG" ] && BEFORE=$(stat -c %s "$LOG") # systemd 가 Tomcat 을 새 cgroup 으로 띄움 — runner step 종료와 무관하게 살아남음 systemctl --user start eapim-portal DEADLINE=$(($(date +%s) + 120)) LIVE_OK=0 STATUS=000 BODY="" while [ $(date +%s) -lt $DEADLINE ]; do # Stage 1: liveness — servlet 응답 가능? if [ "$LIVE_OK" = "0" ]; then LIVE=$(curl -sS -o /dev/null -w '%{http_code}' --max-time 3 \ http://localhost:$DEPLOY_HTTP_PORT/health 2>/dev/null || echo "000") if [ "$LIVE" = "200" ]; then echo "Liveness OK (/health)" LIVE_OK=1 fi fi # Stage 2: readiness — DB(EMS, Gateway)까지 검증 if [ "$LIVE_OK" = "1" ]; then BODY=$(curl -sS -o /tmp/ready-body.json -w '%{http_code}' --max-time 3 \ http://localhost:$DEPLOY_HTTP_PORT/health/ready 2>/dev/null || echo "000") STATUS=$BODY if [ "$STATUS" = "200" ]; then echo "Readiness OK (/health/ready)" cat /tmp/ready-body.json echo break fi fi if [ -f "$LOG" ] && tail -c +$((BEFORE+1)) "$LOG" | grep -qE "Application listener .* Exception|SEVERE.*startup.Catalina"; then echo "::error::Startup error detected in log" tail -c +$((BEFORE+1)) "$LOG" | tail -80 exit 1 fi sleep 2 done if [ "$STATUS" != "200" ]; then echo "::error::Readiness probe failed within 120s (last HTTP status: $STATUS)" [ -f /tmp/ready-body.json ] && echo "--- last readiness body ---" && cat /tmp/ready-body.json && echo [ -f "$LOG" ] && tail -c +$((BEFORE+1)) "$LOG" | tail -100 exit 1 fi echo "--- key boot log lines ---" tail -c +$((BEFORE+1)) "$LOG" | grep -E "Server startup|Deployment of web" | head -10 || true