Skip to content

Commit

Permalink
[Feat] Spring Boot 채팅 서버 프로젝트 생성 (#13)
Browse files Browse the repository at this point in the history
* [feat] API 서버 프로젝트 생성

* [fix] CICD 테스트를 위한 gradle 수정

* [feat] Dockerfile 생성

* [feat] Jenkinsfile 생성

* [remove] 실수로 push한 demo 프로젝트 삭제

* [feat] chatting 프로젝트 생성

* [fix] gradle 데이터베이스 관련 의존성 주석 처리

* [feat] dockerfile, jenkinsfile 생성

* [feat] findMuse-API 서버 jenkins 트리거 생성

* [fix[ 파일 형식 설정

* [fix] jenkinsfile 브런치 경로 수정

* [fix] jenkinsfile 디렉토리 경로 수정

* [fix] jenkinsfile 디렉토리 경로 수정

* [fix] docker image 이름 소문자로 변경

* [fix] jenkinsfile 수정

* [fix] jenkinsfile docker registry url 수정

* [feat] chatting 서버 CI 구축

* [fix] develop 브런치 rebase

* [remove] 실수로 push한 demo 프로젝트 삭제
  • Loading branch information
ehyeok9 authored Aug 8, 2024
1 parent e4d58f2 commit a5f6377
Show file tree
Hide file tree
Showing 13 changed files with 577 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .idea/checkstyle-idea.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-chatting/.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-chatting/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-chatting/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-chatting-server'
PROJECT_DIRECTORY = 'findMuse-chatting'
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 81:81 --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}"
}
}
}
}
}
41 changes: 41 additions & 0 deletions findMuse-chatting/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
plugins {
id 'java'
id 'org.springframework.boot' version '3.3.2'
id 'io.spring.dependency-management' version '1.1.6'
}

group = 'com.whh'
version = '0.0.1-SNAPSHOT'

java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}

configurations {
compileOnly {
extendsFrom annotationProcessor
}
}

repositories {
mavenCentral()
}

dependencies {
// implementation 'org.springframework.boot:spring-boot-starter-data-jdbc'
// implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
// runtimeOnly 'com.mysql:mysql-connector-j'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}

tasks.named('test') {
useJUnitPlatform()
}
Binary file not shown.
7 changes: 7 additions & 0 deletions findMuse-chatting/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit a5f6377

Please sign in to comment.