Commit 78a1fb02 authored by tywldx's avatar tywldx
parents d3a46911 36e99251
......@@ -237,7 +237,7 @@ def dockerbuild_and_push(timeNow, buildNumber, branchName, harborGroup, systemNa
def build_schema = "BUILD_TIME:${timeNow}@BUILD_NUMBER:${buildNumber}@SYSTEM_NAME:${systemName}@BRANCH_NAME:${branchName}"
echo build_schema
def image = docker.build(imageTag, "--build-arg BUILD_SCHEMA=${build_schema} ${contextDir}")
def image = docker.build(imageTag, "--build-arg SYSTEM_NAME=${systemName} --build-arg BUILD_SCHEMA=${build_schema} ${contextDir}")
image.push()
if (branchName == "master" || branchName == "master--master") {
......
......@@ -28,6 +28,7 @@ def before_prepare() {
}
def prepare_config(buildType,systemName, contextDir) {
_utils().beautyEcho("Prepare Config +++ type:${buildType} systemName:${systemName}", "info")
switch (buildType) {
case "java":
prepare_java(systemName, contextDir)
......@@ -39,10 +40,10 @@ def prepare_config(buildType,systemName, contextDir) {
prepare_python(systemName, contextDir)
break
case "lua-ui":
prepare_luaui(systemNames, contextDir)
prepare_luaui(systemName, contextDir)
break
default:
echo "未知的buildType: ${config.buildType}"
_utils().beautyEcho("未知的buildType: ${buildType}","fail")
break
}
}
......@@ -57,21 +58,20 @@ def prepare_nodejs(systemName, contextDir) {
sh "cp -rf /home/quant_group/config_repository/nodejs/${systemName}.js env.config.js"
}
def prepare_luaui(systemNames, contextDir) {
def prepare_luaui(systemName, contextDir) {
sh "cp -rf /home/quant_group/qg-dockerfiles/templates_new/lua-ui/* ${contextDir}"
sh "cp -rf /home/quant_group/config_repository/lua-ui/lua/*.lua ${contextDir}"
def isVhFileExist = fileExists "/home/quant_group/config_repository/lua-ui/nginx/${systemNames}.vh.conf"
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/${systemNames}.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}"
}
arrSystem = systemNames.split("--")
for (systemName in arrSystem) {
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"
}
def prepare_python(systemName, contextDir) {
......@@ -81,7 +81,7 @@ def prepare_python(systemName, contextDir) {
}
def checkout(buildType,systemName, branchName) {
_utils().beautyEcho("checkout ${buildType} ${systemName} ${branchName}", "info")
_utils().beautyEcho("CheckOut +++ type:${buildType} systemName:${systemName} branchName:${branchName}", "info")
switch(buildType){
case "java":
checkout_java(systemName, branchName)
......@@ -96,7 +96,7 @@ def checkout(buildType,systemName, branchName) {
checkout_luaui(systemName, branchName)
break
default:
echo "未知的buildType: ${config.buildType}"
echo "未知的buildType: ${cbuildType}"
break
}
}
......@@ -128,80 +128,42 @@ def checkout_nodejs(systemName, branchName) {
if (bowerFile) {
sh "bower install --allow-root"
}
sh "npm install -g"
sh "npm install"
}
def checkout_luaui(systemNames, branchNames) {
_utils().beautyEcho("checkout_lua_ui :" + systemNames, "info")
sh "cp -rf /home/quant_group/config_repository/lua-ui/npmrc/npmrc /root/.npmrc"
if(systemNames.contains("--")){
_utils().beautyEcho("complex ui projects :" + systemNames, "info")
t1 = systemNames.split("/")
projects = t1[1].split("--")
branches = branchNames.split("--")
def checkout_luaui(systemName, branchName) {
sh "cp -rf /home/quant_group/config_repository/lua-ui/npmrc/npmrc /root/.npmrc"
_utils().beautyEcho("ui project : ${systemName}" , "info")
projectAttr = project_attr(systemName)
gitPath = projectAttr["gitPath"]
t1.size().times {
/*currentPath = sh (
script: 'pwd',
returnStdout: true
).trim()
dir (projects[it]) {
projectAttr = project_attr(projects[it])
gitPath = projectAttr["gitPath"]
currentPath = sh (
script: 'pwd',
returnStdout: true
).trim()
def folder = new File( "${currentPath}/.git/hooks" )
if( !folder.exists() ) {
git branch: branches[it], 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-merge .git/hooks/"
sh "chmod +x .git/hooks/post-merge"
git branch: branches[it], credentialsId: 'e1ccb1ac-1282-4fb4-b766-530ca1a2a2db', url: gitPath
}
}
}
}
else{
_utils().beautyEcho("simple ui project :" + systemNames, "info")
def systemName = systemNames
def branchName = branchNames
projectAttr = project_attr(systemName)
gitPath = projectAttr["gitPath"]
/*currentPath = sh (
script: 'pwd',
returnStdout: true
).trim()
def folder = new File( "${currentPath}/.git/hooks" )*/
sh "cp -rf /home/quant_group/config_repository/lua-ui/hook/post-merge .git/hooks/"
sh "chmod +x .git/hooks/post-merge"
git branch: branchName, credentialsId: 'e1ccb1ac-1282-4fb4-b766-530ca1a2a2db', url: gitPath
def bowerFile = fileExists './bower.json'
def folder = new File( "${currentPath}/.git/hooks" )*/
if (bowerFile) {
sh "bower install --allow-root"
}
sh "npm install"
sh "cp -rf /home/quant_group/config_repository/lua-ui/hook/post-merge .git/hooks/"
sh "chmod +x .git/hooks/post-merge"
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"
}
}
def build(buildType,systemName, contextDir){
_utils().beautyEcho("Build +++ type:${buildType} systemName:${systemName}", "info")
switch(buildType){
case "java":
build_java(systemName, contextDir)
......@@ -216,7 +178,7 @@ def build(buildType,systemName, contextDir){
build_luaui( systemName, contextDir)
break
default:
echo "未知的buildType: ${config.buildType}"
echo "未知的buildType: ${buildType}"
break
}
......@@ -252,24 +214,17 @@ def build_python( systemName, contextDir) {
sh "mv dist.tgz ${contextDir}"
}
def build_luaui( systemNames, contextDir) {
arrSystem = systemNames.split("--")
for (systemName in arrSystem) {
dir (systemName) {
def res_json = project_attr(systemName)
configPath = res_json["configPath"]
buildCmd = res_json["buildCmd"]
configName = systemName
sh "mv -f ../${systemName}.env.config.js ${configPath}"
sh buildCmd
sh "tar zcf ${systemName}.tgz dist/"
sh "mv ${systemName}.tgz ../${contextDir}"
}
}
def build_luaui( systemName, contextDir) {
def res_json = project_attr(systemName)
configPath = res_json["configPath"]
buildCmd = res_json["buildCmd"]
configName = systemName
sh "mv -f ./${systemName}.env.config.js ${configPath}"
sh buildCmd
sh "tar zcf ${systemName}.tgz dist/"
sh "mv ${systemName}.tgz ${contextDir}"
}
def dockerbuild_and_push(timeNow, buildNumber, branchName, harborGroup, systemName, contextDir) {
......@@ -334,8 +289,8 @@ def update_microservice(namespace, name, image, tier) {
requestBody:"""{
"namespace":"${namespace}",
"name":"${name}",
"image":"${image}",
"tier":"${tier}"
"image":"${image}",
"tier":"${tier}"
}""",
url:dest_url
......@@ -343,40 +298,36 @@ def update_microservice(namespace, name, image, tier) {
return res_json
}
def getDocketPackageImage(buildType){
echo "getDocketPackageImage :${buildType}"
def args =""
def packageImageInfo=[:]
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/pacakge/:/home/quant_group/pacakge/ "
switch (buildType) {
case "java":
def args = "-v /root/.m2:/root/.m2 "
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/pacakge/:/home/quant_group/pacakge/ "
args += "-v /root/.m2:/root/.m2 "
packageImageInfo["image"] = "192.168.4.36/baseimg/jenkins-slave:2018040302"
packageImageInfo["args"] = args
break
case "nodejs":
def args = "-v /root/.npm:/root/.npm "
args += "-v /root/.npm:/root/.npm "
args +="-v /root/.cache:/root/.cache "
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/pacakge/:/home/quant_group/pacakge/ "
packageImageInfo["image"] = "192.168.4.36/baseimg/jenkins-node-slave:2018040402"
packageImageInfo["args"] = ""
packageImageInfo["args"] = args
break
case "python":
packageImageInfo["image"] = ""
packageImageInfo["args"] = ""
break
case "lua-ui":
def args = "-v /root/.npm:/root/.npm "
args += "-v /root/.npm:/root/.npm "
args +="-v /root/.cache:/root/.cache "
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/pacakge/:/home/quant_group/pacakge/ "
packageImageInfo["image"] = "192.168.4.36/baseimg/jenkins-node-slave:2018040402"
packageImageInfo["args"] = args
break
......@@ -392,4 +343,48 @@ def getDocketPackageImage(buildType){
return packageImageInfo
}
def checkAndBuild(buildType,systemName,branchName,contextDir){
def pacegeDockerInfo = getDocketPackageImage(buildType)
docker.image(pacegeDockerInfo["image"]).inside(pacegeDockerInfo["args"]){
try{
/*checkout code*/
checkout(buildType, systemName, branchName)
/*prepare config*/
prepare_config(buildType, systemName, contextDir)
/*build*/
build(buildType, systemName, contextDir)
} catch(err){
sleep 120
throw err
}
}
}
def dockerMake(imageTag,buildNumber,systemName,branchName,cluster,timeStemp){
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 image = docker.build(imageTag, "--build-arg SYSTEM_NAME=${systemName} --build-arg BUILD_SCHEMA=${build_schema} ${contextDir}")
image.push()
if (branchName == "master" || branchName == "master--master") {
image.push('latest')
}
}
}
......@@ -40,6 +40,7 @@ def call(body) {
try {
echo config.buildType
/* 1 */
stage('prepare') {
_utils.beautyEcho("Prepare", "stage")
contextDir = _stage.contextMkdir("${systemName}-${timeStemp}")
......@@ -47,57 +48,35 @@ def call(body) {
}
/* 2 */
withDockerServer([uri: "tcp://192.168.4.96:2375/"]) {
stage('checkout & build') {
_utils.beautyEcho("checkout & build", "stage")
def pacegeDockerInfo = _stage.getDocketPackageImage(config.buildType)
docker.image(pacegeDockerInfo["image"]).inside(pacegeDockerInfo["args"]){
def project_attr = _stage.project_attr(systemName)
def gitPath = project_attr["gitPath"]
/*checkout code*/
_utils.beautyEcho("checkout", "info")
_stage.checkout(config.buildType, systemName, branchName)
/*prepare config*/
_utils.beautyEcho("prepare config", "info")
_stage.prepare_config(config.buildType, systemName, contextDir)
/*build*/
_utils.beautyEcho("build", "info")
_stage.build(config.buildType, systemName, contextDir)
arrSystem = systemName.split("--")
for (systemNameSimple in arrSystem) {
_stage.checkAndBuild(config.buildType, systemNameSimple, branchName, contextDir)
}
_utils.beautyEcho("build over", "info")
}
_utils.beautyEcho("build over", "info")
}
/* 3 */
withDockerServer([uri: "tcp://192.168.4.96:2375/"]) {
stage('make docker image') {
_utils.beautyEcho("make docker image", "stage")
imageTag = _stage.imageTag(harborGroup,k8sSystemName,safeBranchName,timeStemp)
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 image = docker.build(imageTag, "--build-arg BUILD_SCHEMA=${build_schema} ${contextDir}")
image.push()
if (branchName == "master" || branchName == "master--master") {
image.push('latest')
}
}
_utils.beautyEcho("make docker image", "stage")
imageTag = _stage.imageTag(harborGroup,k8sSystemName,safeBranchName,timeStemp)
_stage.dockerMake(imageTag,buildNumber,systemName,branchName,cluster,timeStemp)
}
stage('Deploy To K8s Cluster'){
_utils.beautyEcho("Deploy To K8s Cluster", "stage")
_utils.beautyEcho("Deploy image: ${imageTag} to:${namespace}", "info")
_stage.deploy(namespace, systemName, imageTag, config.tier, isDeploy)
}
......@@ -108,11 +87,11 @@ def call(body) {
}catch (err) {
_utils.beautyEcho(err, "fail")
/* sh "rm -rf ${contextDir}"*/
sh "rm -rf ${contextDir}"
if (imageTag){
_stage.clean_images(imageTag)
}
sleep 120
throw err
......@@ -121,3 +100,6 @@ def call(body) {
}
}
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