Commit e39943b2 authored by JooHan Hong's avatar JooHan Hong

jenkins, source code deploy update4

parent 669d1cea
Pipeline #6090 passed with stages
in 1 minute and 4 seconds
[![logo](https://www.hongsnet.net/images/logo.gif)](https://www.hongsnet.net)
# Jenkins Container Image Deploy Overview
> GitLab Project의 Push Event 발생 시 Jenkins가 이를 배포해주는 과정을 살펴본다.
**!참고** : GitLab Webhook 설정은 생략한다. 만약 확인이 필요하다면, 다음의 링크를 참조한다.
[바로가기](./DEVOPS/WEBHOOK/)
# Jenkins Pipeline Script Configuration
> Jenkins 프로젝트 > 구성 > Pipeline 에서 설정한다.
```
import java.text.SimpleDateFormat
def dateFormat = new SimpleDateFormat("yyyyMMdd")
def date = new Date()
def TODAY = dateFormat.format(date)
pipeline {
agent any
stages {
stage('[TB2-DOCKER] Docker Build') {
steps {
script {
def remote = [:]
remote.name = 'TB2-DOCKER'
remote.host = 'IP'
remote.user = '사용자'
remote.port = 포트
remote.password = '패스워드'
remote.allowAnyHosts = true
sshCommand remote: remote, command: "cd /GIT/docker_hongsnet"
sshCommand remote: remote, command: "cd /GIT/docker_hongsnet; /usr/bin/docker build --rm -t hongsnet ."
}
}
}
stage('[TB2-DOCKER] Harbor Repository Image Push') {
steps {
script {
def remote = [:]
remote.name = 'TB2-DOCKER'
remote.host = 'IP'
remote.user = '사용자'
remote.port = PORT
remote.password = '패스워드'
remote.allowAnyHosts = true
sshCommand remote: remote, command: "/usr/bin/docker login -u admin -p 패스워드 harbor.hongsnet.net"
//sshCommand remote: remote, command: "echo TODAY: ${TODAY}"
//sshCommand remote: remote, command: "echo env.BUILD_ID: ${env.BUILD_ID}"
//sshCommand remote: remote, command: "echo env.JOB_NAME: ${env.JOB_NAME}"
sshCommand remote: remote, command: "/usr/bin/docker tag hongsnet:latest harbor.hongsnet.net/hongsnet/hongsnet:${TODAY}_${BUILD_ID}"
sshCommand remote: remote, command: "/usr/bin/docker push harbor.hongsnet.net/hongsnet/hongsnet:${TODAY}_${BUILD_ID}"
}
}
}
stage('[TB2-DOCKER] K8s Image Rolling Update') {
steps {
script {
def remote = [:]
remote.name = 'TB2-DOCKER'
remote.host = 'IP'
remote.user = '사용자'
remote.port = 포트
remote.password = '패스워드'
remote.allowAnyHosts = true
sshCommand remote: remote, command: "/usr/bin/kubectl set image deployment/hongsnet-web hongsnet-web=harbor.hongsnet.net/hongsnet/hongsnet:${TODAY}_${BUILD_ID}"
sshCommand remote: remote, command: "/usr/bin/kubectl rollout history deployment/hongsnet-web"
sshCommand remote: remote, command: "/usr/bin/kubectl rollout status deployment/hongsnet-web"
VER = sshCommand remote: remote, command: "/usr/bin/cat /DOCKERS/K8S/hongsnet/hongsnet.yaml |grep hongsnet |grep \"image:\" |grep -v \"#\" |awk -F: '{ print \$3}'"
//sshCommand remote: remote, command: "echo ${VER}"
SED = sshCommand remote: remote, command: "/usr/bin/sed 's/${VER}/${TODAY}_${BUILD_ID}/g' -i /DOCKERS/K8S/hongsnet/hongsnet.yaml"
sshCommand remote: remote, command: "/usr/bin/kubectl describe deployments"
}
}
}
}
}
```
# Pipeline Script Description
## Source Code Deploy 시 세 가지 Stage로 진행된다.
- **Docker Build**
- Storage(TB2-DOCKER) 시스템에서 최신(**.gitlab-ci.yaml** 먼저 수행)의 /GIT/docker_hongsnet 경로에서 Container Image를 Build한다.
- **Harbor Repository Image Push**
- Storage 시스템에서 harbor.hongsnet.net, Private Registry에 로그인을 수행
- Build 된 Container Image를 **Tagging** 한다.
- Tagging된 Container Image를 저장소에 **Push** 한다.
- **K8s Image Rolling Update**
- Storage 시스템(**K8s의 Master이기도 함**)에서 업데이트 이미지에 대해 `Rolling Update`를 수행한다.
![container_deploy](./container_deploy.png)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment