Commit 0c258506 authored by JooHan Hong's avatar JooHan Hong

k8s rolling update pipeline script 변경

parent 3a8940b9
Pipeline #6096 passed with stages
in 1 minute and 21 seconds
...@@ -18,71 +18,44 @@ import java.text.SimpleDateFormat ...@@ -18,71 +18,44 @@ import java.text.SimpleDateFormat
def dateFormat = new SimpleDateFormat("yyyyMMdd") def dateFormat = new SimpleDateFormat("yyyyMMdd")
def date = new Date() def date = new Date()
def TODAY = dateFormat.format(date)
pipeline { pipeline {
agent any agent any
stages { environment {
TODAY = dateFormat.format(date)
}
stage('[TB2-DOCKER] Docker Build') { stages {
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') { stage('Git Clone') {
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" steps {
//sshCommand remote: remote, command: "echo TODAY: ${TODAY}" //echo 'Clone'
//sshCommand remote: remote, command: "echo env.BUILD_ID: ${env.BUILD_ID}" sh 'mkdir -p docker_hongsnet'
//sshCommand remote: remote, command: "echo env.JOB_NAME: ${env.JOB_NAME}" dir("docker_hongsnet")
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}" git branch: 'master', credentialsId: 'juhanida21', url: 'https://gitlab.hongsnet.net/joohan.hong/docker_hongsnet.git'
} }
} }
} }
stage('[TB2-DOCKER] K8s Image Rolling Update') { stage('Container Image Build and Push') {
steps { steps {
script { //sh 'echo ${TODAY}'
def remote = [:] sh 'sudo /usr/bin/docker login -u admin -p 패스워드 harbor.hongsnet.net'
remote.name = 'TB2-DOCKER' sh 'cd docker_test; sudo /usr/bin/docker build --rm -t hongsnet .'
remote.host = 'IP' sh 'sudo /usr/bin/docker tag hongsnet:latest harbor.hongsnet.net/hongsnet/hongsnet:${TODAY}_${BUILD_ID}'
remote.user = '사용자' sh 'sudo /usr/bin/docker push harbor.hongsnet.net/hongsnet/hongsnet:${TODAY}_${BUILD_ID}'
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}" stage('K8s Rolling Update') {
sshCommand remote: remote, command: "/usr/bin/kubectl rollout history deployment/hongsnet-web" steps {
sshCommand remote: remote, command: "/usr/bin/kubectl rollout status deployment/hongsnet-web" sh 'curl -sS http://K8S-MASTER:15999/api/rollup?deployment=hongsnet-web\'&\'cimage=harbor.hongsnet.net/hongsnet/hongsnet:${TODAY}_${BUILD_ID}'
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"
}
}
} }
} }
...@@ -95,17 +68,15 @@ pipeline { ...@@ -95,17 +68,15 @@ pipeline {
## Source Code Deploy 시 세 가지 Stage로 진행된다. ## Source Code Deploy 시 세 가지 Stage로 진행된다.
- **Docker Build** - **Git Clone**
- Storage(TB2-DOCKER) 시스템에서 최신(**.gitlab-ci.yaml** 먼저 수행)의 /GIT/docker_hongsnet 경로에서 Container Image를 Build한다. - **Jenkins** 시스템에서 최신의 내용을 /GIT/docker_hongsnet 경로로 Pull 한 후 Container Image를 Build한다.
- **Harbor Repository Image Push** - **Container Image Build and Push**
- Storage 시스템에서 harbor.hongsnet.net, Private Registry에 로그인을 수행 - **Jenkins** 시스템에서 harbor.hongsnet.net, Private Registry에 로그인을 수행
- Build 된 Container Image를 **Tagging** 한다. - Build 된 Container Image를 **Tagging** 한다.
- Tagging된 Container Image를 저장소에 **Push** 한다. - Tagging된 Container Image를 저장소에 **Push** 한다.
- **K8s Image Rolling Update** - **K8s Rolling Update**
- Storage 시스템(**K8s의 Master이기도 함**)에서 업데이트 이미지에 대해 `Rolling Update`를 수행한다. - **Jenkins** 시스템에서 업데이트 이미지에 대해 `Rolling Update`를 수행한다.
- **K8S-MASTER:15999**는 직접 Golang을 사용한 RESTful API 이다.
**!참고** : 현재 **kubectl** 명령을 사용하여 관리되기 때문에 yaml 파일에 sed 명령을 통해 Container Image의 최신화를 수행
![container_deploy](./container_deploy.png) ![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