[DevOps] Jenkins๋ฅผ ์ด์šฉํ•œ CI/CD Pipeline ๊ตฌ์ถ• - Advenced Jenkins ์‚ฌ์šฉ โ‘  - Pipeline

2022. 9. 15. 06:27ใ†System ์ž‘์—…์‹ค/DevOps

728x90
๋ฐ˜์‘ํ˜•

 

 

์ด ๋‚ด์šฉ์€ ์ธํ”„๋Ÿฐ - Jenkins๋ฅผ ์ด์šฉํ•œ CI/CD Pipeline ๊ตฌ์ถ• ๊ฐ•์˜๋ฅผ ๋ณด๊ณ  ์ •๋ฆฌํ•œ ๋‚ด์šฉ ์ž…๋‹ˆ๋‹ค.


ํ•ด๋‹น ๋‚ด์šฉ์˜ Code ๋‚ด์šฉ์€ ์ด ๊ณณ์—์„œ ํ™•์ธํ•˜์‹ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.






๐Ÿ—‚ ๋ชฉ์ฐจ

โ— [DevOps] Jenkins๋ฅผ ์ด์šฉํ•œ CI/CD Pipeline ๊ตฌ์ถ• - ์ž๋™ํ™” ๋„๊ตฌ์˜ ์‚ฌ์šฉ
โ— [DevOps] Jenkins๋ฅผ ์ด์šฉํ•œ CI/CD Pipeline ๊ตฌ์ถ• - Jenkins + Infrastructure as Code ์™€์˜ ์—ฐ๋™
โ— [DevOps] Jenkins๋ฅผ ์ด์šฉํ•œ CI/CD Pipeline ๊ตฌ์ถ• - Jenkins + Ansible + Kubernetes ์™€์˜ ์—ฐ๋™
โ— [DevOps] Jenkins๋ฅผ ์ด์šฉํ•œ CI/CD Pipeline ๊ตฌ์ถ• - Advenced Jenkins ์‚ฌ์šฉ โ‘  - Pipeline
โ— [DevOps] Jenkins๋ฅผ ์ด์šฉํ•œ CI/CD Pipeline ๊ตฌ์ถ• - Advenced Jenkins ์‚ฌ์šฉ โ‘ก - SonarQube
โ— [DevOps] Jenkins๋ฅผ ์ด์šฉํ•œ CI/CD Pipeline ๊ตฌ์ถ• - Advenced Jenkins ์‚ฌ์šฉ โ‘ข - Multi Nodes
โ— [DevOps] Jenkins๋ฅผ ์ด์šฉํ•œ CI/CD Pipeline ๊ตฌ์ถ• - ์ƒ์šฉ ํด๋ผ์šฐ๋“œ ํ™˜๊ฒฝ์— ๋ฐฐํฌํ•˜๊ธฐ
โ— [DevOps] Jenkins๋ฅผ ์ด์šฉํ•œ CI/CD Pipeline ๊ตฌ์ถ• - ๋ถ€๋ก


 






๐Ÿš€ Jenkins ๊ฐ€์ง€๊ณ  ๋†€๊ธฐ

    ๐Ÿ”ฝ  Pipeline

        ๐Ÿ“ฆ Delivery Pipeline ์‚ฌ์šฉ

 

์ตœ์ดˆ Jenkins์— Plugin์„ ํ•˜๋‚˜ ์„ค์น˜ํ•ด ์ค„๊ฒŒ์š”.


Jenkins ๊ด€๋ฆฌ -> Plugin Manager -> Avaliable(์„ค์น˜ ๊ฐ€๋Šฅ)

 



์œ„์˜ Plugin์„ ์„ค์น˜ํ•ด ์ฃผ์—ˆ์–ด์š”.

 

 

 

ํ•ด๋‹น Plugin์„ ์„ค์น˜ํ•˜๋ฉด ์œ„์™€ ๊ฐ™์ด '์ƒˆ๋กœ์šด ๋ทฐ'๋ผ๋Š” ์นœ๊ตฌ๊ฐ€ ์ƒ๊ฒจ์š”.



