admin/front 분리2

This commit is contained in:
2026-07-20 17:49:39 +09:00
parent ed41ef24cb
commit 1eac5db02d
4 changed files with 154 additions and 237 deletions
@@ -1,17 +1,10 @@
server: server:
port: 8106 port: 8111
forward-headers-strategy: framework forward-headers-strategy: framework
spring: spring:
application: application:
name: api name: api-admin
mybatis:
mapper-locations: classpath:mapper/**/*.xml
type-aliases-package: com.alist.api
configuration:
map-underscore-to-camel-case: true
log-impl: org.apache.ibatis.logging.slf4j.Slf4jImpl
springdoc: springdoc:
swagger-ui: swagger-ui:
@@ -1,6 +1,4 @@
spring: spring:
application:
name: api
datasource: datasource:
url: jdbc:log4jdbc:mariadb://121.160.234.222:3000/ALISTLMS?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Seoul&connectionCollation=utf8mb4_uca1400_ai_ci url: jdbc:log4jdbc:mariadb://121.160.234.222:3000/ALISTLMS?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Seoul&connectionCollation=utf8mb4_uca1400_ai_ci
username: alist_dev username: alist_dev
@@ -24,6 +22,7 @@ spring:
migration: migration:
datasource: datasource:
alist: alist:
enabled: true
jdbc-url: jdbc:log4jdbc:sqlserver://bigfuntnp.co.kr:51433;databaseName=alist_dev;encrypt=false;trustServerCertificate=true jdbc-url: jdbc:log4jdbc:sqlserver://bigfuntnp.co.kr:51433;databaseName=alist_dev;encrypt=false;trustServerCertificate=true
username: bigfuntnp username: bigfuntnp
password: password12!@ password: password12!@
@@ -32,6 +31,7 @@ migration:
minimum-idle: 1 minimum-idle: 1
connection-timeout: 10000 connection-timeout: 10000
eltown: eltown:
enabled: true
jdbc-url: jdbc:log4jdbc:sqlserver://bigfuntnp.co.kr:51433;databaseName=eltown;encrypt=false;trustServerCertificate=true jdbc-url: jdbc:log4jdbc:sqlserver://bigfuntnp.co.kr:51433;databaseName=eltown;encrypt=false;trustServerCertificate=true
username: bigfuntnp username: bigfuntnp
password: password12!@ password: password12!@
@@ -51,7 +51,6 @@ jwt:
cookie: cookie:
secure: false # (HTTP) -> false secure: false # (HTTP) -> false
domain: # (HTTP) -> 비워두세요 domain: # (HTTP) -> 비워두세요
name: ALIST_SSO
same-site: Lax # (HTTP) -> Lax same-site: Lax # (HTTP) -> Lax
swagger: swagger:
@@ -59,32 +58,11 @@ swagger:
id: alist id: alist
password: "1qaz2wsx!@" password: "1qaz2wsx!@"
tus-file:
upload:
tus-endpoint: https://file-alist.pjt.kr/tus/file/
public-base-url: https://file-alist.pjt.kr
tmp-root: /srv/project/alist/uploads/tmp
final-root: /srv/project/alist/uploads
interrupt-seconds: 30
auth-cache:
ttl-seconds: 20
# types:
# notice:
# folder: notice 저장폴더
# max-size: 20MB 최대 용량
# image-only: false
# resize:
# enabled: true
# width: 800 고정넓이
# height: 600 고정높이
# max-width: 1200 최대 넓이
file: file:
storage:
root-path: /srv/project/alist/uploads
view-domain: http://localhost:8110
upload: upload:
view:
file-domain: http://localhost:8110
root-path: ${tus-file.upload.final-root}
max-size: 10MB max-size: 10MB
allowed-extensions: [jpg, jpeg, png, gif, pdf, hwp, hwpx, doc, docx, xls, xlsx, ppt, pptx, txt, csv, zip] allowed-extensions: [jpg, jpeg, png, gif, pdf, hwp, hwpx, doc, docx, xls, xlsx, ppt, pptx, txt, csv, zip]
types: types:
@@ -1,6 +1,4 @@
spring: spring:
application:
name: api
main: main:
banner-mode: log banner-mode: log
datasource: datasource:
@@ -26,6 +24,7 @@ spring:
migration: migration:
datasource: datasource:
alist: alist:
enabled: true
jdbc-url: jdbc:log4jdbc:sqlserver://${ALIST_DB_HOST}:${ALIST_DB_PORT};databaseName=${ALIST_DB_NAME};encrypt=false;trustServerCertificate=true jdbc-url: jdbc:log4jdbc:sqlserver://${ALIST_DB_HOST}:${ALIST_DB_PORT};databaseName=${ALIST_DB_NAME};encrypt=false;trustServerCertificate=true
username: ${ALIST_DB_USERNAME} username: ${ALIST_DB_USERNAME}
password: ${ALIST_DB_PASSWORD} password: ${ALIST_DB_PASSWORD}
@@ -34,6 +33,7 @@ migration:
minimum-idle: 1 minimum-idle: 1
connection-timeout: 10000 connection-timeout: 10000
eltown: eltown:
enabled: true
jdbc-url: jdbc:log4jdbc:sqlserver://${ELTOWN_DB_HOST}:${ELTOWN_DB_PORT};databaseName=${ELTOWN_DB_NAME};encrypt=false;trustServerCertificate=true jdbc-url: jdbc:log4jdbc:sqlserver://${ELTOWN_DB_HOST}:${ELTOWN_DB_PORT};databaseName=${ELTOWN_DB_NAME};encrypt=false;trustServerCertificate=true
username: ${ELTOWN_DB_USERNAME} username: ${ELTOWN_DB_USERNAME}
password: ${ELTOWN_DB_PASSWORD} password: ${ELTOWN_DB_PASSWORD}
@@ -52,8 +52,7 @@ jwt:
cookie: cookie:
secure: true # 프로젝트 환경 (HTTPS) secure: true # 프로젝트 환경 (HTTPS)
domain: api-alist.pjt.kr domain: apifront-alist.pjt.kr
name: ALIST_SSO
same-site: None same-site: None
swagger: swagger:
@@ -61,32 +60,11 @@ swagger:
id: ${SWAGGER_ID} id: ${SWAGGER_ID}
password: ${SWAGGER_PASSWORD} password: ${SWAGGER_PASSWORD}
tus-file:
upload:
tus-endpoint: https://file-alist.pjt.kr/tus/file/
public-base-url: https://file-alist.pjt.kr
tmp-root: /srv/project/alist/uploads/tmp
final-root: /srv/project/alist/uploads
interrupt-seconds: 30
auth-cache:
ttl-seconds: 20
# types:
# notice:
# folder: notice 저장폴더
# max-size: 20MB 최대 용량
# image-only: false
# resize:
# enabled: true
# width: 800 고정넓이
# height: 600 고정높이
# max-width: 1200 최대 넓이
file: file:
storage:
root-path: /srv/project/alist/uploads
view-domain: https://file-alist.pjt.kr
upload: upload:
view:
file-domain: https://file-alist.pjt.kr
root-path: ${tus-file.upload.final-root}
max-size: 10MB max-size: 10MB
allowed-extensions: [jpg, jpeg, png, gif, pdf, hwp, hwpx, doc, docx, xls, xlsx, ppt, pptx, txt, csv, zip] allowed-extensions: [jpg, jpeg, png, gif, pdf, hwp, hwpx, doc, docx, xls, xlsx, ppt, pptx, txt, csv, zip]
types: types:
+138 -170
View File
@@ -6,73 +6,110 @@ pipeline {
disableConcurrentBuilds() disableConcurrentBuilds()
} }
parameters {
choice(
name: 'TARGET',
choices: ['admin', 'front', 'all'],
description: '빌드와 배포할 API 서버를 선택합니다.'
)
}
environment { environment {
// ===== Registry ===== REGISTRY_HOST = 'registry.pjt.kr'
REGISTRY_HOST = "registry.pjt.kr" DOCKER_CRED = 'registry-pjt'
IMAGE_REPO = "alist/api"
DOCKER_CRED = "registry-pjt"
// ===== api ssh ===== SSH_HOST = '121.160.234.222'
SSH_HOST = "121.160.234.222" SSH_PORT = '2001'
SSH_PORT = "2001" SSH_USER = 'bigfuntnp'
SSH_USER = "bigfuntnp" SSH_COMPOSE_DIR = '/srv/project/alist/compose'
SSH_COMPOSE_DIR = "/srv/project/alist/compose"
SSH_COMPOSE_FILE = "api-compose.pjt.yml"
// ===== jenkins workspace path ===== ADMIN_IMAGE_REPO = 'alist/api-admin'
WORK_COMPOSE_DIR = "deploy/pjt/compose" ADMIN_MODULE_DIR = '02-api-admin'
WORK_COMPOSE_FILE = "api-compose.pjt.yml" ADMIN_COMPOSE_FILE = 'api-admin-compose.pjt.yml'
ADMIN_ENV_FILE = '/srv/project/alist/env/api-admin/.env'
FRONT_IMAGE_REPO = 'alist/api-front'
FRONT_MODULE_DIR = '03-api-front'
FRONT_COMPOSE_FILE = 'api-front-compose.pjt.yml'
FRONT_ENV_FILE = '/srv/project/alist/env/api-front/.env'
WORK_COMPOSE_DIR = 'deploy/pjt/compose'
} }
stages { stages {
stage('1) Git check out') { stage('1) Git check out') {
steps { steps {
echo "[1/1] Git check out"
checkout scm checkout scm
} }
} }
stage('2) Build (Gradle)') { stage('2) ImageTag create') {
steps {
sh '''
set -e
echo "[1/1] Gradle build"
chmod +x ./gradlew
./gradlew clean build -x test
'''
}
}
stage('3) ImageTag create') {
steps { steps {
script { script {
env.SHORT_SHA = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim()
echo "[1/1] ImageTag create"
env.SHORT_SHA = sh(script: "git rev-parse --short HEAD", returnStdout: true).trim()
echo "SHORT_SHA = ${env.SHORT_SHA}"
env.IMAGE_TAG = "${env.BUILD_NUMBER}-${env.SHORT_SHA}" env.IMAGE_TAG = "${env.BUILD_NUMBER}-${env.SHORT_SHA}"
echo "TARGET = ${params.TARGET}"
echo "IMAGE_TAG = ${env.IMAGE_TAG}" echo "IMAGE_TAG = ${env.IMAGE_TAG}"
} }
} }
} }
stage('4) Docker Build') { stage('3) Build admin') {
when {
expression { params.TARGET == 'admin' || params.TARGET == 'all' }
}
steps { steps {
sh ''' sh '''
set -e set -e
chmod +x ./gradlew
echo "[1/1] docker build" ./gradlew :02-api-admin:bootJar
'''
docker build --no-cache -t ${REGISTRY_HOST}/${IMAGE_REPO}:${IMAGE_TAG} .
'''
} }
} }
stage('5) Docker registry Login & Push') { stage('4) Build front') {
when {
expression { params.TARGET == 'front' || params.TARGET == 'all' }
}
steps {
sh '''
set -e
chmod +x ./gradlew
./gradlew :03-api-front:bootJar
'''
}
}
stage('5) Docker build admin') {
when {
expression { params.TARGET == 'admin' || params.TARGET == 'all' }
}
steps {
sh '''
set -e
docker build --no-cache \\
-t ${REGISTRY_HOST}/${ADMIN_IMAGE_REPO}:${IMAGE_TAG} \\
${ADMIN_MODULE_DIR}
'''
}
}
stage('6) Docker build front') {
when {
expression { params.TARGET == 'front' || params.TARGET == 'all' }
}
steps {
sh '''
set -e
docker build --no-cache \\
-t ${REGISTRY_HOST}/${FRONT_IMAGE_REPO}:${IMAGE_TAG} \\
${FRONT_MODULE_DIR}
'''
}
}
stage('7) Docker push') {
steps { steps {
withCredentials([usernamePassword( withCredentials([usernamePassword(
credentialsId: DOCKER_CRED, credentialsId: DOCKER_CRED,
@@ -81,12 +118,15 @@ pipeline {
)]) { )]) {
sh ''' sh '''
set -e set -e
echo "[1/2] docker registry login"
echo "$DOCKER_PASS" | docker login ${REGISTRY_HOST} -u "$DOCKER_USER" --password-stdin echo "$DOCKER_PASS" | docker login ${REGISTRY_HOST} -u "$DOCKER_USER" --password-stdin
echo "[2/2] docker image push" if [ "${TARGET}" = "admin" ] || [ "${TARGET}" = "all" ]; then
docker push ${REGISTRY_HOST}/${IMAGE_REPO}:${IMAGE_TAG} docker push ${REGISTRY_HOST}/${ADMIN_IMAGE_REPO}:${IMAGE_TAG}
fi
if [ "${TARGET}" = "front" ] || [ "${TARGET}" = "all" ]; then
docker push ${REGISTRY_HOST}/${FRONT_IMAGE_REPO}:${IMAGE_TAG}
fi
docker logout ${REGISTRY_HOST} docker logout ${REGISTRY_HOST}
''' '''
@@ -94,42 +134,10 @@ pipeline {
} }
} }
stage('6) Jenkins cleanup') { stage('8) Deploy admin') {
steps { when {
sh ''' expression { params.TARGET == 'admin' || params.TARGET == 'all' }
set -e
echo "[1/3] Remove pushed image from Jenkins"
docker rmi ${REGISTRY_HOST}/${IMAGE_REPO}:${IMAGE_TAG} 2>/dev/null || true
echo "[2/3] Remove dangling images"
docker image prune -f
echo "[3/3] Remove old build cache (safe-ish)"
docker builder prune -f || true
'''
} }
}
stage('7) Copy compose') {
steps {
sshagent(['ssh-pjt']) {
sh '''
set -e
echo "[1/2] ssh login"
SRC="${WORK_COMPOSE_DIR}/${WORK_COMPOSE_FILE}"
DST="${SSH_USER}@${SSH_HOST}:${SSH_COMPOSE_DIR}/${SSH_COMPOSE_FILE}"
echo "[2/2] Copy compose $SRC -> $DST"
scp -P ${SSH_PORT} -o StrictHostKeyChecking=no "$SRC" "$DST"
'''
}
}
}
stage('8) Remote docker registry login') {
steps { steps {
sshagent(['ssh-pjt']) { sshagent(['ssh-pjt']) {
withCredentials([usernamePassword( withCredentials([usernamePassword(
@@ -140,15 +148,21 @@ pipeline {
sh ''' sh '''
set -e set -e
echo "[1/1] docker registry login" scp -P ${SSH_PORT} -o StrictHostKeyChecking=no \\
${WORK_COMPOSE_DIR}/${ADMIN_COMPOSE_FILE} \\
${SSH_USER}@${SSH_HOST}:${SSH_COMPOSE_DIR}/${ADMIN_COMPOSE_FILE}
ssh -p ${SSH_PORT} -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ${SSH_USER}@${SSH_HOST} ' ssh -p ${SSH_PORT} -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \\
set -e ${SSH_USER}@${SSH_HOST} '
REGISTRY_HOST='"${REGISTRY_HOST}"' set -e
DOCKER_USER='"${DOCKER_USER}"' cd '"${SSH_COMPOSE_DIR}"'
DOCKER_PASS='"${DOCKER_PASS}"' export IMAGE_TAG='"${IMAGE_TAG}"'
echo "$DOCKER_PASS" | docker login "$REGISTRY_HOST" -u "$DOCKER_USER" --password-stdin echo '"$DOCKER_PASS"' | docker login '"${REGISTRY_HOST}"' -u '"$DOCKER_USER"' --password-stdin
docker compose -p alist-api-admin --env-file '"${ADMIN_ENV_FILE}"' -f '"${ADMIN_COMPOSE_FILE}"' pull
docker compose -p alist-api-admin --env-file '"${ADMIN_ENV_FILE}"' -f '"${ADMIN_COMPOSE_FILE}"' up -d --remove-orphans
docker compose -p alist-api-admin --env-file '"${ADMIN_ENV_FILE}"' -f '"${ADMIN_COMPOSE_FILE}"' ps
docker logout '"${REGISTRY_HOST}"'
' '
''' '''
} }
@@ -156,105 +170,59 @@ pipeline {
} }
} }
stage('9) Remote docker pull') { stage('9) Deploy front') {
steps { when {
sshagent(['ssh-pjt']) { expression { params.TARGET == 'front' || params.TARGET == 'all' }
sh '''
set -e
ssh -p ${SSH_PORT} -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
${SSH_USER}@${SSH_HOST} \
'set -e
cd '"${SSH_COMPOSE_DIR}"'
export IMAGE_TAG='"${IMAGE_TAG}"'
echo "[1/1] docker pull"
docker compose -p alist-api --env-file /srv/project/alist/env/api/.env -f '"${SSH_COMPOSE_FILE}"' pull
'
'''
}
} }
}
stage('10) Remote docker down & up') {
steps { steps {
sshagent(['ssh-pjt']) { sshagent(['ssh-pjt']) {
sh ''' withCredentials([usernamePassword(
set -e credentialsId: DOCKER_CRED,
ssh -p ${SSH_PORT} -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \ usernameVariable: 'DOCKER_USER',
${SSH_USER}@${SSH_HOST} \ passwordVariable: 'DOCKER_PASS'
'set -e )]) {
cd '"${SSH_COMPOSE_DIR}"' sh '''
export IMAGE_TAG='"${IMAGE_TAG}"'
echo "[1/3] docker down (remove orphans)"
docker compose -p alist-api --env-file /srv/project/alist/env/api/.env -f "'"${SSH_COMPOSE_FILE}"'" down --remove-orphans
echo "[2/3] docker up"
docker compose -p alist-api --env-file /srv/project/alist/env/api/.env -f '"${SSH_COMPOSE_FILE}"' up -d
echo "[3/3] docker ps"
docker compose -p alist-api --env-file /srv/project/alist/env/api/.env -f '"${SSH_COMPOSE_FILE}"' ps
'
'''
}
}
}
stage('11) Remote cleanup') {
steps {
sshagent(['ssh-pjt']) {
sh '''
set -e
ssh -p ${SSH_PORT} -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ${SSH_USER}@${SSH_HOST} '
set -e set -e
Repo='"${REGISTRY_HOST}/${IMAGE_REPO}"' scp -P ${SSH_PORT} -o StrictHostKeyChecking=no \\
${WORK_COMPOSE_DIR}/${FRONT_COMPOSE_FILE} \\
${SSH_USER}@${SSH_HOST}:${SSH_COMPOSE_DIR}/${FRONT_COMPOSE_FILE}
echo "[1/3] Remove old image" ssh -p ${SSH_PORT} -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \\
docker images "${Repo}" --format '{{.Repository}}:{{.Tag}}' | grep -v -F -f <(docker ps --format '{{.Image}}') | xargs -r docker rmi ${SSH_USER}@${SSH_HOST} '
set -e
cd '"${SSH_COMPOSE_DIR}"'
export IMAGE_TAG='"${IMAGE_TAG}"'
echo "[2/3] Remove dangling images" echo '"$DOCKER_PASS"' | docker login '"${REGISTRY_HOST}"' -u '"$DOCKER_USER"' --password-stdin
docker image prune -f docker compose -p alist-api-front --env-file '"${FRONT_ENV_FILE}"' -f '"${FRONT_COMPOSE_FILE}"' pull
docker compose -p alist-api-front --env-file '"${FRONT_ENV_FILE}"' -f '"${FRONT_COMPOSE_FILE}"' up -d --remove-orphans
echo "[3/3] Remove old build cache (safe-ish)" docker compose -p alist-api-front --env-file '"${FRONT_ENV_FILE}"' -f '"${FRONT_COMPOSE_FILE}"' ps
docker builder prune -f || true docker logout '"${REGISTRY_HOST}"'
' '
''' '''
}
} }
} }
} }
stage('12) registry docker image cleanup') { stage('10) Jenkins cleanup') {
steps { steps {
withCredentials([usernamePassword( sh '''
credentialsId: DOCKER_CRED, set -e
usernameVariable: 'DOCKER_USER',
passwordVariable: 'DOCKER_PASS'
)]) {
sh '''
set -e
echo "[1/2] Remove registry old image tag list" if [ "${TARGET}" = "admin" ] || [ "${TARGET}" = "all" ]; then
TAGS_TO_DELETE=$(curl -s -u "$DOCKER_USER:$DOCKER_PASS" https://${REGISTRY_HOST}/v2/${IMAGE_REPO}/tags/list | jq -r '.tags[]' | grep -E '^[0-9]+' | sort -t- -k1,1n | head -n -5) docker rmi ${REGISTRY_HOST}/${ADMIN_IMAGE_REPO}:${IMAGE_TAG} 2>/dev/null || true
fi
echo "[2/2] Remove registry old image sha list and delete registry" if [ "${TARGET}" = "front" ] || [ "${TARGET}" = "all" ]; then
for TAG in $TAGS_TO_DELETE; do docker rmi ${REGISTRY_HOST}/${FRONT_IMAGE_REPO}:${IMAGE_TAG} 2>/dev/null || true
DIGEST=$(curl -s -u "$DOCKER_USER:$DOCKER_PASS" -H "Accept: application/vnd.oci.image.index.v1+json, application/vnd.oci.image.manifest.v1+json, application/vnd.docker.distribution.manifest.list.v2+json, application/vnd.docker.distribution.manifest.v2+json" -D - https://${REGISTRY_HOST}/v2/${IMAGE_REPO}/manifests/$TAG -o /dev/null | grep -i Docker-Content-Digest | awk '{print $2}' | tr -d $'\r') fi
if [ -z "$DIGEST" ]; then docker image prune -f
echo "[SKIP] $TAG digest not found" docker builder prune -f || true
continue '''
fi
echo "[DRY] $TAG -> $DIGEST"
curl -s -u "$DOCKER_USER:$DOCKER_PASS" -X DELETE "https://${REGISTRY_HOST}/v2/${IMAGE_REPO}/manifests/${DIGEST}" -o /dev/null -w "HTTP %{http_code}\n"
done
'''
}
} }
} }
} }
} }