// Jenkinsfile.prod
|
|
// @version 180820:1
|
|
// @author zhangxuhong <zhangxuhong@xitu.io>
|
|
//
|
|
|
|
def appName = "suid-generator"
|
|
def label = "worker-${UUID.randomUUID().toString()}"
|
|
def registryHost = "harbor02.juejin.id/prod/"
|
|
def deployLocation = "prod.kube01.lobj.juejin.id"
|
|
|
|
podTemplate(
|
|
label: label,
|
|
containers: [
|
|
containerTemplate(
|
|
name: 'git',
|
|
image: 'harbor02.juejin.id/infrastructure/git-1.8.3.1-centos:0.0.3',
|
|
command: 'cat',
|
|
ttyEnabled: true
|
|
),
|
|
containerTemplate(
|
|
name: 'dind',
|
|
image: 'harbor02.juejin.id/infrastructure/docker-18.06.0-ce-dind:0.0.2',
|
|
command: 'cat',
|
|
ttyEnabled: true
|
|
),
|
|
containerTemplate(
|
|
name: 'kubectl',
|
|
image: 'harbor02.juejin.id/infrastructure/kubectl-1.11.1-centos-with-cert-cluster01.lobj:latest',
|
|
command: 'cat',
|
|
ttyEnabled: true
|
|
),
|
|
],
|
|
volumes: [
|
|
hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock'),
|
|
],
|
|
cloud: deployLocation
|
|
){
|
|
node(label) {
|
|
// start deploy phrase
|
|
stage("[1/4] check out"){
|
|
container('git'){
|
|
checkout scm
|
|
sh "git rev-parse --short HEAD > commit-id"
|
|
tag = readFile('commit-id').replace("\n", "").replace("\r", "")
|
|
imageName = "${registryHost}${appName}:${tag}"
|
|
env.BUILDIMG=imageName
|
|
}
|
|
}
|
|
stage("[2/4] Build"){
|
|
container('dind'){
|
|
sh "docker version"
|
|
sh "docker build -t ${imageName} ./"
|
|
}
|
|
}
|
|
stage("[3/4] Push"){
|
|
container('dind'){
|
|
sh "/usr/local/bin/docker-login.sh"
|
|
sh "docker push ${imageName}"
|
|
}
|
|
}
|
|
stage("[4/4] Deploy"){
|
|
container('kubectl'){
|
|
sh "sed -i 's#__IMAGE__#$BUILDIMG#g' ./config/kubernetes/Deployment.yaml"
|
|
sh "cat ./config/kubernetes/Deployment.yaml"
|
|
sh "kubectl --kubeconfig=/root/.kube/config apply -f ./config/kubernetes/Service.yaml"
|
|
sh "kubectl --kubeconfig=/root/.kube/config apply -f ./config/kubernetes/Ingress.yaml"
|
|
sh "kubectl --kubeconfig=/root/.kube/config apply -f ./config/kubernetes/Deployment.yaml"
|
|
}
|
|
}
|
|
}
|
|
}
|