์—ฐ์†์ ์ธ ์„ธ ๊ฐœ์˜ Project๊ฐ€ ์žˆ์„ ๋•Œ,

์ฃผ๋‹ˆํ•˜๋ž‘์€ [DevOps] Jenkins๋ฅผ ์ด์šฉํ•œ CI/CD Pipeline ๊ตฌ์ถ• - Jenkins + Ansible + Kubernetes ์™€์˜ ์—ฐ๋™ ์—์„œ '๋นŒ๋“œ ํ›„ ์กฐ์น˜'์— ๋‹ค์Œ Project๋ฅผ ๊ธฐ๋™ํ•˜๊ฒŒ ์„ค์ •ํ•ด ์คŒ์œผ๋กœ ์—ฐ์†์ ์ธ Build๊ฐ€ ์ผ์–ด๋‚˜๊ฒŒ ํ•  ์ˆ˜ ์žˆ๋‹ค๋Š” ๊ฑธ ๊ณต๋ถ€ํ–ˆ์–ด์š”.

์ด๋ฒˆ์—๋Š” ์œ„์™€ ๊ฐ™์ด ์ƒˆ๋กœ์šด ๋ทฐ์—์„œ ์ฒซ๋ฒˆ์งธ Project๋ฅผ Initial Job์— ๋„ฃ์–ด์ฃผ์—ˆ์–ด์š”.



์œ„์™€ ๊ฐ™์ด ์„ค์ •์„ ํ•˜๊ฒŒ ๋˜๋ฉด ์—ฐ์†์ ์œผ๋กœ ์ง„ํ–‰๋˜๋Š”

Project๋“ค์— ์ง„ํ–‰ ์‚ฌํ•ญ์„ ์œ„์™€ ๊ฐ™์ด ์‹œ๊ฐํ™” ํ•˜์—ฌ ๋ณด๋‹ค ํŽธ๋ฆฌํ•˜๊ฒŒ ์ด์šฉํ•  ์ˆ˜ ์žˆ์–ด์š”.



์ตœ์ดˆ ์œ„์™€ ๊ฐ™์ด '์ƒˆ๋กœ์šด ๋ทฐ'์—์„œ ์ด๋ฆ„์„ ์ง€์ •ํ•ด ์ฃผ๊ณ , Delivery Pipeline View๋ฅผ ์„ ํƒํ•ด ์ฃผ์—ˆ์–ด์š”.
๊ทธ๋Ÿฐ ๋’ค Create๋ฅผ ๋ˆŒ๋Ÿฌ์ฃผ์—ˆ์Šต๋‹ˆ๋‹ค.




๋ฐ‘์œผ๋กœ ์Šคํฌ๋กค์„ ๋‚ด๋ฆฌ๋ฉด ์œ„์™€ ๊ฐ™์ด Piplines์— Componentes๊ฐ€ ์žˆ๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.

'์ถ”๊ฐ€' ๋ฒ„ํŠผ์„ ๋ˆŒ๋Ÿฌ์ค๋‹ˆ๋‹ค.



Name์—๋Š” ์ž์œ ๋กญ๊ฒŒ ์ด๋ฆ„์„ ์ง€์ •ํ•ด ์ฃผ๊ณ , Initial Job ์ฆ‰, ์ตœ์ดˆ ์ˆ˜ํ–‰๋  Project๋ฅผ ์„ ํƒ์„ ํ•ด์ฃผ๋ฉด ๋˜์š”.

์ €์žฅ์„ ๋ˆ„๋ฅด๊ณ , ํ•ด๋‹น ์ฐฝ์„ ๋‚˜์™€์ค๋‹ˆ๋‹ค.



๊ทธ๋Ÿผ ์œ„์™€ ๊ฐ™์ด ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.

 

 

 

 

 

        ๐Ÿ“ฆ Delivery Pipeline Script ์‚ฌ์šฉํ•˜๊ธฐ

