본문 바로가기
개발인생/DevOps Engneer

DevOps ) CI/CD Workflow

by DevOps_901126 2023. 3. 14.
반응형

CI/CD WorkFlow

CI (지속적인 통합)

  1. GitLab에 Source Code Push
  2. Docker 에서 Git Clone 하여 Project 받아오기
  3. Project의 gradlew 에 권한을 부여하고 실행하여 jar 파일 build
  4. (작성된 혹은 작성하여) Dockerfile & jar 파일 기반으로 Image 빌드
  5. Image 를 Repository (Harbor/Docker hub)에 Push
  6. GitLab > Manifest 프로젝트 > deploy.yaml 작성 (image 주소는 내가 push 한 repository 주소)

※ 위 과정을 Jenkins와 GitLab을 연동하여 Jenkins pipeline script로 진행 가능.

CD (지속적인 배포)

  1. ArgoCD에 GitLab > Manifest > deploy.yaml이 위치한 Repository 등록
  2. New App > Deploy.yaml 파일을 Sync 하면
    deploy.yaml에 따라 K8s에 pod , deploy , svc 생성이 됨
  3. 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"
	}
}
 
반응형