ruby-ex/deployment/pipeline.groovy

60 lines
2.2 KiB
Groovy
Raw Normal View History

2016-12-09 14:53:29 +01:00
import org.yaml.snakeyaml.Yaml
2016-12-09 15:52:57 +01:00
import org.yaml.snakeyaml.constructor.Constructor
2016-12-09 14:43:49 +01:00
2016-12-08 00:28:53 +01:00
def getOcCmd() {
return "oc --token=`cat /var/run/secrets/kubernetes.io/serviceaccount/token` --server=https://openshift.default.svc.cluster.local --certificate-authority=/run/secrets/kubernetes.io/serviceaccount/ca.crt"
}
2016-12-06 10:10:10 +01:00
2016-12-09 12:51:26 +01:00
def getReplicasOrDefault(deploymentConfig, project, defaultReplicas) {
2016-12-08 00:28:53 +01:00
def ocCmd = getOcCmd()
2016-12-08 17:39:48 +01:00
def replicas = sh(script: "${ocCmd} get dc ${deploymentConfig} --template='{{ .spec.replicas }}' -n ${project} || true", returnStdout: true).trim()
2016-12-09 12:51:26 +01:00
return replicas ?: defaultReplicas
2016-12-08 00:26:40 +01:00
}
2016-12-08 00:24:05 +01:00
2016-12-09 15:18:30 +01:00
@NonCPS
2016-12-09 15:23:17 +01:00
def getConfig() {
2016-12-09 16:06:48 +01:00
return new Yaml().loadAs(readFile("deployment/config.yaml"), HashMap)
2016-12-09 15:17:10 +01:00
}
2016-12-08 00:26:40 +01:00
node() {
2016-12-08 00:28:53 +01:00
def ocCmd = getOcCmd()
2016-12-09 01:17:44 +01:00
def buildManifest = "deployment/manifests/build.yaml"
def appManifest = "deployment/manifests/app.yaml"
2016-12-09 14:33:03 +01:00
stage("Build") {
2016-12-07 23:21:17 +01:00
git "https://github.com/omallo/ruby-ex.git"
2016-12-09 15:55:28 +01:00
println "teeeeeest start"
def config = getConfig()
println config.getClass()
println "teeeeeest end"
2016-12-09 01:17:44 +01:00
sh "${ocCmd} process -f ${buildManifest} -n rubex-dev | ${ocCmd} apply -f - -n rubex-dev"
2016-12-06 10:10:10 +01:00
sh "${ocCmd} start-build frontend -w -n rubex-dev"
2016-12-05 15:32:22 +01:00
}
2016-12-09 14:33:03 +01:00
stage("Deploy to DEV") {
2016-12-09 12:51:26 +01:00
def replicas = getReplicasOrDefault("frontend", "rubex-dev", 1)
sh "${ocCmd} process -f ${appManifest} -v ENV=dev -v REPLICAS=${replicas} -n rubex-dev | ${ocCmd} apply -f - -n rubex-dev"
2016-12-06 10:10:10 +01:00
sh "${ocCmd} tag rubex-dev/frontend:latest rubex-dev/frontend:dev"
sh "${ocCmd} rollout latest dc/frontend -n rubex-dev"
sh "${ocCmd} rollout status dc/frontend -n rubex-dev"
2016-12-05 15:32:22 +01:00
}
def isPromoteToTest = false
2016-12-09 14:33:03 +01:00
stage("Promote to TEST?") {
isPromoteToTest = input(message: "Promotion", parameters: [booleanParam(defaultValue: false, name: "Promote to TEST?")])
2016-12-05 15:32:22 +01:00
}
if (isPromoteToTest) {
2016-12-09 14:33:03 +01:00
stage("Deploy to TEST") {
2016-12-09 12:51:26 +01:00
def replicas = getReplicasOrDefault("frontend", "rubex-test", 2)
sh "${ocCmd} process -f ${appManifest} -v ENV=test -v REPLICAS=${replicas} -n rubex-test | ${ocCmd} apply -f - -n rubex-test"
2016-12-06 10:10:10 +01:00
sh "${ocCmd} tag rubex-dev/frontend:dev rubex-dev/frontend:test"
sh "${ocCmd} rollout latest dc/frontend -n rubex-test"
sh "${ocCmd} rollout status dc/frontend -n rubex-test"
2016-12-05 15:32:22 +01:00
}
}
}