-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
799 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
HELP.md | ||
.gradle | ||
build/ | ||
!gradle/wrapper/gradle-wrapper.jar | ||
!**/src/main/**/build/ | ||
!**/src/test/**/build/ | ||
|
||
### STS ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
bin/ | ||
!**/src/main/**/bin/ | ||
!**/src/test/**/bin/ | ||
|
||
### IntelliJ IDEA ### | ||
.idea | ||
*.iws | ||
*.iml | ||
*.ipr | ||
out/ | ||
!**/src/main/**/out/ | ||
!**/src/test/**/out/ | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ | ||
|
||
### VS Code ### | ||
.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
FROM openjdk:17 | ||
|
||
ENV TZ="Asia/Seoul" | ||
|
||
ARG JAR_FILE=build/libs/*.jar | ||
|
||
COPY ${JAR_FILE} app.jar | ||
|
||
ENTRYPOINT ["java","-jar","/app.jar"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
pipeline { | ||
agent any | ||
|
||
environment { | ||
REPOSITORY_NAME = 'Backend' | ||
GITHUB_CREDENTIALS = credentials('Github-Credential') | ||
DOCKER_CREDENTIALS = credentials('Docker-Credential') | ||
IMAGE_NAME = 'findmuse-api-server' | ||
PROJECT_DIRECTORY = 'finMuse-API' | ||
DOCKER_REGISTRY_URL = "${DOCKER_CREDENTIALS_USR}/${IMAGE_NAME}" | ||
} | ||
|
||
stages { | ||
stage('Checkout') { | ||
steps { | ||
git branch: 'develop', url: "https://github.com/WooHyeopHa/${env.REPOSITORY_NAME}.git", credentialsId: 'Github-Credential' | ||
} | ||
} | ||
|
||
stage('Build JAR') { | ||
steps { | ||
dir("${env.PROJECT_DIRECTORY}") { | ||
sh './gradlew clean build' | ||
} | ||
} | ||
} | ||
|
||
stage('Build Docker Image') { | ||
steps { | ||
dir("${env.PROJECT_DIRECTORY}") { | ||
script { | ||
def imageTag = "${env.IMAGE_NAME}:${env.BUILD_NUMBER}" | ||
docker.build(imageTag) | ||
} | ||
} | ||
} | ||
} | ||
|
||
stage('Push Docker Image') { | ||
steps { | ||
withCredentials([usernamePassword(credentialsId: 'Docker-Credential', usernameVariable: 'DOCKER_USERNAME', passwordVariable: 'DOCKER_PASSWORD')]) { | ||
script { | ||
def imageTag = "${env.IMAGE_NAME}:${env.BUILD_NUMBER}" | ||
sh "echo ${DOCKER_PASSWORD} | docker login -u ${DOCKER_USERNAME} --password-stdin" | ||
sh "docker tag ${imageTag} ${env.DOCKER_REGISTRY_URL}:${env.BUILD_NUMBER}" | ||
sh "docker push ${env.DOCKER_REGISTRY_URL}:${env.BUILD_NUMBER}" | ||
} | ||
} | ||
} | ||
} | ||
|
||
stage('Cleanup Old Containers') { | ||
steps { | ||
script { | ||
sh """ | ||
docker ps -q -f name=${env.IMAGE_NAME} | xargs -r docker stop | ||
docker ps -a -q -f name=${env.IMAGE_NAME} | xargs -r docker rm | ||
""" | ||
} | ||
} | ||
} | ||
|
||
stage('Deploy Docker Container') { | ||
steps { | ||
script { | ||
sh """ | ||
docker run -d -p 80:80 --name ${env.IMAGE_NAME} ${env.DOCKER_REGISTRY_URL}:${env.BUILD_NUMBER} | ||
""" | ||
} | ||
} | ||
} | ||
} | ||
|
||
post { | ||
success { | ||
echo '빌드 및 배포가 성공적으로 완료되었습니다!' | ||
} | ||
failure { | ||
echo '빌드 또는 배포에 실패했습니다.' | ||
} | ||
cleanup { | ||
script { | ||
def previousBuildNumber = "${env.BUILD_NUMBER.toInteger() - 1}" | ||
def previousTag = "${env.IMAGE_NAME}:${previousBuildNumber}" | ||
def registryTag = "${env.DOCKER_REGISTRY_URL}:${previousBuildNumber}" | ||
|
||
def tagExists = sh(script: "docker images -q ${previousTag}", returnStatus: true) == 0 | ||
|
||
if (tagExists) { | ||
sh "docker rmi ${previousTag} || true" | ||
sh "docker rmi ${registryTag} || true" | ||
echo "이전 버전의 도커 이미지가 삭제되었습니다: ${previousTag}" | ||
} else { | ||
echo "이전 버전의 도커 이미지가 발견되지 않았습니다: ${previousTag}" | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.