1. Pipe Line Script ์ž‘์„ฑ ๋ฐฉ์‹ ๋‘๊ฐ€์ง€
     1) Declarative
     2) Scripted (Groovy + DSL)

2. ์ฐจ์ด์ 
    - ์‹œ์ž‘ ์‹œ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ ์œ ๋ฌด
    - ํŠน์ • Stage ์‹คํ–‰ ๊ฐ€๋Šฅ ์—ฌ๋ถ€
    - ์ œ์–ด๋ฌธ
    - Option
    - ๊ฐ๊ฐ์˜ Pipe Line์„ ์ง„ํ–‰ํ•˜๋‹ค๊ฐ€ ์–ด๋–ค ์ž‘์—…์ด ์‹คํŒจํ–ˆ์„ ๋•Œ, Declarative ๋ฐฉ์‹์€ ๊ทธ ๋‹ค์Œ ๋‹จ๊ณ„๋ฅผ ์ง„ํ–‰ํ•˜์ง€ ์•Š๊ณ ,         
       Scripted ๋ฐฉ์‹์€ ๊ทธ ๋‹ค์Œ ๋‹จ๊ณ„๋ฅผ ์ง„ํ–‰.


Declarative ๋ฐฉ์‹

pipeline {
	agent any
    stage {
    	steps('build') {
        	//
        }
        
        steps('test') {
        	//
        }
        
        steps('deploy')	{
        	//
        }
}
๋ฐ˜์‘ํ˜•

1. agnet : Jenkins Server๋ฅผ ๊ธฐ๋™ํ•  ๋•Œ, Master Server์™€ Slave Server๋กœ ๊ตฌ์„ฑํ•  ์ˆ˜ ์žˆ๋Š”๋ฐ, ์–ด๋–ค Server์—
                      Jenkins๋ฅผ ์‹คํ–‰ํ• ์ง€๋ฅผ ์ง€์ •. any๋ฅผ ์ง€์ •ํ–ˆ์„ ๋•Œ๋Š” ๊ตฌ์„ฑ๋œ Server ์ค‘ ์–ด๋–ค Server๋„ ๊ด€๊ณ„ ์—†์œผ๋‹ˆ
                      ์‹คํ–‰ํ•˜๊ฒ ๋‹ค๋Š” ์˜๋ฏธ.

2. Stages : ๊ตฌ์„ฑํ•˜๊ณ ์ž ํ•˜๋Š” ๊ฐ๊ฐ์˜ ๋‹จ๊ณ„์— ๋Œ€ํ•œ ๋‚ด์šฉ์„ ์‚ฝ์ž….

    1)build: build Stage ์„ ์–ธ ๋ฐ ํ•˜์œ„์— build Stage์— ํ•„์š”ํ•œ ์ž‘์—… ๋ช…๋ น์–ด ๋“ฑ ์ž…๋ ฅ.
    2)test: test Stage ์„ ์–ธ ๋ฐ ํ•˜์œ„ test Stage์— ํ•„์š”ํ•œ ์ž‘์—… ๋ช…๋ น์–ด ๋“ฑ ์ž…๋ ฅ.
    3)deploy: deploy Stage ์„ ์–ธ ๋ฐ ํ•˜์œ„ deploy Stage์— ํ•„์š”ํ•œ ์ž‘์—… ๋ช…๋ น์–ด ๋“ฑ ์ž…๋ ฅ.

Jenkinsfile


์œ„์™€ ๊ฐ™์ด Jenkinsfile์„ ๋งŒ๋“ค์—ˆ๊ณ , ๊ฐ„๋‹จํ•˜๊ฒŒ ๊ฐ ๋‹จ๊ณ„๋ณ„๋กœ ๋ฌธ์ž์—ด์„ ์ถœ๋ ฅํ•˜๋„๋ก ๋งŒ๋“ค์–ด ์ฃผ์—ˆ์–ด์š”.


 






