Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
joohanhong
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
JooHan Hong
joohanhong
Commits
e39943b2
Commit
e39943b2
authored
Aug 08, 2022
by
JooHan Hong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
jenkins, source code deploy update4
parent
669d1cea
Pipeline
#6090
passed with stages
in 1 minute and 4 seconds
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
109 additions
and
0 deletions
+109
-0
README.md
DEVOPS/K8S_BUILD/README.md
+109
-0
container_deploy.png
DEVOPS/K8S_BUILD/container_deploy.png
+0
-0
No files found.
DEVOPS/K8S_BUILD/README.md
0 → 100644
View file @
e39943b2
[
![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
)
DEVOPS/K8S_BUILD/container_deploy.png
0 → 100644
View file @
e39943b2
64.1 KB
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment