ruby-ex/deployment/pipeline.groovy

63 lines
2.4 KiB
Groovy
Raw Normal View History

2016-12-09 13:53:29 +00:00
import org.yaml.snakeyaml.Yaml
2016-12-09 14:52:57 +00:00
import org.yaml.snakeyaml.constructor.Constructor
2016-12-09 13:43:49 +00:00
2016-12-07 23:28:53 +00: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 09:10:10 +00:00
2016-12-09 11:51:26 +00:00
def getReplicasOrDefault(deploymentConfig, project, defaultReplicas) {
2016-12-07 23:28:53 +00:00
def ocCmd = getOcCmd()
2016-12-08 16:39:48 +00:00
def replicas = sh(script: "${ocCmd} get dc ${deploymentConfig} --template='{{ .spec.replicas }}' -n ${project} || true", returnStdout: true).trim()
2016-12-09 11:51:26 +00:00
return replicas ?: defaultReplicas
2016-12-07 23:26:40 +00:00
}
2016-12-07 23:24:05 +00:00
2016-12-09 14:18:30 +00:00
@NonCPS
2016-12-09 14:23:17 +00:00
def getConfig() {
2016-12-09 15:10:07 +00:00
def yamlAsString = "{JYaml: Original Java Implementation, JvYaml: Java port of RbYaml, SnakeYAML: Java 5 / YAML 1.1, YamlBeans: To/from JavaBeans}"
2016-12-09 15:13:17 +00:00
return new Yaml().load(readFile("deployment/config.yaml"))
2016-12-09 14:17:10 +00:00
}
2016-12-07 23:26:40 +00:00
node() {
2016-12-07 23:28:53 +00:00
def ocCmd = getOcCmd()
2016-12-09 00:17:44 +00:00
def buildManifest = "deployment/manifests/build.yaml"
def appManifest = "deployment/manifests/app.yaml"
2016-12-09 13:33:03 +00:00
stage("Build") {
2016-12-07 22:21:17 +00:00
git "https://github.com/omallo/ruby-ex.git"
2016-12-09 14:55:28 +00:00
2016-12-09 15:11:15 +00:00
println readFile("deployment/config.yaml")
2016-12-09 14:55:28 +00:00
println "teeeeeest start"
def config = getConfig()
println config.getClass()
println "teeeeeest end"
2016-12-09 00:17:44 +00:00
sh "${ocCmd} process -f ${buildManifest} -n rubex-dev | ${ocCmd} apply -f - -n rubex-dev"
2016-12-06 09:10:10 +00:00
sh "${ocCmd} start-build frontend -w -n rubex-dev"
2016-12-05 14:32:22 +00:00
}
2016-12-09 13:33:03 +00:00
stage("Deploy to DEV") {
2016-12-09 11:51:26 +00: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 09:10:10 +00: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 14:32:22 +00:00
}
def isPromoteToTest = false
2016-12-09 13:33:03 +00:00
stage("Promote to TEST?") {
isPromoteToTest = input(message: "Promotion", parameters: [booleanParam(defaultValue: false, name: "Promote to TEST?")])
2016-12-05 14:32:22 +00:00
}
if (isPromoteToTest) {
2016-12-09 13:33:03 +00:00
stage("Deploy to TEST") {
2016-12-09 11:51:26 +00: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 09:10:10 +00: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 14:32:22 +00:00
}
}
}