git์— Push๋ฅผ ํ•˜๋Š” ์ˆœ๊ฐ„ Jenkins๋ฅผ ์ž‘๋™ํ•˜๊ฒŒ ๋˜๊ณ , ์œ„์™€ ๊ฐ™์ด ์ž‘์—…์ด ์„ฑ๊ณตํ•œ ๊ฒƒ์„ ํ™•์ธ ํ•  ์ˆ˜ ์žˆ์–ด์š”.

 

 

 

 


3. post : stages ๋‹จ๊ณ„ ์ฆ‰, Build ์ž‘์—…์„ ๋งˆ์ณค์„ ๋•Œ, ๊ทธ ์ดํ›„ ์ž‘์—…์— ๋Œ€ํ•ด ๋ช…์‹œ

     1) always : ์ž‘์—… ์„ฑ๊ณต ์—ฌ๋ถ€์™€ ๊ด€๊ณ„ ์—†์ด ํ•ด๋‹น ๋‚ด์šฉ ์ž‘์—… ์‹คํ–‰.
     2) success : ์ž‘์—… ์„ฑ๊ณต ์‹œ ํ•ด๋‹น ๋‚ด์šฉ ์ž‘์—… ์‹คํ–‰.
     3) failure : ์ž‘์—… ์‹คํŒจ ์‹œ ํ•ด๋‹น ๋‚ด์šฉ ์ž‘์—… ์‹คํ–‰.
     4) unstable : ๋ถ€๋ถ„ ์‹คํŒจ ์‹œ ํ•ด๋‹น ๋‚ด์šฉ ์ž‘์—… ์‹คํ–‰.
     5) changed : ๋ณ€๊ฒฝ๋œ ์‚ฌํ•ญ์ด ์žˆ์„ ์‹œ ํ•ด๋‹น ๋‚ด์šฉ ์ž‘์—… ์‹คํ–‰.

Jenkinsfile






Deploy ์ž‘์—…์ด ๋๋‚˜๊ณ , Post์— ๋ช…์‹œํ–ˆ๋˜ ์ž‘์—…์ด ์‹คํ–‰๋œ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.




 

Scripted ๋ฐฉ์‹

node {
	stage('build') {
    	//
    }
    
    stage('test') {
    	//
    }
    
    stage('deploy') {
    	//
    }
}



 

 

    ๐Ÿ”ฝ  Pipeline Sysnax

        ๐Ÿ“ฆ ์ž๋™ ์ƒ์„ฑ

http://{jenkins Server ์ฃผ์†Œ:port}/pipeline-syntax/


์œ„์˜ ์ฃผ์†Œ๋กœ ๋“ค์–ด๊ฐ€๋ฉด pipline ๋ฌธ๋ฒ•์„ ํŽธ๋ฆฌํ•˜๊ฒŒ ๋งŒ๋“ค์–ด์ค„ ์ˆ˜ ์žˆ๋Š” ๋„๊ตฌ๋กœ ์ด๋™ํ•  ์ˆ˜ ์žˆ์–ด์š”.


728x90


์ฃผ๋‹ˆํ•˜๋ž‘์€ Slack์— ์•Œ๋ฆผ์„ ๋ณด๋‚ผ ์ˆ˜ ์žˆ๋Š” ๋ฌธ๋ฒ•์„ Test๋กœ ๊ตฌ์„ฑํ•ด ๋ณด์•˜์–ด์š”.



์ž‘์„ฑ์ด ์™„๋ฃŒ๋œ ๋’ค ํŒŒ์ดํ”„๋ผ์ธ ์Šคํฌ๋ฆฝํŠธ ์ƒ์„ฑ์„ ๋ˆ„๋ฅด๋ฉด ์œ„์™€ ๊ฐ™์ด ์ž๋™์œผ๋กœ Script ๋ฌธ์ด ๋‚˜์˜ค๊ฒŒ ๋˜์š”.






์ด๋ฒˆ์—๋Š” Git Repository์— File๋“ค์„ ์ด์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด์„œ ๊ณต๋ถ€ํ•ด ๋ณด์•˜์–ด์š”.

