반응형
CI/CD WorkFlow
CI (지속적인 통합)
- GitLab에 Source Code Push
- Docker 에서 Git Clone 하여 Project 받아오기
- Project의 gradlew 에 권한을 부여하고 실행하여 jar 파일 build
- (작성된 혹은 작성하여) Dockerfile & jar 파일 기반으로 Image 빌드
- Image 를 Repository (Harbor/Docker hub)에 Push
- GitLab > Manifest 프로젝트 > deploy.yaml 작성 (image 주소는 내가 push 한 repository 주소)
※ 위 과정을 Jenkins와 GitLab을 연동하여 Jenkins pipeline script로 진행 가능.
CD (지속적인 배포)
- ArgoCD에 GitLab > Manifest > deploy.yaml이 위치한 Repository 등록
- New App > Deploy.yaml 파일을 Sync 하면
deploy.yaml에 따라 K8s에 pod , deploy , svc 생성이 됨 - Nodeport에 접근하여 프로젝트 배포 확인
## Jenkins Pipeline example) Gradle 기준
node {
// Check out
stage('Git Checkout') {
echo '>>>>>STAGE: CHECKOUT'
sh "rm -rf ./* ./.git*"
git branch: 'main', credentialsId: 'yj0326', url: 'https://gitlab.com/msa3040311/hello1.git'
}
// Build
stage('GRADLE BUILD') {
echo '>>>>>빌드'
sh "chmod +x ./gradlew"
sh "./gradlew build"
}
// plain.jar delete & .jar rename
stage('Archive Setting'){
echo 'STAGE: ARCHIVE SETTING - GRADLE'
// build file counting
def fileCount = sh(script:"find ./build/libs -type f | wc -l", returnStdout: true);
echo ">>>>> fileCount = ${fileCount}"
if(fileCount.toInteger() > 1){
// get plain jar
def plainFile = sh(script:"""find ./build/libs -regextype egrep -regex '.*plain.(war|jar)\$'""", returnStdout: true).trim();
echo ">>>>> PLAIN FILE DELETE = ${plainFile}"
// plain jar delete
sh """find ./build/libs -regextype egrep -regex '.*plain.(war|jar)\$' -exec rm {} \\;"""
}
def archiveFile = sh(script:"find ./build/libs -type f", returnStdout: true).trim();
echo ">>>>> ARCHIVE FILE = ${archiveFile}"
sh "cp ${archiveFile} ./hello1.jar"
}
}
반응형
'개발인생 > DevOps Engneer' 카테고리의 다른 글
DevOps) CI with Jenkins (0) | 2023.03.15 |
---|---|
DevOps) CI with Docker (Legacy 방식) (0) | 2023.03.15 |
DevOps) GitLab + ArgoCD로 kubernetes project 배포 (0) | 2023.03.09 |
DevOps) Docker로 로컬 프로젝트를 Docker Hub에 이미지로 build하는 방법 (0) | 2023.03.09 |
install) kubernetes + ArgoCd (yaml 파일로 배포) (0) | 2023.02.14 |