Commit d62e561c authored by wentao.suo's avatar wentao.suo

fix

parent 99d7a3c5
......@@ -14,7 +14,7 @@ def debug() {
def contextMkdir(key) {
uuid = UUID.randomUUID().toString()
contextDir = "/home/quant_group/package/${key}"
sh "mkdir -p ${contextDir}"
sh "mkdir -p ${contextDir}"
return contextDir
}
......@@ -64,13 +64,13 @@ def prepare_luaui(systemName, contextDir) {
def isVhFileExist = fileExists "/home/quant_group/config_repository/lua-ui/nginx/${systemName}.vh.conf"
if (isVhFileExist) {
sh "cp -rf /home/quant_group/config_repository/lua-ui/nginx/${systemName}.vh.conf ${contextDir}"
sh "cp -rf /home/quant_group/config_repository/lua-ui/nginx/${systemName}.vh.conf ${contextDir}"
}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}"
}
sh "cp -rf /home/quant_group/config_repository/lua-ui/config/${systemName}.js ${systemName}.env.config.js"
sh "cp -rf /home/quant_group/config_repository/lua-ui/config/${systemName}.js ${systemName}.env.config.js"
}
......@@ -112,20 +112,20 @@ def checkout_nodejs(systemName, branchName) {
def projectAttr = project_attr(systemName)
def gitPath =projectAttr["gitPath"]
currentPath = sh (script: 'pwd',returnStdout: true).trim()
def folder = new File( "${currentPath}/.git/hooks" )
currentPath = sh (script: 'pwd',returnStdout: true).trim()
def folder = new File( "${currentPath}/.git/hooks" )
if( !folder.exists()){
git branch: branchName, credentialsId: 'e1ccb1ac-1282-4fb4-b766-530ca1a2a2db', url: gitPath
def bowerFile = fileExists './bower.json'
if (bowerFile) {
sh "bower install --allow-root"
}
sh "npm install"
git branch: branchName, credentialsId: 'e1ccb1ac-1282-4fb4-b766-530ca1a2a2db', url: gitPath
def bowerFile = fileExists './bower.json'
if (bowerFile) {
sh "bower install --allow-root"
}
sh "npm install"
} else {
sh "cp -rf /home/quant_group/config_repository/lua-ui/hook/post-checkout .git/hooks/"
sh "chmod +x .git/hooks/post-checkout"
git branch: branchName, credentialsId: 'e1ccb1ac-1282-4fb4-b766-530ca1a2a2db', url: gitPath
sh "cp -rf /home/quant_group/config_repository/lua-ui/hook/post-checkout .git/hooks/"
sh "chmod +x .git/hooks/post-checkout"
git branch: branchName, credentialsId: 'e1ccb1ac-1282-4fb4-b766-530ca1a2a2db', url: gitPath
}
......@@ -195,13 +195,13 @@ def build(buildType,systemName, contextDir){
}
def build_java(systemName, contextDir) {
def projectAttr = project_attr(systemName)
def projectAttr = project_attr(systemName)
buildCmd = projectAttr["buildCmd"]
jarFilePath = projectAttr["jarFilePath"]
sh buildCmd
sh "cp ${jarFilePath}/*.jar ${contextDir}/app.jar"
buildCmd = projectAttr["buildCmd"]
jarFilePath = projectAttr["jarFilePath"]
sh buildCmd
sh "cp ${jarFilePath}/*.jar ${contextDir}/app.jar"
}
def build_nodejs( systemName, contextDir) {
......@@ -265,49 +265,69 @@ def update_microservice(namespace, name, image, tier) {
return res_json
}
def getDocketPackageImage(buildType){
echo "getDocketPackageImage :${buildType}"
def args = ""
def packageImageInfo=[:]
def slaveImageRespority(buildEnv){
//envType java8 java9 node7 node8
switch(envType){
catch "java8":
return "192.168.4.36/baseimg/docker-jenkins-slave:2018041202"
break
catch "java9":
return null
break
catch "node7":
return "192.168.4.36/baseimg/jenkins-node7-slave:2018041301"
break
catch "node8":
return "192.168.4.36/baseimg/jenkins-node8-slave:2018041301"
break
default :
return "192.168.4.36/baseimg/docker-jenkins-slave:2018041202"
}
packageImageInfo["image"] = "192.168.4.36/baseimg/docker-jenkins-slave:2018041202"
}
def slaveImageArgs(buildType){
def args = ""
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/package/:/home/quant_group/package/ "
switch (buildType) {
case "java":
args += "-v /root/.m2:/root/.m2 "
packageImageInfo["args"] = args
args += "-v /root/.m2:/root/.m2 "
break
case "nodejs":
args += "-v /root/.npm:/root/.npm:rw "
args += "-v /root/.cache:/root/.cache:rw "
args += "-v /root/.node-gyp:/root/.node-gyp:rw "
packageImageInfo["args"] = args
break
case "python":
packageImageInfo["args"] = ""
args += "-v /root/.node-gyp:/root/.node-gyp:rw "
break
case "python":
break
case "lua-ui":
args += "-v /root/.npm:/root/.npm:rw "
args += "-v /root/.cache:/root/.cache:rw "
args += "-v /root/.node-gyp:/root/.node-gyp:rw "
packageImageInfo["image"] = "192.168.4.36/baseimg/docker-jenkins-slave:2018041204"
packageImageInfo["args"] = args
args += "-v /root/.node-gyp:/root/.node-gyp:rw "
break
default:
echo ""
_utils() .beautyEcho("未知的buildType: ${buildType}", "info")
packageImageInfo["image"] = ""
packageImageInfo["args"] = ""
default:
break
}
return args
}
def getDocketPackageImage(buildType,buildEnv){
echo "getDocketPackageImage :${buildType}"
def packageImageInfo=[:]
packageImageInfo["image"] = slaveImageRespority(buildEnv)
packageImageInfo["args"] = slaveImageArgs(buildType)
_utils().beautyEcho("image :"+ packageImageInfo["image"], "info")
_utils().beautyEcho("args :"+ packageImageInfo["args"], "info")
return packageImageInfo
......@@ -315,6 +335,21 @@ def getDocketPackageImage(buildType){
def check_and_build(buildType,systemName,branchName,contextDir){
def buildEnv =""
switch(buildType){
case "java"
buildEnv ="java8"
break
case "lua-ui"
buildEnv = "node8"
if(systemName=="xyqb-ui"){
buildEnv ="node7"
}
break
default :
buildEnv ="java8"
}
def pacegeDockerInfo = getDocketPackageImage(buildType)
docker.image(pacegeDockerInfo["image"]).inside(pacegeDockerInfo["args"]){
......@@ -331,54 +366,50 @@ def check_and_build(buildType,systemName,branchName,contextDir){
stage('Build'){
build(buildType, systemName, contextDir)
}
}
}
def dockerbuild_and_push(imageTag,buildNumber,systemName,branchName,cluster,timeStemp){
//systemName == originSystemName
stage('Docker Build And Push') {
stage('Docker Build And Push') {
withDockerRegistry([credentialsId: 'harbor-qajenkins', url: "http://192.168.4.36"]) {
def build_schema = "BUILD_TIME:${timeStemp}@BUILD_NUMBER:${buildNumber}@SYSTEM_NAME:${systemName}@BRANCH_NAME:${branchName}@CLUSTER:${cluster}"
echo build_schema
def args = ""
args += "--build-arg BUILD_TIME=${timeStemp} "
args += "--build-arg BUILD_NUMBER=${buildNumber} "
args += "--build-arg SYSTEM_NAME=${systemName} "
args += "--build-arg BRANCH_NAME=${branchName} "
args += "--build-arg SAFE_SYSTEM_NAME=${systemName} "
args += "--build-arg BUILD_SCHEMA=${build_schema} "
def image = docker.build(imageTag, "${args} ${contextDir}")
image.push()
if (branchName == "master" || branchName == "master--master") {
image.push('latest')
}
def build_schema = "BUILD_TIME:${timeStemp}@BUILD_NUMBER:${buildNumber}@SYSTEM_NAME:${systemName}@BRANCH_NAME:${branchName}@CLUSTER:${cluster}"
echo build_schema
def args = ""
args += "--build-arg BUILD_TIME=${timeStemp} "
args += "--build-arg BUILD_NUMBER=${buildNumber} "
args += "--build-arg SYSTEM_NAME=${systemName} "
args += "--build-arg BRANCH_NAME=${branchName} "
args += "--build-arg SAFE_SYSTEM_NAME=${systemName} "
args += "--build-arg BUILD_SCHEMA=${build_schema} "
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")
}
}
}
}
def deploy(namespace, systemName, imageTag, tier, isDeploy) {
stage('Deploy To K8s Cluster'){
def deploy_job_info
stage('Deploy To K8s Cluster'){
def deploy_job_info
if (isDeploy=="true") {
_utils().beautyEcho("[新集群][deployV2]将镜像更新到到Namespace:" + namespace, "info")
update_microservice(namespace, systemName, imageTag, tier)
update_microservice(namespace, systemName, imageTag, tier)
}else{
_utils().beautyEcho( "isDeploy == false,不执行deploy","info")
_utils().beautyEcho( "isDeploy == false,不执行deploy","info")
}
}
}
}
/*def dockerbuild_and_push(timeNow, buildNumber, branchName, harborGroup, systemName, contextDir) {
......
......@@ -5,98 +5,98 @@ def call(body) {
ansiColor('xterm') {
def harborGroup = "library"
def _stage = new org.qg.docker_new.StageBucket()
def _utils = new org.qg.docker_new.Utils()
def harborGroup = "library"
def _stage = new org.qg.docker_new.StageBucket()
def _utils = new org.qg.docker_new.Utils()
def config = [:]
def timeStemp = new Date().format("yyyyMMddHHmmss")
def env = body.env
def gitRepo = env.GIT_REPO
def originBranchName = env.BRANCH_NAME
def namespace = env.NAMESPACE
def isDeploy = env.IS_DEPLOY
def buildNumber = env.BUILD_NUMBER
def cluster = env.CLUSTER
// QG/XXX or QG--QG/systemName--systemName
t = gitRepo.split("/")
def gitGroup = t[0]
// systemName or systemName--systemName
def originSystemName = t[1]
// ["",""]
def systemNames = originSystemName.split("--")
def branchNames = originBranchName.split("--")
def contextDir
def imageTag
def config = [:]
def timeStemp = new Date().format("yyyyMMddHHmmss")
def env = body.env
def gitRepo = env.GIT_REPO
def originBranchName = env.BRANCH_NAME
def namespace = env.NAMESPACE
def isDeploy = env.IS_DEPLOY
def buildNumber = env.BUILD_NUMBER
def cluster = env.CLUSTER
// QG/XXX or QG--QG/systemName--systemName
t = gitRepo.split("/")
def gitGroup = t[0]
// systemName or systemName--systemName
def originSystemName = t[1]
// ["",""]
def systemNames = originSystemName.split("--")
def branchNames = originBranchName.split("--")
def contextDir
def imageTag
body.resolveStrategy = Closure.DELEGATE_FIRST
body.delegate = config
body()
body.resolveStrategy = Closure.DELEGATE_FIRST
body.delegate = config
body()
node {
try {
echo config.buildType
/* 1 */
stage('Init') {
_utils.beautyEcho("Init", "stage")
contextDir = _stage.contextMkdir("${originSystemName}-${timeStemp}")
_stage.before_prepare()
}
try {
echo config.buildType
/* 1 */
stage('Init') {
_utils.beautyEcho("Init", "stage")
contextDir = _stage.contextMkdir("${originSystemName}-${timeStemp}")
_stage.before_prepare()
}
/* 2 */
withDockerServer([uri: "tcp://192.168.4.96:2375/"]) {
_utils.beautyEcho("checkout & build < ${originSystemName} : ${originBranchName} >", "stage")
/* 2 */
withDockerServer([uri: "tcp://192.168.4.96:2375/"]) {
_utils.beautyEcho("checkout & build < ${originSystemName} : ${originBranchName} >", "stage")
for(def i = 0; i<systemNames.length; i++){
dir(systemNames[i]){
_stage.check_and_build(config.buildType, systemNames[i], branchNames[i], contextDir)
}
dir(systemNames[i]){
_stage.check_and_build(config.buildType, systemNames[i], branchNames[i], contextDir)
}
_utils.beautyEcho("build over", "info")
}
/* 3 */
withDockerServer([uri: "tcp://192.168.4.96:2375/"]) {
_utils.beautyEcho("make docker image", "stage")
def regex = "[`,./;\\[\\]&<>?:\"()|-]+"
_utils.beautyEcho("build over", "info")
}
/* 3 */
withDockerServer([uri: "tcp://192.168.4.96:2375/"]) {
_utils.beautyEcho("make docker image", "stage")
def regex = "[`,./;\\[\\]&<>?:\"()|-]+"
def k8sSystemName = originSystemName.replaceAll("_","-")
def safeBranchName = originBranchName.replaceAll(regex,"_")
imageTag = _stage.imageTag(harborGroup,k8sSystemName,safeBranchName,timeStemp)
def _systemName = originSystemName.toLowerCase()
_stage.dockerbuild_and_push(imageTag,buildNumber,_systemName,originBranchName ,cluster,timeStemp)
_utils.beautyEcho("Deploy To K8s Cluster image: ${imageTag} to:${namespace}", "stage")
_stage.deploy(namespace, _systemName, imageTag, config.tier, isDeploy)
imageTag = _stage.imageTag(harborGroup,k8sSystemName,safeBranchName,timeStemp)
}
/* 4 */
stage('Clean'){
_utils.beautyEcho("Clear Cache Tmp", "stage")
_stage.clean_images(imageTag,contextDir)
}
def _systemName = originSystemName.toLowerCase()
_stage.dockerbuild_and_push(imageTag,buildNumber,_systemName,originBranchName ,cluster,timeStemp)
_utils.beautyEcho("Deploy To K8s Cluster image: ${imageTag} to:${namespace}", "stage")
_stage.deploy(namespace, _systemName, imageTag, config.tier, isDeploy)
}
/* 4 */
stage('Clean'){
_utils.beautyEcho("Clear Cache Tmp", "stage")
_stage.clean_images(imageTag,contextDir)
}
} catch (err) {
_utils.beautyEcho(err, "fail")
_stage.clean_images(imageTag,contextDir)
throw err
}
} catch (err) {
_utils.beautyEcho(err, "fail")
_stage.clean_images(imageTag,contextDir)
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