ํ•ด๋‹น Repository๋Š” Public์ด๊ธฐ ๋•Œ๋ฌธ์— Credential์— ๋ณ„๋„์— ์„ค์ •์ด ํ•„์š”์—†์ง€๋งŒ, Repository๊ฐ€ Private์ด๋ผ๋ฉด ํ•ด๋‹น Repository ๊ณ„์ •์— ๊ฐ’์„ ์ •์˜ํ•ด์ฃผ์–ด์•ผ ํ•ด์š”.



Jenkins์— ์ƒˆ๋กœ์šด Item์„ Pipeline์œผ๋กœ ๋งŒ๋“ค์–ด์ฃผ์—ˆ๊ณ , ์œ„์™€ ๊ฐ™์ด Script๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์—ˆ์–ด์š”.

pipeline {
    agent any
    stages {
        stage('Git clone') {
            steps {
                git 'https://github.com/joneconsulting/jenkins_pipeline_script';
            }
        }

        stage('Compile') {
            steps {
                echo "Compiled successfully!";
                sh './build.sh'
            }
        }

        stage('JUnit') {
            steps {
                echo "JUnit passed successfully!";
                sh './unit.sh'
            }
        }

        stage('Code Analysis') {
            steps {
                echo "Code Analysis completed successfully!";
                sh './quality.sh'
            }
        }

        stage('Deploy') {
            steps {
                echo "Deployed successfully!";
                sh './deploy.sh'
            }
        }
    }
}

 


์ตœ์ข…์ ์œผ๋กœ ์ฃผ๋‹ˆํ•˜๋ž‘์ด ์ž…๋ ฅํ•œ Script ๋ฌธ์ด์—์š”.

์ €์žฅ์„ ํ•˜๊ณ , Build๋ฅผ ํ•ด ๋ณด์•˜์–ด์š”.



์œ„์™€ ๊ฐ™์ด Build๊ฐ€ ์ง„ํ–‰๋˜๊ณ  ์žˆ์–ด์š”.



Build๊ฐ€ ๋ชจ๋‘ ๋๋‚ฌ์–ด์š”!


 

pipeline {
    agent any
    stages {
        stage('Git clone') {
            steps {
                git 'https://github.com/joneconsulting/jenkins_pipeline_script';
            }
        }

        stage('Compile') {
            steps {
                echo "Compiled successfully!";
                sh './build.sh'
            }
        }

        stage('JUnit') {
            steps {
                echo "JUnit passed successfully!";
                sh './unit.sh'
            }
        }

        stage('Code Analysis') {
            steps {
                echo "Code Analysis completed successfully!";
                sh './quality.sh'
            }
        }

        stage('Deploy') {
            steps {
                echo "Deployed successfully!";
                sh './deploy.sh'
            }
        }
    }
    
    post {
      always {
        echo "This will always run"
      }
      success {
        echo "This will run when the run finished successfully"
      }
      failure {
        echo "This will run if failed"
      }
      unstable {
        echo "This will run when the run was marked as unstable"
      }
      changed {
        echo "This will run when the state of the pipeline has changed"
      }
    }
}



์ด๋ฒˆ์—๋Š” Deploy ์ž‘์—…์ด ๋ชจ๋‘ ๋๋‚˜๊ณ , ์ž‘์—… ์ƒํƒœ ์—ฌ๋ถ€์— ๋”ฐ๋ผ ์–ด๋–ค ์ž‘์—…์„ ์ถ”๊ฐ€์ ์œผ๋กœ ์ง„ํ–‰ํ•  ๊ฒƒ์ธ์ง€์— ๋Œ€ํ•œ
Script๋ฌธ์„ ์ถ”๊ฐ€ํ•ด ์ฃผ์—ˆ์–ด์š”.

์ €์žฅ์„ ํ•˜๊ณ , ๋‹ค์‹œ Build ์ž‘์—…์„ ์‹œ๋„ํ•ด ๋ณด์•˜์–ด์š”.


Post Actions๋ผ๋Š” ๋‹จ๊ณ„๊ฐ€ ์ถ”๊ฐ€๋˜์–ด ์ž‘์—…์ด ์ง„ํ–‰๋œ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.


 

 

 

 

 

 

 

 

 

 

 

 

    ๐Ÿ”ฝ  Gradle build

 

