Skip to content

Commit

Permalink
[fix] 폴더 구조 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
ehyeok9 committed Aug 8, 2024
1 parent ad28048 commit b0d4e89
Show file tree
Hide file tree
Showing 13 changed files with 799 additions and 0 deletions.
233 changes: 233 additions & 0 deletions finMuse-API/.idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions findMuse-API/.gitignore
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/
9 changes: 9 additions & 0 deletions findMuse-API/Dockerfile
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"]
99 changes: 99 additions & 0 deletions findMuse-API/Jenkinsfile
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}"
}
}
}
}
}
Loading

0 comments on commit b0d4e89

Please sign in to comment.