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

格式化

parent 2d254821
...@@ -4,624 +4,616 @@ import org.qg.docker_new.Utils; ...@@ -4,624 +4,616 @@ import org.qg.docker_new.Utils;
import groovy.json.JsonSlurperClassic; import groovy.json.JsonSlurperClassic;
def _utils() { def _utils() {
return new org.qg.docker_new.Utils(); return new org.qg.docker_new.Utils();
} }
def debug() { def debug() {
_utils().beautyEcho("debug", "info") _utils().beautyEcho("debug", "info")
} }
def contextMkdir(key) { def contextMkdir(key) {
uuid = UUID.randomUUID().toString() uuid = UUID.randomUUID().toString()
contextDir = "/home/quant_group/package/${key}" contextDir = "/home/quant_group/package/${key}"
sh "mkdir -p ${contextDir}" sh "mkdir -p ${contextDir}"
return contextDir return contextDir
} }
def imageTag(harborGroup,k8sSystemName,safeBranchName,tagName){ 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 ]
} }
def init_dependency() { def init_dependency() {
sh "cd /home/quant_group/qg-dockerfiles; git pull; cd -" sh "cd /home/quant_group/qg-dockerfiles; git pull; cd -"
sh "cd /home/quant_group/config_repository; git pull origin master; cd -" sh "cd /home/quant_group/config_repository; git pull origin master; cd -"
} }
def init_image_dependency(buildType,originSystemName,contextDir){ 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 default:
default: break
break }
}
} }
def ext_bower_install(){ def ext_bower_install(){
def bowerFile = fileExists './bower.json' def bowerFile = fileExists './bower.json'
if(bowerFile){ if(bowerFile){
sh "bower install --allow-root" sh "bower install --allow-root"
return 1 return 1
} }
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){
// sh "npm install" // sh "npm install"
return 1 return 1
} }
return 0 return 0
} }
@NonCPS @NonCPS
def jsonParse(def json) { def jsonParse(def json) {
new groovy.json.JsonSlurperClassic().parseText(json) new groovy.json.JsonSlurperClassic().parseText(json)
} }
def project_attr(systemName) { def project_attr(systemName) {
response = httpRequest "http://192.168.4.3:10088/config_server/get_project_attr/${systemName}" response = httpRequest "http://192.168.4.3:10088/config_server/get_project_attr/${systemName}"
def res_json = jsonParse(response.content) def res_json = jsonParse(response.content)
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",
requestBody:"""{ customHeaders: [[name:'cluster', value:"${cluster}"]],
"namespace":"${namespace}", requestBody:"""{
"serviceName":"${name}", "namespace":"${namespace}",
"image":"${image}", "serviceName":"${name}",
"label":"${tier}", "image":"${image}",
"type":"${tier}", "label":"${tier}",
"domain":"${domain}", "type":"${tier}",
"debug":0 "domain":"${domain}",
}""", "debug":0
url:dest_url }""",
url:dest_url
def res_json = jsonParse(response.content)
return res_json 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:"""{
"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
} }
def ding_talk(buildNumber,flags) {
dest_url = "http://172.30.220.22:3003/pipeline/dingTalk"
response = httpRequest httpMode:"POST", def ding_talk(buildNumber,flags) {
consoleLogResponseBody:true, dest_url = "http://172.30.220.22:3003/pipeline/dingTalk"
contentType:"APPLICATION_JSON",
requestBody:"""{
"buildNumber":"${buildNumber}",
"flag":"${flags}"
}""",
url:dest_url
response = httpRequest httpMode:"POST",
consoleLogResponseBody:true,
contentType:"APPLICATION_JSON",
requestBody:"""{
"buildNumber":"${buildNumber}",
"flag":"${flags}"
}""",
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"
response = httpRequest httpMode:"POST", response = httpRequest httpMode:"POST",
consoleLogResponseBody:true, consoleLogResponseBody:true,
contentType:"APPLICATION_JSON", contentType:"APPLICATION_JSON",
requestBody:"""{ requestBody:"""{
"microservice_name":"${microservice_name}", "microservice_name":"${microservice_name}",
"git_commit_hash":"${git_commit_hash}", "git_commit_hash":"${git_commit_hash}",
"image": "${image}" "image": "${image}"
}""", }""",
url:dest_url url:dest_url
def res_json = jsonParse(response.content) def res_json = jsonParse(response.content)
return res_json return res_json
} }
def slaveImageRespority(buildEnv){ def slaveImageRespority(buildEnv){
//envType java8 java9 node7 node8 //envType java8 java9 node7 node8
switch(buildEnv){ switch(buildEnv){
case "java8": case "java8":
// return "192.168.4.4/baseimg/jenkins-java-slave:latest" // return "192.168.4.4/baseimg/jenkins-java-slave:latest"
return "192.168.4.4/baseimg/jenkins-java-slave-new:latest" return "192.168.4.4/baseimg/jenkins-java-slave-new:latest"
break break
case "java9": case "java9":
return null return null
break break
case "node7": case "node7":
return "192.168.4.4/baseimg/jenkins-node7-slave:latest" return "192.168.4.4/baseimg/jenkins-node7-slave:latest"
break break
case "node8": case "node8":
return "192.168.4.4/baseimg/jenkins-node8-slave:latest" return "192.168.4.4/baseimg/jenkins-node8-slave:latest"
break break
default : default :
return "192.168.4.4/baseimg/jenkins-slave:latest" return "192.168.4.4/baseimg/jenkins-slave:latest"
} }
} }
def slaveImageArgs(buildType){ def slaveImageArgs(buildType){
def args = "" def args = ""
args += "-v /home/quant_group/qg-dockerfiles:/home/quant_group/qg-dockerfiles " args += "-v /home/quant_group/qg-dockerfiles:/home/quant_group/qg-dockerfiles "
args += "-v /home/quant_group/config_repository:/home/quant_group/config_repository " args += "-v /home/quant_group/config_repository:/home/quant_group/config_repository "
args += "-v /home/quant_group/package/:/home/quant_group/package/ " args += "-v /home/quant_group/package/:/home/quant_group/package/ "
switch (buildType) { switch (buildType) {
case "java": case "java":
args += "-v /root/.m2:/root/.m2 " args += "-v /root/.m2:/root/.m2 "
break break
case "nodejs": case "nodejs":
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 "
args += "-v /root/.cache:/root/.cache:rw " args += "-v /root/.cache:/root/.cache:rw "
args += "-v /root/.node-gyp:/root/.node-gyp:rw " args += "-v /root/.node-gyp:/root/.node-gyp:rw "
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 " args += "-v /root/.cache:/root/.cache:rw "
args += "-v /root/.cache:/root/.cache:rw " args += "-v /root/.node-gyp:/root/.node-gyp:rw "
args += "-v /root/.node-gyp:/root/.node-gyp:rw " break
break
default:
default: break
break }
}
return args
return args
} }
def getDocketPackageImage(buildType,buildEnv){ def getDocketPackageImage(buildType,buildEnv){
echo "getDocketPackageImage :${buildType}" echo "getDocketPackageImage :${buildType}"
def packageImageInfo=[:] def packageImageInfo=[:]
packageImageInfo["image"] = slaveImageRespority(buildEnv) packageImageInfo["image"] = slaveImageRespority(buildEnv)
packageImageInfo["args"] = slaveImageArgs(buildType) packageImageInfo["args"] = slaveImageArgs(buildType)
_utils().beautyEcho("image :"+ packageImageInfo["image"], "info") _utils().beautyEcho("image :"+ packageImageInfo["image"], "info")
_utils().beautyEcho("args :"+ packageImageInfo["args"], "info") _utils().beautyEcho("args :"+ packageImageInfo["args"], "info")
return packageImageInfo return packageImageInfo
} }
def check_and_build(buildType,systemName,branchName,contextDir){ def check_and_build(buildType,systemName,branchName,contextDir){
def branchHashCode = null
def branchHashCode = null def buildEnv =""
switch(buildType){
def buildEnv ="" case "java":
switch(buildType){ buildEnv ="java8"
case "java": break
buildEnv ="java8" case "python":
break buildEnv ="python"
case "python": break
buildEnv ="python" case "lua-ui":
break buildEnv = "node8"
case "lua-ui": if(systemName in ["xyqb-ui"]){
buildEnv = "node8" buildEnv ="node7"
if(systemName in ["xyqb-ui"]){ }
buildEnv ="node7" break
} case "nodejs":
break buildEnv = "node8"
case "nodejs": break
buildEnv = "node8" default :
break buildEnv ="java8"
default : }
buildEnv ="java8"
} def pacegeDockerInfo = getDocketPackageImage(buildType,buildEnv)
if (buildType in ["nodejs","lua-ui"]){
def pacegeDockerInfo = getDocketPackageImage(buildType,buildEnv) branchHashCode = cpb(buildType,systemName,branchName,contextDir)
} else {
if (buildType in ["nodejs","lua-ui"]){ docker.image(pacegeDockerInfo["image"]).inside(pacegeDockerInfo["args"]){
branchHashCode = cpb(buildType,systemName,branchName,contextDir) branchHashCode = cpb(buildType,systemName,branchName,contextDir)
}
} else { }
docker.image(pacegeDockerInfo["image"]).inside(pacegeDockerInfo["args"]){ return branchHashCode
branchHashCode = cpb(buildType,systemName,branchName,contextDir)
}
}
return branchHashCode
} }
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) }
} /*prepare config*/
/*prepare config*/ stage('Prepare') {
stage('Prepare') { if(systemName=='xjd-ui' && branchName == 'apollo'){
if(systemName=='xjd-ui' && branchName == 'apollo'){ _utils().beautyEcho("xjd-ui : apollo not exec prepare_config", "info")
_utils().beautyEcho("xjd-ui : apollo not exec prepare_config", "info") } else{
} else{ prepare_config(buildType, systemName, contextDir)
prepare_config(buildType, systemName, contextDir) }
} }
}
/*build*/
/*build*/ stage('Build'){
stage('Build'){ build(buildType, systemName, branchName,contextDir)
build(buildType, systemName, branchName,contextDir) }
} return branchHashCode
return branchHashCode
} }
def checkout(buildType,systemName, branchName) { def checkout(buildType,systemName, branchName) {
_utils().beautyEcho("CheckOut +++ type:${buildType} systemName:${systemName} branchName:${branchName}", "info") _utils().beautyEcho("CheckOut +++ type:${buildType} systemName:${systemName} branchName:${branchName}", "info")
switch(buildType){ switch(buildType){
case "java": case "java":
checkout_java(systemName, branchName) checkout_java(systemName, branchName)
break break
case "nodejs": case "nodejs":
checkout_nodejs(systemName, branchName) checkout_nodejs(systemName, branchName)
break break
case "python": case "python":
checkout_python(systemName, branchName) checkout_python(systemName, branchName)
break break
case "lua-ui": case "lua-ui":
checkout_luaui(systemName, branchName) checkout_luaui(systemName, branchName)
break break
default: default:
echo "未知的buildType: ${buildType}" echo "未知的buildType: ${buildType}"
break break
} }
def brahHashCode = sh (script: 'git log -1 --pretty=%H',returnStdout: true).trim()
brahHashCode = brahHashCode.substring(0,16)
echo "brahHashCode:${brahHashCode} with 'git log -1 --pretty=%H'"
return brahHashCode
def brahHashCode = sh (script: 'git log -1 --pretty=%H',returnStdout: true).trim()
brahHashCode = brahHashCode.substring(0,16)
echo "brahHashCode:${brahHashCode} with 'git log -1 --pretty=%H'"
return brahHashCode
} }
def checkout_java(systemName, branchName) { def checkout_java(systemName, branchName) {
def projectAttr = project_attr(systemName) def projectAttr = project_attr(systemName)
def gitPath =projectAttr["gitPath"] def gitPath =projectAttr["gitPath"]
def configPath = projectAttr["configPath"] def configPath = projectAttr["configPath"]
git branch: branchName, credentialsId: 'e1ccb1ac-1282-4fb4-b766-530ca1a2a2db', url: gitPath git branch: branchName, credentialsId: 'e1ccb1ac-1282-4fb4-b766-530ca1a2a2db', url: gitPath
} }
def checkout_python(systemName, branchName) { def checkout_python(systemName, branchName) {
def projectAttr = project_attr(systemName) def projectAttr = project_attr(systemName)
def gitPath =projectAttr["gitPath"] def gitPath =projectAttr["gitPath"]
git branch: branchName, credentialsId: 'e1ccb1ac-1282-4fb4-b766-530ca1a2a2db', url: gitPath git branch: branchName, credentialsId: 'e1ccb1ac-1282-4fb4-b766-530ca1a2a2db', url: gitPath
} }
def checkout_nodejs(systemName, branchName) { def checkout_nodejs(systemName, branchName) {
sh "cp -rf /home/quant_group/qg-dockerfiles/tke/ui/npmrc/common-npmrc /root/.npmrc" sh "cp -rf /home/quant_group/qg-dockerfiles/tke/ui/npmrc/common-npmrc /root/.npmrc"
def projectAttr = project_attr(systemName) def projectAttr = project_attr(systemName)
def gitPath =projectAttr["gitPath"] def gitPath =projectAttr["gitPath"]
currentPath = sh (script: 'pwd',returnStdout: true).trim() currentPath = sh (script: 'pwd',returnStdout: true).trim()
def folder = new File( "${currentPath}/.git/hooks" ) def folder = new File( "${currentPath}/.git/hooks" )
echo "${currentPath}/.git/hooks" echo "${currentPath}/.git/hooks"
if( !folder.exists()){ if( !folder.exists()){
echo ">>>>>>>>> first git clone" echo ">>>>>>>>> first git clone"
git branch: branchName, credentialsId: 'e1ccb1ac-1282-4fb4-b766-530ca1a2a2db', url: gitPath git branch: branchName, credentialsId: 'e1ccb1ac-1282-4fb4-b766-530ca1a2a2db', url: gitPath
def bowerFile = fileExists './bower.json' def bowerFile = fileExists './bower.json'
if (bowerFile) { if (bowerFile) {
sh "bower install --allow-root" sh "bower install --allow-root"
} }
} else { } else {
echo ">>>>>>>>> not first git clone" echo ">>>>>>>>> not first git clone"
// sh "cp -rf /home/quant_group/config_repository/lua-ui/hook/post-checkout .git/hooks/" // sh "cp -rf /home/quant_group/config_repository/lua-ui/hook/post-checkout .git/hooks/"
// sh "chmod +x .git/hooks/post-checkout" // sh "chmod +x .git/hooks/post-checkout"
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" echo "----------------------------"
echo "----------------------------" // def npmrcPath = "/home/quant_group/config_repository/lua-ui/npmrc/${systemName}-npmrc"
// def npmrcPath = "/home/quant_group/config_repository/lua-ui/npmrc/${systemName}-npmrc" // def specialNpmrc = new File( npmrcPath )
// def specialNpmrc = new File( npmrcPath ) // if(specialNpmrc.exists()){
// if(specialNpmrc.exists()){ // sh "cp -rf ${npmrcPath} .npmrc"
// sh "cp -rf ${npmrcPath} .npmrc" // }
// }
_utils().beautyEcho("ui project : ${systemName}" , "info")
_utils().beautyEcho("ui project : ${systemName}" , "info") projectAttr = project_attr(systemName)
projectAttr = project_attr(systemName) gitPath = projectAttr["gitPath"]
gitPath = projectAttr["gitPath"]
//0 if project is simple ui not run npm install
//0 if project is simple ui not run npm install
def hookfolder = new File( "${currentPath}/.git/hooks" )
def hookfolder = new File( "${currentPath}/.git/hooks" ) def packejson = new File( "${currentPath}/package.json" )
def packejson = new File( "${currentPath}/package.json" )
sh "cp -rf /home/quant_group/qg-dockerfiles/tke/ui/npmrc/common-npmrc /root/.npmrc"
sh "cp -rf /home/quant_group/qg-dockerfiles/tke/ui/npmrc/common-npmrc /root/.npmrc"
if(!hookfolder.exists()){
if(!hookfolder.exists()){ echo ">>>>>>> first checkout project ${systemName}"
echo ">>>>>>> first checkout project ${systemName}" git branch: branchName, credentialsId: 'e1ccb1ac-1282-4fb4-b766-530ca1a2a2db', url: gitPath
git branch: branchName, credentialsId: 'e1ccb1ac-1282-4fb4-b766-530ca1a2a2db', url: gitPath
def bowerResult = ext_bower_install()
def bowerResult = ext_bower_install() def npmResult = ext_npm_intall()
def npmResult = ext_npm_intall() def resultNum = bowerResult +npmResult
def resultNum = bowerResult +npmResult
if(resultNum ==0){
if(resultNum ==0){ echo ">>>>>>> is simple ui project"
echo ">>>>>>> is simple ui project" def dist = fileExists './dist'
def dist = fileExists './dist' if(!dist){
if(!dist){ sh "mkdir dist"
sh "mkdir dist" }
} return
return } else {
} else { echo ">>>>>>> is node ui project"
echo ">>>>>>> is node ui project" def bowerFile = fileExists './bower.json'
def bowerFile = fileExists './bower.json' sh "npm install"
sh "npm install" if (bowerFile) {
if (bowerFile) { sh "bower install --allow-root"
sh "bower install --allow-root" }
} }
}
}else{
}else{ if(!packejson.exists()){
if(!packejson.exists()){ echo ">>>>>>> is simple ui project"
echo ">>>>>>> is simple ui project" git branch: branchName, credentialsId: 'e1ccb1ac-1282-4fb4-b766-530ca1a2a2db', url: gitPath
git branch: branchName, credentialsId: 'e1ccb1ac-1282-4fb4-b766-530ca1a2a2db', url: gitPath def dist = fileExists './dist'
def dist = fileExists './dist' if(!dist){
if(!dist){ sh "mkdir dist"
sh "mkdir dist" }
} return
return } else{
} else{ echo ">>>>>>> is node ui project"
echo ">>>>>>> is node ui project" // sh "cp -rf /home/quant_group/config_repository/lua-ui/hook/post-checkout .git/hooks/"
// sh "cp -rf /home/quant_group/config_repository/lua-ui/hook/post-checkout .git/hooks/" // sh "chmod +x .git/hooks/post-checkout"
// sh "chmod +x .git/hooks/post-checkout"
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 prepare_config(buildType,systemName, contextDir) { def prepare_config(buildType,systemName, contextDir) {
_utils().beautyEcho("Prepare Config +++ type:${buildType} systemName:${systemName}", "info") _utils().beautyEcho("Prepare Config +++ type:${buildType} systemName:${systemName}", "info")
switch (buildType) { switch (buildType) {
case "java": case "java":
prepare_java(systemName, contextDir) prepare_java(systemName, contextDir)
break break
case "nodejs": case "nodejs":
prepare_nodejs(systemName, contextDir) prepare_nodejs(systemName, contextDir)
break break
case "python": case "python":
prepare_python(systemName, contextDir) prepare_python(systemName, contextDir)
break break
case "lua-ui": case "lua-ui":
prepare_luaui(systemName, contextDir) prepare_luaui(systemName, contextDir)
break break
default: default:
_utils().beautyEcho("未知的buildType: ${buildType}","fail") _utils().beautyEcho("未知的buildType: ${buildType}","fail")
break break
} }
} }
def prepare_java(systemName, contextDir) { def prepare_java(systemName, contextDir) {
sh "cp -rf /home/quant_group/qg-dockerfiles/tke/java/* ${contextDir}" sh "cp -rf /home/quant_group/qg-dockerfiles/tke/java/* ${contextDir}"
def existProperties = fileExists "/home/quant_group/config_repository/tke/java/${systemName}.properties" def existProperties = fileExists "/home/quant_group/config_repository/tke/java/${systemName}.properties"
echo "------ java properties exist :$existProperties ------" echo "------ java properties exist :$existProperties ------"
if(existProperties){ if(existProperties){
sh "cp -rf /home/quant_group/config_repository/tke/java/${systemName}.properties ${contextDir}/application.properties" sh "cp -rf /home/quant_group/config_repository/tke/java/${systemName}.properties ${contextDir}/application.properties"
} else { } else {
sh "cp -rf /home/quant_group/config_repository/tke/java/null.properties ${contextDir}/application.properties" sh "cp -rf /home/quant_group/config_repository/tke/java/null.properties ${contextDir}/application.properties"
} }
} }
def prepare_nodejs(systemName, contextDir) { def prepare_nodejs(systemName, contextDir) {
sh "cp -rf /home/quant_group/qg-dockerfiles/tke/nodejs/* ${contextDir}" sh "cp -rf /home/quant_group/qg-dockerfiles/tke/nodejs/* ${contextDir}"
sh "cp -rf /home/quant_group/config_repository/tke/nodejs/${systemName}.js ${systemName}.env.config" sh "cp -rf /home/quant_group/config_repository/tke/nodejs/${systemName}.js ${systemName}.env.config"
sh "cp -rf /home/quant_group/qg-dockerfiles/tke/ui/npmrc/common-npmrc ${contextDir}/.npmrc" sh "cp -rf /home/quant_group/qg-dockerfiles/tke/ui/npmrc/common-npmrc ${contextDir}/.npmrc"
// sh "cp -rf /home/quant_group/qg-dockerfiles/tke/ui/npmrc/common-npmrc /root/.npmrc" // sh "cp -rf /home/quant_group/qg-dockerfiles/tke/ui/npmrc/common-npmrc /root/.npmrc"
} }
def prepare_luaui(systemName, contextDir) { def prepare_luaui(systemName, contextDir) {
sh "cp -rf /home/quant_group/qg-dockerfiles/tke/ui/npmrc/common-npmrc /root/.npmrc" sh "cp -rf /home/quant_group/qg-dockerfiles/tke/ui/npmrc/common-npmrc /root/.npmrc"
} }
def prepare_python(systemName, contextDir) { def prepare_python(systemName, contextDir) {
// sh "rm -rf ${contextDir}" // sh "rm -rf ${contextDir}"
sh "cp -rf /home/quant_group/qg-dockerfiles/tke/python/* ${contextDir}" sh "cp -rf /home/quant_group/qg-dockerfiles/tke/python/* ${contextDir}"
sh "cp -rf /home/quant_group/config_repository/python/${systemName}.ini ${contextDir}/config.ini" sh "cp -rf /home/quant_group/config_repository/python/${systemName}.ini ${contextDir}/config.ini"
} }
def build(buildType,systemName, branchName,contextDir){ def build(buildType,systemName, branchName,contextDir){
sh 'echo $PATH' sh 'echo $PATH'
_utils().beautyEcho("Build +++ type:${buildType} systemName:${systemName}", "info") _utils().beautyEcho("Build +++ type:${buildType} systemName:${systemName}", "info")
switch(buildType){ switch(buildType){
case "java": case "java":
build_java(systemName, branchName,contextDir) build_java(systemName, branchName,contextDir)
break break
case "nodejs": case "nodejs":
sh "which node" sh "which node"
sh "node -v" sh "node -v"
sh "npm -v" sh "npm -v"
build_nodejs( systemName, branchName,contextDir) build_nodejs( systemName, branchName,contextDir)
break break
case "python": case "python":
build_python( systemName, branchName,contextDir) build_python( systemName, branchName,contextDir)
break break
case "lua-ui": case "lua-ui":
sh "which node" sh "which node"
sh "node -v" sh "node -v"
sh "npm -v" sh "npm -v"
build_luaui( systemName, branchName,contextDir) build_luaui( systemName, branchName,contextDir)
break break
default: default:
echo "未知的buildType: ${buildType}" echo "未知的buildType: ${buildType}"
break break
} }
} }
def build_java(systemName, branchName,contextDir) { def build_java(systemName, branchName,contextDir) {
def projectAttr = project_attr(systemName) def projectAttr = project_attr(systemName)
buildCmd = projectAttr["buildCmd"] buildCmd = projectAttr["buildCmd"]
jarFilePath = projectAttr["jarFilePath"] jarFilePath = projectAttr["jarFilePath"]
sh "mkdir ${contextDir}/lib ${contextDir}/config;touch ${contextDir}/lib/lib.txt;touch ${contextDir}/config/config.txt" sh "mkdir ${contextDir}/lib ${contextDir}/config;touch ${contextDir}/lib/lib.txt;touch ${contextDir}/config/config.txt"
sh 'mvn -v' sh 'mvn -v'
sh buildCmd sh buildCmd
sh "mv ${jarFilePath}/*.jar ${contextDir}/app.jar" sh "mv ${jarFilePath}/*.jar ${contextDir}/app.jar"
currentPath = sh (script: 'pwd',returnStdout: true).trim() currentPath = sh (script: 'pwd',returnStdout: true).trim()
def libfolder = new File( "${currentPath}/target/lib" ) def libfolder = new File( "${currentPath}/target/lib" )
echo "${currentPath}/target/lib is exist : ${libfolder.exists()}" echo "${currentPath}/target/lib is exist : ${libfolder.exists()}"
if (libfolder.exists()){ if (libfolder.exists()){
sh "mv ${jarFilePath}/lib/* ${contextDir}/lib" sh "mv ${jarFilePath}/lib/* ${contextDir}/lib"
} }
def configfolder = new File( "${currentPath}/target/config" ) def configfolder = new File( "${currentPath}/target/config" )
echo "${currentPath}/target/config is exist : ${configfolder.exists()}" echo "${currentPath}/target/config is exist : ${configfolder.exists()}"
if (configfolder.exists()){ if (configfolder.exists()){
sh "mv ${jarFilePath}/config/* ${contextDir}/config" sh "mv ${jarFilePath}/config/* ${contextDir}/config"
} }
} }
def build_nodejs( systemName, branchName,contextDir) { def build_nodejs( systemName, branchName,contextDir) {
def projectAttr = project_attr(systemName) def projectAttr = project_attr(systemName)
configPath = projectAttr["configPath"] configPath = projectAttr["configPath"]
buildCmd = projectAttr["buildCmd"] buildCmd = projectAttr["buildCmd"]
configName = systemName configName = systemName
sh "mv -f ./${systemName}.env.config ${configPath}" sh "mv -f ./${systemName}.env.config ${configPath}"
sh "tar zcf ${contextDir}/dist.tgz ./* " sh "tar zcf ${contextDir}/dist.tgz ./* "
sh "cp -rf package.json ${contextDir}" sh "cp -rf package.json ${contextDir}"
} }
def build_python( systemName, branchName,contextDir) { def build_python( systemName, branchName,contextDir) {
// sh "cp -rf ${contextDir}/config.ini server/config/release/config.ini" // sh "cp -rf ${contextDir}/config.ini server/config/release/config.ini"
// sh "cp -rf ${contextDir}/config.ini server/config/beta/config.ini" // sh "cp -rf ${contextDir}/config.ini server/config/beta/config.ini"
def projectAttr = project_attr(systemName) def projectAttr = project_attr(systemName)
configPath = projectAttr["configPath"] configPath = projectAttr["configPath"]
sh "cp -rf ${contextDir}/config.ini ${configPath}" sh "cp -rf ${contextDir}/config.ini ${configPath}"
sh "tar zcf ${contextDir}/dist.tgz ./*" sh "tar zcf ${contextDir}/dist.tgz ./*"
// sh "mv dist.tgz ${contextDir}" // sh "mv dist.tgz ${contextDir}"
} }
def build_luaui( systemName, branchName,contextDir) { def build_luaui( systemName, branchName,contextDir) {
def projectAttr = project_attr(systemName) def projectAttr = project_attr(systemName)
configPath = projectAttr["configPath"] configPath = projectAttr["configPath"]
buildCmd = projectAttr["buildCmd"] buildCmd = projectAttr["buildCmd"]
configName = systemName configName = systemName
currentPath = sh (script: 'pwd',returnStdout: true).trim() currentPath = sh (script: 'pwd',returnStdout: true).trim()
if(systemName=='xjd-ui' && branchName == 'apollo'){ if(systemName=='xjd-ui' && branchName == 'apollo'){
sh "npm run build" sh "npm run build"
} else { } else {
// sh "mv -f ./${systemName}.env.config ${configPath}" // sh "mv -f ./${systemName}.env.config ${configPath}"
sh buildCmd sh buildCmd
} }
sh "tar zcf ${systemName}.tgz dist/" sh "tar zcf ${systemName}.tgz dist/"
sh "mv ${systemName}.tgz ${contextDir}" sh "mv ${systemName}.tgz ${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}"
def build_schema = "BUILD_TIME:${timeStemp}@BUILD_NUMBER:${buildNumber}@SYSTEM_NAME:${systemName}@BRANCH_NAME:${branchName}@CLUSTER:${cluster}" echo build_schema
echo build_schema def args = ""
def args = "" args += "--build-arg BUILD_TIME=${timeStemp} "
args += "--build-arg BUILD_TIME=${timeStemp} " args += "--build-arg BUILD_NUMBER=${buildNumber} "
args += "--build-arg BUILD_NUMBER=${buildNumber} " args += "--build-arg SYSTEM_NAME=${systemName} "
args += "--build-arg SYSTEM_NAME=${systemName} " 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} " def image
if(buildType=="java"){ if(systemName=="smart-recruitment" || systemName=="smart-recruitment-spyder"){
if(cluster=="pro"){ image = docker.build(imageTag, "${args} -f ${contextDir}/smart.Dockerfile ${contextDir}")
def imageCode = docker.build(imageTagCode, "-f ${contextDir}/Code.Dockerfile ${contextDir}") } else {
imageCode.push() image = docker.build(imageTag, "${args} ${contextDir}")
} else if (cluster=="test") { }
def image image.push()
if(systemName=="smart-recruitment" || systemName=="smart-recruitment-spyder"){
image = docker.build(imageTag, "${args} -f ${contextDir}/smart.Dockerfile ${contextDir}") if (branchName == "master" || branchName == "master--master") {
} else { image.push('latest')
image = docker.build(imageTag, "${args} ${contextDir}") }
}
image.push() _utils().beautyEcho("镜像地址:${imageTag}", "info")
}
if (branchName == "master" || branchName == "master--master") { }
image.push('latest') /* 设置etcd镜像信息 */
} // set_image_info(systemName, branchHashCode, imageTag)
} }
} else {
if (buildType=='lua-ui'){ def deploy(namespace, systemName, imageTag, tier, isDeploy, cluster) {
def imageCode = docker.build(imageTagCode, "-f ${contextDir}/Code.Dockerfile ${contextDir}") stage('Deploy To K8s Cluster'){
imageCode.push() _utils().beautyEcho("Deploy To K8S Cluster image: ${imageTag} to:${namespace}", "info")
}
if (isDeploy=="true") {
def image = docker.build(imageTag, "${args} ${contextDir}") def projectAttr = project_attr(systemName)
image.push() def host = projectAttr["host"]
def hostArray = host.split("\\.")
if (branchName == "master" || branchName == "master--master") { imageTag = imageTag.replaceAll("ccr.ccs.tencentyun.com/","")
image.push('latest') _utils().beautyEcho("[新集群][deployV2]将镜像更新到到Namespace:" + namespace, "info")
} // update_microservice(namespace, systemName, imageTag, tier, hostArray[0], cluster)
} // for test
if(cluster=='qke'){
_utils().beautyEcho("镜像地址:${imageTag}", "info") update_microservice_qke(namespace, systemName, imageTag, tier, hostArray[0], cluster)
} }else{
} update_microservice(namespace, systemName, imageTag, tier, hostArray[0], cluster)
/* 设置etcd镜像信息 */ }
// set_image_info(systemName, branchHashCode, imageTag) } else {
} _utils().beautyEcho( "isDeploy == false,不执行deploy","info")
}
def deploy(namespace, systemName, imageTag, tier, isDeploy) { }
stage('Deploy To K8s Cluster'){ }
_utils().beautyEcho("Deploy To K8S Cluster image: ${imageTag} to:${namespace}", "info")
if (isDeploy=="true") { def clean_images(imageTag,contextDir,buildType) {
def projectAttr = project_attr(systemName) sh "rm -rf ${contextDir}"
def host = projectAttr["host"] sh "docker rmi -f \$(docker images -q ${imageTag})"
def hostArray = host.split("\\.")
imageTag = imageTag.replaceAll("ccr.ccs.tencentyun.com/","")
_utils().beautyEcho("[新集群][deployV2]将镜像更新到到Namespace:" + namespace, "info")
update_microservice(namespace, systemName, imageTag, tier, hostArray[0])
} else {
_utils().beautyEcho( "isDeploy == false,不执行deploy","info")
}
}
}
def clean_images(imageTag,imageTagCode,contextDir,buildType) {
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})"
}
} }
...@@ -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