pipeline {
    agent any

    tools {
        gradle 'gradle'
    }

    stages {

        stage('Build') {
            steps {
                echo "Build Started";

                try{
                sh "gradle clen build -x test -b build.gradle"
                } catch (e) {
                    sh 'echo Build Fail'
                }
                
                echo "Build End";
            }
        }

        stage('JUnit Test') {
            steps {
                echo "JUnit Started";
                
                try {
                    junit '**/build/test-results/test/*.xml'
                } catch (e) {
                    sh 'echo Test Fail'
                }
                
                echo "Test End"
            }
        }
    }

    post {
        always {
            echo 'This will always run'
        }

        success {
            echo 'This will run when the run finished successfully'
        }

        failure {
            echo 'This will run if failed'
        }

        unstable {
            echo 'This will run when the run was marked as unstable'
        }

        changed {
            echo 'This will run when the state of the pipeline has changed'
        }
    }
}

 


์ด๋ฒˆ์—๋Š” Gradle Build๋ฅผ ์œ„ํ•ด ์œ„์™€ ๊ฐ™์ด Jenkinsfile์„ ์ˆ˜์ •ํ•ด ์ฃผ์—ˆ์–ด์š”.

 



 

 

    ๐Ÿ”ฝ  Jenkins Pipeline ๊ฐ€์ง€๊ณ  ๋†€๊ธฐ

        ๐Ÿ“ฆ Maven build pipeline

์ด๋ฒˆ์—๋Š” Maven build๋ฅผ Jenkins Pipeline์— ์ถ”๊ฐ€ํ•˜๋ฉด์„œ ๋†€์•„๋ณผ๊ฒŒ์š”.


Jenkins์—์„œ ์œ„์™€ ๊ฐ™์ด Item์„ ๋งŒ๋“ค์–ด ์ค„๊ฑฐ์—์š”.



 

pipeline {
    agent any
    tools {
        maven 'Maven3.8.5'
    }
    
    stages {
        stage('Git Clone') {
            steps {
                git 'https://github.com/junyharang-coding-study/JunyHarang-Maven-Test-Project'
            }
        }
        
        stage('Maven Build') {
            steps {
                sh '''
                    echo build start
                    mvn clean compile package -Dskiptests=true
                '''
            }
        }
    }
}



์œ„์™€ ๊ฐ™์ด Script ๋ฌธ์„ ๋„ฃ์–ด ์ฃผ์—ˆ์–ด์š”.

์ฐธ๊ณ ๋กœ Script ๋ฌธ ์•ˆ์— tools์— Build Tool ์ •๋ณด๋ฅผ ๋„ฃ์–ด์ค˜์•ผ ํ•˜๋Š”๋ฐ, ํ˜„์žฌ maven Tool์„ ์ด์šฉํ•ด ๋ณผ ๊ฒƒ์ด๊ณ ,
Maven์˜ Version์„ ์•„๋ž˜์™€ ๊ฐ™์ด ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.

Maven Build Tool์„ ์ด์šฉํ•ด์„œ ์ด ์ „ Build ์ž‘์—…์— ๋Œ€ํ•œ ๊ฒฐ๊ณผ๋ฌผ์„ ์‚ญ์ œ(clean)ํ•˜๊ณ , compile ํ•˜๊ณ , packagingํ•œ ๋’ค Unit Test๋Š” ์ง„ํ–‰ํ•˜์ง€ ์•Š๊ธฐ ์œ„ํ•ด -Dskiptests=true Option์„ ์ฃผ์—ˆ์–ด์š”.

Jenkins ๊ด€๋ฆฌ -> Global Tool Configuration -> Maven


์ค‘์š”ํ•œ ๊ฒƒ์€ Maven์˜ Name (Maven3.8.5)์™€ Script ๋ฌธ์— tools์— Maven ์ •๋ณด๋ฅผ ์ ์„ ๋•Œ,
๋‘˜์ด ๋˜‘๊ฐ™์ด ์ ์–ด์ค˜์•ผ ํ•œ๋‹ค๋Š” ์ ์ด์—์š”.



