forked from tmax-cloud/hypercloud-console4.2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
132 lines (119 loc) · 5.51 KB
/
Jenkinsfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
//input 'Is it OK? \n MAJOR_VERSION=4, MINOR_VERSION=1, PATCH_VERSION=${env.BUILD_NUMBER}, HOTFIX_VERSION=3'
// Script Pipeline
// def CHOICE = input message: 'choice your cloud',
// parameters: [choice(choices: ['kubernetes','196'],
// description: 'need to specify where deploy console app', name: 'Cloud option')]
// def CHOICE = "kubernetes"
// def MAJOR_VERSION = "4"
// def MINOR_VERSION = "1"
def CHOICE = "${params.choice}"
def MAJOR_VERSION = "${params.major_version}"
def MINOR_VERSION = "${params.minor_version}"
def PATCH_VERSION = "${params.patch_version}"
def PRE_VERSION = (("${params.patch_version}" as int) - 1).toString()
def HOTFIX_VERSION = "${params.hotfix_version}"
def DOCKER_REGISTRY = "tmaxcloudck"
def PRODUCT = "hypercloud-console"
def VER = "${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}.${HOTFIX_VERSION}"
def PRE_VER = "${MAJOR_VERSION}.${MINOR_VERSION}.${PRE_VERSION}.${HOTFIX_VERSION}"
// def VER = "1.1.38.1"
def REALM = "${params.realm}"
def KEYCLOAK = "${params.keycloak}"
def CLIENTID = "${params.clientid}"
def BRANCH = "hc-release"
// k8s environment
def NAME_NS = "console-system"
def NODE_PORT = "31304"
def HDC_FLAG = "false"
def PORTAL = "false"
podTemplate(cloud: "${CHOICE}", containers: [
// podTemplate(containers: [
// // podTemplate(cloud: 'kubernetes', containers: [
containerTemplate(name: 'docker', image: 'docker', command: 'cat', ttyEnabled: true),
containerTemplate(name: 'kubectl', image: 'lachlanevenson/k8s-kubectl:v1.18.3', command: 'cat', ttyEnabled: true),
// containerTemplate(name: 'ssh-client', image: 'kroniak/ssh-client', command: 'cat', ttyEnabled: true),
],
volumes: [
hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock')
]) {
node(POD_LABEL) {
def myRepo = checkout scm
def gitBranch = myRepo.GIT_BRANCH
stage('Input'){
sh "echo 'INSTALL TO ${CHOICE}'"
sh "echo 'PRODUCT=${PRODUCT}'"
sh "echo 'VERSION=${VER}'"
sh "echo 'PREVIOUS_VERSION=${PRE_VER}'"
}
stage('Docker Build'){
container('docker'){
withCredentials([usernamePassword(
credentialsId: 'tmaxcloudck',
usernameVariable: 'DOCKER_USER',
passwordVariable: 'DOCKER_PWD')]){
sh "docker login -u ${DOCKER_USER} -p ${DOCKER_PWD}"
sh "docker build -t ${DOCKER_REGISTRY}/${PRODUCT}:${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}.${HOTFIX_VERSION} -f ./Dockerfile.jenkins ."
sh "docker push ${DOCKER_REGISTRY}/${PRODUCT}:${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}.${HOTFIX_VERSION}"
}
}
}
stage('K8S Deploy'){
container('kubectl'){
sh "rm -rf ./temp-yaml"
sh "cp -r ./install-yaml ./temp-yaml"
sh "sed -i 's#@@NAME_NS@@#${NAME_NS}#g' ./temp-yaml/*.yaml"
sh "cat ./temp-yaml/1.initialization.yaml"
sh "sed -i 's#@@NODE_PORT@@#${NODE_PORT}#g' ./temp-yaml/2.svc-np.yaml"
sh "cat ./temp-yaml/2.svc-np.yaml"
sh "sed -i 's#@@REALM@@#${REALM}#g' ./temp-yaml/3.deployment.yaml "
sh "sed -i 's#@@KEYCLOAK@@#${KEYCLOAK}#g' ./temp-yaml/3.deployment.yaml "
sh "sed -i 's#@@CLIENTID@@#${CLIENTID}#g' ./temp-yaml/3.deployment.yaml "
sh "sed -i 's#@@VER@@#${VER}#g' ./temp-yaml/3.deployment.yaml "
sh "sed -i '/--hdc-mode=/d' ./temp-yaml/3.deployment.yaml"
sh "sed -i '/--tmaxcloud-portal=/d' ./temp-yaml/3.deployment.yaml"
sh "cat ./temp-yaml/3.deployment.yaml"
sh "kubectl apply -f ./temp-yaml/1.initialization.yaml"
secret = sh (
script: 'kubectl get secret -A | grep console-https-secret',
returnStdout: true
).trim()
sh """
if [ -z "${secret}" ]; then
kubectl create secret tls console-https-secret --cert=tls/tls.crt --key=tls/tls.key -n ${NAME_NS}
fi
"""
sh "kubectl apply -f ./temp-yaml/2.svc-lb.yaml"
sh "kubectl apply -f ./temp-yaml/2.svc-np.yaml"
sh "kubectl apply -f ./temp-yaml/3.deployment.yaml"
// sh "kubectl apply -f ./temp-yaml/3.deployment.yaml"
}
}
stage('GIT Commit & Push'){
withCredentials([usernamePassword(credentialsId: 'jinsoo-youn', usernameVariable: 'username', passwordVariable: 'password')]) {
sh """
git config --global user.name ${username}
git config --global user.email [email protected]
git config --global credential.username ${username}
git config --global credential.helper "!echo password=${password}; echo"
"""
sh "git tag ${PRODUCT}_${VER}"
sh "git push origin HEAD:${BRANCH} --tags"
// NOTE: 4.1.3.0 정기 배포관련된 패치 노트는 젠킨스 이용 x tag가 꼬여서 직접 만들어서 업로드 함
sh """
echo '# hypercloud-console patch note' > ./docs-internal/CHANGELOG.md
echo '## [Product Name]_[major].[minor].[patch].[hotfix]' >> ./docs-internal/CHANGELOG.md
echo 'Version: ${PRODUCT}_${VER}' >> ./docs-internal/CHANGELOG.md
date '+%F %r' >> ./docs-internal/CHANGELOG.md
git log --grep=[patch] -F --all-match --no-merges --date-order --reverse \
--pretty=format:\"- %s (%cn) %n Message: %b\" \
--simplify-merges ${PRODUCT}_${PRE_VER}..${PRODUCT}_${VER} \
>> ./docs-internal/CHANGELOG.md
"""
//// sh "rm -r ./temp-yaml"
sh "git add -A"
sh "git commit -m 'build ${PRODUCT}_${VER}' "
sh "git push origin HEAD:${BRANCH}"
}
}
}
}