Commit 24579acb authored by 智勇's avatar 智勇

格式化

parent 2d254821
...@@ -22,7 +22,6 @@ def imageTag(harborGroup,k8sSystemName,safeBranchName,tagName){ ...@@ -22,7 +22,6 @@ def imageTag(harborGroup,k8sSystemName,safeBranchName,tagName){
def imageTag4_4=[:] def imageTag4_4=[:]
imageTag4_4["harborHost"]="http://192.168.4.4" imageTag4_4["harborHost"]="http://192.168.4.4"
imageTag4_4["imageTag"] = "${harborGroup}/${k8sSystemName}:${safeBranchName}-${tagName}" imageTag4_4["imageTag"] = "${harborGroup}/${k8sSystemName}:${safeBranchName}-${tagName}"
imageTag4_4["imageTagCode"] = "${harborGroup}/${k8sSystemName}:Code${safeBranchName}-${tagName}"
return [ imageTag4_4 ] return [ imageTag4_4 ]
} }
...@@ -35,11 +34,10 @@ def init_image_dependency(buildType,originSystemName,contextDir){ ...@@ -35,11 +34,10 @@ def init_image_dependency(buildType,originSystemName,contextDir){
switch (buildType){ switch (buildType){
case "lua-ui": case "lua-ui":
sh "cp -rf /home/quant_group/qg-dockerfiles/tke/ui/* ${contextDir}" sh "cp -rf /home/quant_group/qg-dockerfiles/tke/ui/* ${contextDir}"
def isVhFileExist = fileExists "/home/quant_group/config_repository/lua-ui/nginx/${originSystemName}.vh.conf" def isVhFileExist = fileExists "/home/quant_group/config_repository/lua-ui/nginx/${originSystemName}.vh.conf"
if (isVhFileExist) { if (isVhFileExist) {
sh "cp -rf /home/quant_group/config_repository/lua-ui/nginx/${originSystemName}.vh.conf ${contextDir}" sh "cp -rf /home/quant_group/config_repository/lua-ui/nginx/${originSystemName}.vh.conf ${contextDir}"
}else{ } else {
sh "cp -rf /home/quant_group/config_repository/lua-ui/nginx/default.vh.conf ${contextDir}" sh "cp -rf /home/quant_group/config_repository/lua-ui/nginx/default.vh.conf ${contextDir}"
} }
break break
...@@ -56,6 +54,7 @@ def ext_bower_install(){ ...@@ -56,6 +54,7 @@ def ext_bower_install(){
} }
return 0 return 0
} }
def ext_npm_intall(){ def ext_npm_intall(){
def packageFile = fileExists './package.json' def packageFile = fileExists './package.json'
if(packageFile){ if(packageFile){
...@@ -76,12 +75,36 @@ def project_attr(systemName) { ...@@ -76,12 +75,36 @@ def project_attr(systemName) {
return res_json return res_json
} }
def update_microservice(namespace, name, image, tier, domain) { def update_microservice(namespace, name, image, tier, domain, cluster) {
dest_url = "http://172.30.220.22:3003/k8s/service/modifyImage" dest_url = "http://172.30.220.22:3003/k8s/service/modifyImage"
response = httpRequest httpMode:"POST", response = httpRequest httpMode:"POST",
consoleLogResponseBody:true, consoleLogResponseBody:true,
contentType:"APPLICATION_JSON", contentType:"APPLICATION_JSON",
customHeaders: [[name:'cluster', value:"${cluster}"]],
requestBody:"""{
"namespace":"${namespace}",
"serviceName":"${name}",
"image":"${image}",
"label":"${tier}",
"type":"${tier}",
"domain":"${domain}",
"debug":0
}""",
url:dest_url
def res_json = jsonParse(response.content)
return res_json
}
// for test
def update_microservice_qke(namespace, name, image, tier, domain, cluster) {
dest_url = "http://192.168.28.179:3003/k8s/service/modifyImage"
response = httpRequest httpMode:"POST",
consoleLogResponseBody:true,
contentType:"APPLICATION_JSON",
customHeaders: [[name:'cluster', value:"${cluster}"]],
requestBody:"""{ requestBody:"""{
"namespace":"${namespace}", "namespace":"${namespace}",
"serviceName":"${name}", "serviceName":"${name}",
...@@ -96,6 +119,7 @@ def update_microservice(namespace, name, image, tier, domain) { ...@@ -96,6 +119,7 @@ def update_microservice(namespace, name, image, tier, domain) {
def res_json = jsonParse(response.content) def res_json = jsonParse(response.content)
return res_json return res_json
} }
def ding_talk(buildNumber,flags) { def ding_talk(buildNumber,flags) {
dest_url = "http://172.30.220.22:3003/pipeline/dingTalk" dest_url = "http://172.30.220.22:3003/pipeline/dingTalk"
...@@ -107,8 +131,8 @@ def ding_talk(buildNumber,flags) { ...@@ -107,8 +131,8 @@ def ding_talk(buildNumber,flags) {
"flag":"${flags}" "flag":"${flags}"
}""", }""",
url:dest_url url:dest_url
} }
def set_image_info(microservice_name, git_commit_hash, image) { def set_image_info(microservice_name, git_commit_hash, image) {
dest_url = "http://eos.quantgroups.com/api/etcd/set_image_info" dest_url = "http://eos.quantgroups.com/api/etcd/set_image_info"
...@@ -166,7 +190,6 @@ def slaveImageArgs(buildType){ ...@@ -166,7 +190,6 @@ def slaveImageArgs(buildType){
break break
case "python": case "python":
break break
case "lua-ui": case "lua-ui":
args += "-v /root/.nvm/versions/node/v8.9.1/bin:/usr/local/node-v8.9.1-linux-x64/bin " args += "-v /root/.nvm/versions/node/v8.9.1/bin:/usr/local/node-v8.9.1-linux-x64/bin "
args += "-v /root/.npm:/root/.npm:rw " args += "-v /root/.npm:/root/.npm:rw "
...@@ -195,9 +218,7 @@ def getDocketPackageImage(buildType,buildEnv){ ...@@ -195,9 +218,7 @@ def getDocketPackageImage(buildType,buildEnv){
} }
def check_and_build(buildType,systemName,branchName,contextDir){ def check_and_build(buildType,systemName,branchName,contextDir){
def branchHashCode = null def branchHashCode = null
def buildEnv ="" def buildEnv =""
switch(buildType){ switch(buildType){
case "java": case "java":
...@@ -220,10 +241,8 @@ def check_and_build(buildType,systemName,branchName,contextDir){ ...@@ -220,10 +241,8 @@ def check_and_build(buildType,systemName,branchName,contextDir){
} }
def pacegeDockerInfo = getDocketPackageImage(buildType,buildEnv) def pacegeDockerInfo = getDocketPackageImage(buildType,buildEnv)
if (buildType in ["nodejs","lua-ui"]){ if (buildType in ["nodejs","lua-ui"]){
branchHashCode = cpb(buildType,systemName,branchName,contextDir) branchHashCode = cpb(buildType,systemName,branchName,contextDir)
} else { } else {
docker.image(pacegeDockerInfo["image"]).inside(pacegeDockerInfo["args"]){ docker.image(pacegeDockerInfo["image"]).inside(pacegeDockerInfo["args"]){
branchHashCode = cpb(buildType,systemName,branchName,contextDir) branchHashCode = cpb(buildType,systemName,branchName,contextDir)
...@@ -234,7 +253,6 @@ def check_and_build(buildType,systemName,branchName,contextDir){ ...@@ -234,7 +253,6 @@ def check_and_build(buildType,systemName,branchName,contextDir){
def cpb(buildType,systemName,branchName,contextDir){ def cpb(buildType,systemName,branchName,contextDir){
/*checkout code*/ /*checkout code*/
stage('Checkout') { stage('Checkout') {
branchHashCode = checkout(buildType, systemName, branchName) branchHashCode = checkout(buildType, systemName, branchName)
} }
...@@ -278,7 +296,6 @@ def checkout(buildType,systemName, branchName) { ...@@ -278,7 +296,6 @@ def checkout(buildType,systemName, branchName) {
brahHashCode = brahHashCode.substring(0,16) brahHashCode = brahHashCode.substring(0,16)
echo "brahHashCode:${brahHashCode} with 'git log -1 --pretty=%H'" echo "brahHashCode:${brahHashCode} with 'git log -1 --pretty=%H'"
return brahHashCode return brahHashCode
} }
def checkout_java(systemName, branchName) { def checkout_java(systemName, branchName) {
...@@ -318,10 +335,9 @@ def checkout_nodejs(systemName, branchName) { ...@@ -318,10 +335,9 @@ def checkout_nodejs(systemName, branchName) {
git branch: branchName, credentialsId: 'e1ccb1ac-1282-4fb4-b766-530ca1a2a2db', url: gitPath git branch: branchName, credentialsId: 'e1ccb1ac-1282-4fb4-b766-530ca1a2a2db', url: gitPath
} }
// sh "npm install" // sh "npm install"
} }
def checkout_luaui(systemName, branchName) { def checkout_luaui(systemName, branchName) {
currentPath = sh (script: 'pwd',returnStdout: true).trim() currentPath = sh (script: 'pwd',returnStdout: true).trim()
echo "- ${currentPath} -" echo "- ${currentPath} -"
sh "whoami" sh "whoami"
...@@ -537,15 +553,14 @@ def build_luaui( systemName, branchName,contextDir) { ...@@ -537,15 +553,14 @@ def build_luaui( systemName, branchName,contextDir) {
} }
def dockerbuild_and_push(imageTagInfo,buildNumber,systemName,branchName,cluster,timeStemp,contextDir,branchHashCode,buildType){ def dockerbuild_and_push(imageTagInfo,buildNumber,systemName,branchName,timeStemp,contextDir,branchHashCode,buildType){
//systemName == originSystemName //systemName == originSystemName
def harbor_host = imageTagInfo["harborHost"] def harbor_host = imageTagInfo["harborHost"]
def imageTag = imageTagInfo["imageTag"] def imageTag = imageTagInfo["imageTag"]
def imageTagCode = imageTagInfo["imageTagCode"]
stage('Docker Build And Push') { stage('Docker Build And Push') {
withDockerRegistry([credentialsId: 'harbor-qajenkins', url: harbor_host]) { withDockerRegistry([credentialsId: 'harbor-qajenkins', url: harbor_host]) {
def build_schema = "BUILD_TIME:${timeStemp}@BUILD_NUMBER:${buildNumber}@SYSTEM_NAME:${systemName}@BRANCH_NAME:${branchName}@CLUSTER:${cluster}" def build_schema = "BUILD_TIME:${timeStemp}@BUILD_NUMBER:${buildNumber}@SYSTEM_NAME:${systemName}@BRANCH_NAME:${branchName}"
echo build_schema echo build_schema
def args = "" def args = ""
args += "--build-arg BUILD_TIME=${timeStemp} " args += "--build-arg BUILD_TIME=${timeStemp} "
...@@ -554,12 +569,7 @@ def dockerbuild_and_push(imageTagInfo,buildNumber,systemName,branchName,cluster, ...@@ -554,12 +569,7 @@ def dockerbuild_and_push(imageTagInfo,buildNumber,systemName,branchName,cluster,
args += "--build-arg BRANCH_NAME=${branchName} " args += "--build-arg BRANCH_NAME=${branchName} "
args += "--build-arg SAFE_SYSTEM_NAME=${systemName} " args += "--build-arg SAFE_SYSTEM_NAME=${systemName} "
args += "--build-arg BUILD_SCHEMA=${build_schema} " args += "--build-arg BUILD_SCHEMA=${build_schema} "
args += "--build-arg FROM_IMAGE=${imageTagCode} "
if(buildType=="java"){
if(cluster=="pro"){
def imageCode = docker.build(imageTagCode, "-f ${contextDir}/Code.Dockerfile ${contextDir}")
imageCode.push()
} else if (cluster=="test") {
def image def image
if(systemName=="smart-recruitment" || systemName=="smart-recruitment-spyder"){ if(systemName=="smart-recruitment" || systemName=="smart-recruitment-spyder"){
image = docker.build(imageTag, "${args} -f ${contextDir}/smart.Dockerfile ${contextDir}") image = docker.build(imageTag, "${args} -f ${contextDir}/smart.Dockerfile ${contextDir}")
...@@ -571,20 +581,6 @@ def dockerbuild_and_push(imageTagInfo,buildNumber,systemName,branchName,cluster, ...@@ -571,20 +581,6 @@ def dockerbuild_and_push(imageTagInfo,buildNumber,systemName,branchName,cluster,
if (branchName == "master" || branchName == "master--master") { if (branchName == "master" || branchName == "master--master") {
image.push('latest') image.push('latest')
} }
}
} else {
if (buildType=='lua-ui'){
def imageCode = docker.build(imageTagCode, "-f ${contextDir}/Code.Dockerfile ${contextDir}")
imageCode.push()
}
def image = docker.build(imageTag, "${args} ${contextDir}")
image.push()
if (branchName == "master" || branchName == "master--master") {
image.push('latest')
}
}
_utils().beautyEcho("镜像地址:${imageTag}", "info") _utils().beautyEcho("镜像地址:${imageTag}", "info")
} }
...@@ -593,7 +589,7 @@ def dockerbuild_and_push(imageTagInfo,buildNumber,systemName,branchName,cluster, ...@@ -593,7 +589,7 @@ def dockerbuild_and_push(imageTagInfo,buildNumber,systemName,branchName,cluster,
// set_image_info(systemName, branchHashCode, imageTag) // set_image_info(systemName, branchHashCode, imageTag)
} }
def deploy(namespace, systemName, imageTag, tier, isDeploy) { def deploy(namespace, systemName, imageTag, tier, isDeploy, cluster) {
stage('Deploy To K8s Cluster'){ stage('Deploy To K8s Cluster'){
_utils().beautyEcho("Deploy To K8S Cluster image: ${imageTag} to:${namespace}", "info") _utils().beautyEcho("Deploy To K8S Cluster image: ${imageTag} to:${namespace}", "info")
...@@ -603,7 +599,13 @@ def deploy(namespace, systemName, imageTag, tier, isDeploy) { ...@@ -603,7 +599,13 @@ def deploy(namespace, systemName, imageTag, tier, isDeploy) {
def hostArray = host.split("\\.") def hostArray = host.split("\\.")
imageTag = imageTag.replaceAll("ccr.ccs.tencentyun.com/","") imageTag = imageTag.replaceAll("ccr.ccs.tencentyun.com/","")
_utils().beautyEcho("[新集群][deployV2]将镜像更新到到Namespace:" + namespace, "info") _utils().beautyEcho("[新集群][deployV2]将镜像更新到到Namespace:" + namespace, "info")
update_microservice(namespace, systemName, imageTag, tier, hostArray[0]) // update_microservice(namespace, systemName, imageTag, tier, hostArray[0], cluster)
// for test
if(cluster=='qke'){
update_microservice_qke(namespace, systemName, imageTag, tier, hostArray[0], cluster)
}else{
update_microservice(namespace, systemName, imageTag, tier, hostArray[0], cluster)
}
} else { } else {
_utils().beautyEcho( "isDeploy == false,不执行deploy","info") _utils().beautyEcho( "isDeploy == false,不执行deploy","info")
} }
...@@ -611,17 +613,7 @@ def deploy(namespace, systemName, imageTag, tier, isDeploy) { ...@@ -611,17 +613,7 @@ def deploy(namespace, systemName, imageTag, tier, isDeploy) {
} }
def clean_images(imageTag,imageTagCode,contextDir,buildType) { def clean_images(imageTag,contextDir,buildType) {
sh "rm -rf ${contextDir}" sh "rm -rf ${contextDir}"
if(buildType=="java"){
if (cluster=="pro"){
sh "docker rmi -f \$(docker images -q ${imageTagCode})"
}else if (cluster=="test") {
sh "docker rmi -f \$(docker images -q ${imageTag})"
}
}else{
// sh "docker rmi -f \$(docker images -q ${imageTagCode})"
sh "docker rmi -f \$(docker images -q ${imageTag})" sh "docker rmi -f \$(docker images -q ${imageTag})"
}
} }
...@@ -79,22 +79,22 @@ def call(body) { ...@@ -79,22 +79,22 @@ def call(body) {
imageTagInfos = _stage.imageTag(harborGroup,k8sSystemName,safeBranchName,timeStemp) imageTagInfos = _stage.imageTag(harborGroup,k8sSystemName,safeBranchName,timeStemp)
for (imageTagInfo in imageTagInfos){ for (imageTagInfo in imageTagInfos){
_stage.dockerbuild_and_push(imageTagInfo,buildNumber,originSystemName,originBranchName ,cluster,timeStemp,contextDir,branchHashCode,config.buildType) _stage.dockerbuild_and_push(imageTagInfo,buildNumber,originSystemName,originBranchName,timeStemp,contextDir,branchHashCode,config.buildType)
} }
_stage.deploy(namespace, originSystemName, imageTagInfos[0]["imageTag"], config.tier, isDeploy) _stage.deploy(namespace, originSystemName, imageTagInfos[0]["imageTag"], config.tier, isDeploy, cluster)
} }
/* 4 */ /* 4 */
stage('Clean'){ stage('Clean'){
_utils.beautyEcho("Clear Cache Tmp", "stage") _utils.beautyEcho("Clear Cache Tmp", "stage")
_stage.clean_images(imageTagInfos[0]["imageTag"],imageTagInfos[0]["imageTagCode"],contextDir,config.buildType) _stage.clean_images(imageTagInfos[0]["imageTag"],contextDir,config.buildType)
_stage.ding_talk(buildNumber,"success") _stage.ding_talk(buildNumber,"success")
} }
} catch (err) { } catch (err) {
_utils.beautyEcho(err, "fail") _utils.beautyEcho(err, "fail")
_stage.ding_talk(buildNumber,"fail") _stage.ding_talk(buildNumber,"fail")
if(imageTagInfos != null){ if(imageTagInfos != null){
_stage.clean_images(imageTagInfos[0]["imageTag"],imageTagInfos[0]["imageTagCode"],contextDir,config.buildType) _stage.clean_images(imageTagInfos[0]["imageTag"],contextDir,config.buildType)
} }
throw err throw err
} }
......
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