์ €์žฅํ•˜๊ณ , Build๋ฅผ ์ง„ํ–‰ํ•ด ๋ณผ๊ฒŒ์š”.




Build ์ž‘์—…์ด ์ •์ƒ์ ์œผ๋กœ ๋๋‚ฌ์–ด์š”.









        ๐Ÿ“ฆ Tomcat 9.0์— ๋ฐฐํฌํ•˜๊ธฐ


Script๋ฌธ์„ ์ƒ์„ฑํ•˜๊ธฐ ์ „์— Script ์ž๋™ ์ƒ์„ฑ ๋„์›€์„ ๋ฐ›์•„ ์œ„์™€ ๊ฐ™์ด Tomcat์— Deployํ•  ๋•Œ
Script๋ฌธ์„ ๋งŒ๋“ค๊ฒŒ ํ•ด ์ฃผ์—ˆ์–ด์š”.

 



JunyHarang-Secone-Pipeline


์œ„์—์„œ ๋งŒ๋“ค์—ˆ๋˜ Pipeline Projce ๊ตฌ์„ฑ์—์„œ 23๋ฒˆ์งธ ์ค„๊ณผ ๊ฐ™์ด Deploy ๊ด€๋ จ Script ๋ฌธ์„ ์ถ”๊ฐ€ํ•ด ์ฃผ์—ˆ์–ด์š”.

๊ทธ๋Ÿฐ ๋’ค ์ €์žฅํ•œ ๋’ค ๋‚˜์™”์–ด์š”.




Tomcat ์ดˆ๊ธฐ Page์—์„œ Manager App์„ ๋ˆŒ๋Ÿฌ ์ฃผ์—ˆ์–ด์š”.



๊ทธ๋ฆฌ๊ณ , ๊ด€๋ฆฌ์ž ๊ณ„์ •์„ ์ž…๋ ฅ ํ•ด ์ฃผ์—ˆ์–ด์š”.

์ด ๋ถ€๋ถ„์— ๋Œ€ํ•ด์„œ๋Š” ์ด ๊ณณ์— ์ค€๋น„๋ฅผ ํ•ด ๋‘์—ˆ์–ด์š”.




์ด ์ „์— Test ํ•ด ๋ณด์•˜๋˜ /hello-world๊ฐ€ ๋ณด์ด๊ณ  ์žˆ์–ด์š”.

์ด๊ฑด ์‚ญ์ œ๋ฅผ ํ•ด ์ฃผ๊ณ  ์ง„ํ–‰ํ•ด ๋ณผ๊ฒŒ์š”.




์šฐ์ธก ๋์— '๋ฐฐ์น˜๋œ ๊ฒƒ์„ ์ œ๊ฑฐ'๋ฅผ ๋ˆŒ๋Ÿฌ์ฃผ๋ฉด ๋˜์š”.



์ •์ƒ์ ์œผ๋กœ ์‚ญ์ œ๊ฐ€ ๋œ ๊ฒƒ์„ ํ™•์ธํ•˜์˜€์–ด์š”.


์ด์ œ Jenkins์—์„œ Build๋ฅผ ์ง„ํ–‰ํ•ด ๋ณผ ๊ฒƒ์ด์—์š”.



deploy ๋‹จ๊ณ„๊ฐ€ ์ถ”๊ฐ€ ๋˜์—ˆ๊ณ , ์ •์ƒ ์ง„ํ–‰๋œ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.







        ๐Ÿ“ฆ Docker Container์— ๋ฐฐํฌํ•˜๊ธฐ

 


์ตœ์ดˆ Script๋ฅผ ๋งŒ๋“ค๊ธฐ ์œ„ํ•ด ์œ„์™€ ๊ฐ™์ด ์ž‘์„ฑ์„ ํ•ด ์ฃผ์—ˆ์–ด์š”.

