diff --git a/Jenkinsfile.deploy b/Jenkinsfile.deploy new file mode 100644 index 0000000..0dd45e7 --- /dev/null +++ b/Jenkinsfile.deploy @@ -0,0 +1,182 @@ +pipeline { + agent { label 'djb-vm' } + + parameters { + string(name: 'BRANCH', defaultValue: 'master', description: 'Branch to deploy') + } + + options { + timestamps() + disableConcurrentBuilds() + buildDiscarder(logRotator(numToKeepStr: '20', artifactNumToKeepStr: '20')) + } + + environment { + JAVA_HOME = '/apps/opts/jdk8' + JAVA_HOME_TOMCAT = '/apps/opts/jdk17' + GRADLE_HOME = '/apps/opts/gradle-8.7' + GRADLE_USER_HOME = '/apps/opts/gradle-home' + NODE_HOME = '/apps/opts/node-v24' + PATH = "/apps/opts/jdk8/bin:/apps/opts/gradle-8.7/bin:/apps/opts/node-v24/bin:/apps/opts/bin:${env.PATH}" + GIT_SSH_COMMAND = 'ssh -o StrictHostKeyChecking=accept-new' + 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' + } + + stages { + stage('Checkout') { + steps { + checkout([ + $class: 'GitSCM', + branches: [[name: "*/${params.BRANCH}"]], + userRemoteConfigs: [[url: 'ssh://git@172.30.1.50:2222/djb-eapim/eapim-portal.git']] + ]) + } + } + + stage('Checkout dependencies') { + steps { + sh ''' + set -eu + cd "$WORKSPACE/.." + + if [ ! -d elink-portal-common/.git ]; then + git clone --depth=1 --branch master \ + ssh://git@172.30.1.50:2222/djb-eapim/elink-portal-common.git \ + elink-portal-common + else + git -C elink-portal-common fetch --depth=1 origin master + git -C elink-portal-common reset --hard origin/master + git -C elink-portal-common clean -fdx + fi + + mkdir -p eapim-online + if [ ! -d eapim-online/elink-online-core-jpa/.git ]; then + git clone --depth=1 --branch master \ + ssh://git@172.30.1.50:2222/djb-eapim/elink-online-core-jpa.git \ + eapim-online/elink-online-core-jpa + else + git -C eapim-online/elink-online-core-jpa fetch --depth=1 origin master + git -C eapim-online/elink-online-core-jpa reset --hard origin/master + git -C eapim-online/elink-online-core-jpa clean -fdx + fi + ''' + } + } + + stage('Verify toolchain') { + steps { + sh ''' + set -eu + java -version + gradle --version + ''' + } + } + + stage('Build WAR') { + steps { + sh 'gradle clean build -x test --no-daemon' + } + post { + success { + sh ''' + set -eu + cd build/libs + sha1sum eapim-portal.war eapim-portal-boot.war > SHA1SUMS + sha256sum eapim-portal.war eapim-portal-boot.war > SHA256SUMS + ''' + archiveArtifacts artifacts: 'build/libs/eapim-portal.war,build/libs/eapim-portal-boot.war,build/libs/SHA1SUMS,build/libs/SHA256SUMS', fingerprint: true + } + } + } + + stage('Stop Tomcat') { + steps { + sh ''' + set +e + systemctl --user stop eapim-portal 2>/dev/null + + 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" + ''' + } + } + + stage('Deploy ROOT.war') { + steps { + sh ''' + set -eu + DEPLOY_DIR="$CATALINA_BASE/webapps" + rm -rf "$DEPLOY_DIR/ROOT" "$DEPLOY_DIR/ROOT.war" + cp build/libs/eapim-portal.war "$DEPLOY_DIR/ROOT.war" + ls -la "$DEPLOY_DIR" + ''' + } + } + + stage('Start Tomcat and readiness') { + steps { + sh ''' + set -eu + LOG="$CATALINA_BASE/logs/catalina.$(date +%Y-%m-%d).log" + BEFORE=0 + [ -f "$LOG" ] && BEFORE=$(stat -c %s "$LOG") + + systemctl --user start eapim-portal + + DEADLINE=$(($(date +%s) + 120)) + LIVE_OK=0 + STATUS=000 + + while [ "$(date +%s)" -lt "$DEADLINE" ]; do + 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 + + if [ "$LIVE_OK" = "1" ]; then + STATUS=$(curl -sS -o /tmp/eapim-ready-body.json -w '%{http_code}' --max-time 3 \ + "http://localhost:$DEPLOY_HTTP_PORT/health/ready" 2>/dev/null || echo "000") + if [ "$STATUS" = "200" ]; then + echo "Readiness OK (/health/ready)" + cat /tmp/eapim-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 "Startup error detected in log" + tail -c +$((BEFORE+1)) "$LOG" | tail -80 + exit 1 + fi + sleep 2 + done + + if [ "$STATUS" != "200" ]; then + echo "Readiness probe failed within 120s, last HTTP status: $STATUS" + [ -f /tmp/eapim-ready-body.json ] && cat /tmp/eapim-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 + ''' + } + } + } +} diff --git a/Jenkinsfile.test-build b/Jenkinsfile.test-build new file mode 100644 index 0000000..e1d2d4c --- /dev/null +++ b/Jenkinsfile.test-build @@ -0,0 +1,102 @@ +pipeline { + agent { label 'djb-vm' } + + triggers { + pollSCM('H/10 * * * *') + } + + options { + timestamps() + disableConcurrentBuilds() + buildDiscarder(logRotator(numToKeepStr: '20', artifactNumToKeepStr: '20')) + } + + environment { + JAVA_HOME = '/apps/opts/jdk8' + JAVA_HOME_TOMCAT = '/apps/opts/jdk17' + GRADLE_HOME = '/apps/opts/gradle-8.7' + GRADLE_USER_HOME = '/apps/opts/gradle-home' + NODE_HOME = '/apps/opts/node-v24' + PATH = "/apps/opts/jdk8/bin:/apps/opts/gradle-8.7/bin:/apps/opts/node-v24/bin:/apps/opts/bin:${env.PATH}" + GIT_SSH_COMMAND = 'ssh -o StrictHostKeyChecking=accept-new' + } + + stages { + stage('Checkout') { + steps { + checkout scm + } + } + + stage('Checkout dependencies') { + steps { + sh ''' + set -eu + cd "$WORKSPACE/.." + + if [ ! -d elink-portal-common/.git ]; then + git clone --depth=1 --branch master \ + ssh://git@172.30.1.50:2222/djb-eapim/elink-portal-common.git \ + elink-portal-common + else + git -C elink-portal-common fetch --depth=1 origin master + git -C elink-portal-common reset --hard origin/master + git -C elink-portal-common clean -fdx + fi + + mkdir -p eapim-online + if [ ! -d eapim-online/elink-online-core-jpa/.git ]; then + git clone --depth=1 --branch master \ + ssh://git@172.30.1.50:2222/djb-eapim/elink-online-core-jpa.git \ + eapim-online/elink-online-core-jpa + else + git -C eapim-online/elink-online-core-jpa fetch --depth=1 origin master + git -C eapim-online/elink-online-core-jpa reset --hard origin/master + git -C eapim-online/elink-online-core-jpa clean -fdx + fi + ''' + } + } + + stage('Verify toolchain') { + steps { + sh ''' + set -eu + java -version + gradle --version + node --version || true + npm --version || true + ''' + } + } + + stage('Test') { + steps { + sh 'gradle clean test --no-daemon' + } + post { + always { + junit allowEmptyResults: true, testResults: 'build/test-results/test/*.xml' + archiveArtifacts allowEmptyArchive: true, artifacts: 'build/reports/tests/test/**,build/test-results/test/**' + } + } + } + + stage('Build WAR') { + steps { + sh 'gradle build -x test --no-daemon' + } + post { + success { + sh ''' + set -eu + cd build/libs + sha1sum eapim-portal.war eapim-portal-boot.war > SHA1SUMS + sha256sum eapim-portal.war eapim-portal-boot.war > SHA256SUMS + ''' + archiveArtifacts artifacts: 'build/libs/eapim-portal.war,build/libs/eapim-portal-boot.war,build/libs/SHA1SUMS,build/libs/SHA256SUMS', fingerprint: true + } + } + } + } +} diff --git a/build-gf63.sh b/build-gf63.sh deleted file mode 100644 index 9a8060e..0000000 --- a/build-gf63.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -export JAVA_HOME=/c/eactive/apps/jdk1.8.0_441 -export GRADLE_HOME=/c/eactive/apps/gradle-8.7 -export GRADLE_USER_HOME=/c/eactive/workspaces/gradle-user-home-kjbank - -export PATH=$JAVA_HOME/bin:$GRADLE_HOME/bin:$PATH - - -echo "========================" -java -version -javac -version -echo "========================" -gradle --version -echo "========================" - -gradle clean build -x test --no-daemon \ No newline at end of file diff --git a/build_docker.sh b/build_docker.sh deleted file mode 100644 index 1cf0a19..0000000 --- a/build_docker.sh +++ /dev/null @@ -1,3 +0,0 @@ -./gradlew bootWar -docker build -t eactive-portal . - diff --git a/deploy_portal.sh b/deploy_portal.sh deleted file mode 100644 index 5344dea..0000000 --- a/deploy_portal.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/bash - -# Check if the war file is provided -if [ -z "$1" ]; then - echo "Usage: $0 /path/to/DEVPortal.war" - exit 1 -fi - -# Variables -WAR_FILE="$1" -TIMESTAMP=$(date +%Y%m%d%H%M%S) -DEST_DIR="/app/apim/deploy/DVPWeb" -BACKUP_DIR="/app/apim/backup" - -# Create backup directory if not exists -mkdir -p $BACKUP_DIR - -# Backup the existing directory -if [ -d "$DEST_DIR" ]; then - echo "Backing up existing directory..." - mv $DEST_DIR "${BACKUP_DIR}/dvp_${TIMESTAMP}" -fi - -# Create destination directory if not exists -mkdir -p $DEST_DIR - -# Unzip the file to the dedicated location -echo "Extracting WAR file to $DEST_DIR..." -unzip $WAR_FILE -d $DEST_DIR - -echo "deploy successful" diff --git a/deploy_portal2.sh b/deploy_portal2.sh deleted file mode 100644 index 952665c..0000000 --- a/deploy_portal2.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/bash - -# Check if the war file is provided -if [ -z "$1" ]; then - echo "Usage: $0 /path/to/DEVPortal.war" - exit 1 -fi - -# Variables -WAR_FILE="$1" -TIMESTAMP=$(date +%Y%m%d%H%M%S) -DEST_DIR="/app/apim/deploy/DVPWeb" -STATIC_DIR="/app/apim/deploy/static" -BACKUP_DIR="/app/apim/backup" - -# Create backup directory if not exists -mkdir -p $BACKUP_DIR - -# Backup the existing directory -if [ -d "$STATIC_DIR" ]; then - echo "Backing up existing static directory..." - mv $STATIC_DIR "${BACKUP_DIR}/dvp_static_${TIMESTAMP}" -fi - -if [ -d "$DEST_DIR" ]; then - echo "Backing up existing directory..." - mv $DEST_DIR "${BACKUP_DIR}/dvp_${TIMESTAMP}" -fi - - -# Create destination directory if not exists -mkdir -p $DEST_DIR -mkdir -p $STATIC_DIR - -# unzip the file to the dedicated location -echo "Extracting WAR file to $DEST_DIR..." -unzip $WAR_FILE -d $DEST_DIR -mv $DEST_DIR/static/* $STATIC_DIR/ - -echo "deploy successful" diff --git a/gradle-gf63.sh b/gradle-gf63.sh deleted file mode 100644 index 35d9cc1..0000000 --- a/gradle-gf63.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -export JAVA_HOME=/c/eactive/apps/jdk1.8.0_441 -export GRADLE_HOME=/c/eactive/apps/gradle-8.7 -export GRADLE_USER_HOME=/c/eactive/workspaces/gradle-user-home-kjbank - -export PATH=$JAVA_HOME/bin:$GRADLE_HOME/bin:$PATH - - -# gradle 명령을 대체합니다. -command gradle $@ \ No newline at end of file