SSH Server๋Š” ์ด ์ „์— ์ž‘์—…ํ–ˆ๋˜ Docker๋ฅผ ์„ค์น˜ํ•œ Container์—์š”.



Generate๋ฅผ ํ•ด์ฃผ๋‹ˆ ์—„์ฒญ ๊ธด Script๋ฌธ์ด ๋‚˜์™”์–ด์š”.




์œ„์—์„œ ๋งŒ๋“ค์—ˆ๋˜ Pipeline Projce ๊ตฌ์„ฑ์—์„œ 29๋ฒˆ์งธ ์ค„๊ณผ ๊ฐ™์ด Script๋ฌธ์„ ์ถ”๊ฐ€ํ•ด ์ฃผ์—ˆ์–ด์š”.

๊ทธ๋ฆฌ๊ณ , ์ €์žฅ์„ ํ•˜๊ณ  ๋‚˜์™€ ์ฃผ์—ˆ์–ด์š”.


์ด์ œ Build๋ฅผ ์ง„ํ–‰ํ•ด ๋ณผ๊ฒŒ์š”.



Build๊ฐ€ ์‹คํŒจํ•˜์˜€์–ด์š”!




docker images


SSH๋กœ ์—ฐ๊ฒฐํ•ด ์ฃผ์—ˆ๋˜ Docker Container์—์„œ Docker Image๋ฅผ ํ™•์ธํ•ด ๋ณด๋‹ˆ ์œ„์™€ ๊ฐ™์ด
<NONE> ์ด๋ผ๊ณ  ๋‚˜์˜ค๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.


์ด๋ ‡๊ฒŒ ๋œ ์ด์œ ๋Š” Image๋ฅผ ์ƒ์„ฑํ•˜๋Š” ๊ณผ์ •์—์„œ war File์ด ๋ณต์‚ฌ๊ฐ€ ๋˜๊ธฐ๋Š” ํ•˜์˜€์œผ๋‚˜, ํ•ด๋‹น File์ด Image๋ฅผ ์ƒ์„ฑํ•˜๋Š” ๊ณผ์ •๊นŒ์ง€ ์ด์–ด์ง€์ง€ ๋ชปํ•˜๊ณ  ์ค‘๋‹จ ๋˜์—ˆ๊ธฐ ๋•Œ๋ฌธ์ด์—์š”.


์ผ๋‹จ hello-world.war File์„ ์‚ญ์ œํ•ด ์ฃผ๋„๋ก ํ• ๊ฒŒ์š”.

rm -rf {์‚ญ์ œํ•  File ์ด๋ฆ„}

 


๋ฌธ์ œ๋Š” Docker Container์— ์žˆ๋Š” Dockerfile์ด ๋ฌธ์ œ์˜€์–ด์š”.

์šฐ๋ฆฌ๋Š” hello-world.war๋ฅผ ์ „๋‹ฌํ•˜๋Š”๋ฐ, COPY ์ ˆ์— ๋ณด๋ฉด ./webapp.war๋ผ๊ณ  ์ ํžŒ ๊ฒƒ์ด์—์š”.



์œ„์™€ ๊ฐ™์ด ๋ณ€๊ฒฝํ•ด ์ฃผ๊ณ , ๋‹ค์‹œ Build๋ฅผ ์ง„ํ–‰ํ•ด ๋ณผ๊ฒŒ์š”.



์ž‘์—…์ด ์ •์ƒ์ ์œผ๋กœ ์™„๋ฃŒ ๋˜์—ˆ์–ด์š”!



docker images


SSH๋กœ ์—ฐ๊ฒฐํ–ˆ๋˜ Docker Container์—์„œ Docker Image๋ฅผ ํ™•์ธํ•ด๋ณด๋‹ˆ
์ •์ƒ์ ์œผ๋กœ Image๊ฐ€ ๋งŒ๋“ค์–ด์ง„ ๊ฒƒ์„ ํ™•์ธ ํ•  ์ˆ˜ ์žˆ์–ด์š”.





 

 

 

 

 

728x90
๋ฐ˜์‘ํ˜•