1 #!/usr/bin/env groovy
\r
3 /* Copyright (c) 2019 AT&T Intellectual Property. #
\r
5 # Licensed under the Apache License, Version 2.0 (the "License"); #
\r
6 # you may not use this file except in compliance with the License. #
\r
7 # You may obtain a copy of the License at #
\r
9 # http://www.apache.org/licenses/LICENSE-2.0 #
\r
11 # Unless required by applicable law or agreed to in writing, software #
\r
12 # distributed under the License is distributed on an "AS IS" BASIS, #
\r
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
\r
14 # See the License for the specific language governing permissions and #
\r
15 # limitations under the License. #
\r
16 ##############################################################################*/
\r
18 properties([[$class: 'ParametersDefinitionProperty', parameterDefinitions: [
\r
19 [$class: 'hudson.model.StringParameterDefinition', name: 'PHASE', defaultValue: "BUILD"],
\r
20 [$class: 'hudson.model.StringParameterDefinition', name: 'ENV', defaultValue: "dev"],
\r
21 [$class: 'hudson.model.StringParameterDefinition', name: 'MECHID', defaultValue: "username"],
\r
22 [$class: 'hudson.model.StringParameterDefinition', name: 'KUBE_CONFIG', defaultValue: "kubeConfig-dev"],
\r
23 [$class: 'hudson.model.StringParameterDefinition', name: 'OTF_MONGO_DB', defaultValue: "otf_mongo_dev_db"],
\r
24 [$class: 'hudson.model.StringParameterDefinition', name: 'OTF_CAMUNDA_DB', defaultValue: "otf_camunda_dev_db"],
\r
25 [$class: 'hudson.model.StringParameterDefinition', name: 'TILLER_NAMESPACE', defaultValue: ""]
\r
28 echo "Build branch: ${env.BRANCH_NAME}"
\r
33 PHASES=PHASE.tokenize( '_' );
\r
34 echo "PHASES : " + PHASES
\r
37 ARTIFACT_ID="otf-frontend";
\r
38 VERSION="Camille.1.0.3";
\r
39 //TODO: deal with namespace and docker registry
\r
43 if( ENV.equalsIgnoreCase("dev") ){
\r
44 IMAGE_NAME=DOCKER_REGISTRY + "/" + NAMESPACE + "/" + ARTIFACT_ID + ":" + VERSION
\r
46 if( ENV.equalsIgnoreCase("prod") || ENV.equalsIgnoreCase("prod-dr")){
\r
47 IMAGE_NAME=DOCKER_REGISTRY + "/" + NAMESPACE + ".prod" + "/" + ARTIFACT_ID + ":" + VERSION
\r
49 if( ENV.equalsIgnoreCase("st") ){
\r
50 IMAGE_NAME=DOCKER_REGISTRY + "/" + NAMESPACE + ".st" + "/" + ARTIFACT_ID + ":" + VERSION
\r
52 echo "Artifact: " + IMAGE_NAME
\r
54 withEnv(["PATH=${env.PATH}:${env.WORKSPACE}/linux-amd64", "HELM_HOME=${env.WORKSPACE}"]) {
\r
56 echo "PATH=${env.PATH}"
\r
57 echo "HELM_HOME=${env.HELM_HOME}"
\r
59 withCredentials([usernamePassword(credentialsId: MECHID, usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
\r
62 // docker login $DOCKER_REGISTRY --username $USERNAME --password $PASSWORD
\r
65 if (PHASES.contains("BUILD")){
\r
66 stage 'Publish Artifact'
\r
69 echo "Artifact: " + IMAGE_NAME
\r
72 docker login $DOCKER_REGISTRY --username $USERNAME --password $PASSWORD
\r
73 docker build --no-cache -t $IMAGE_NAME .
\r
74 docker push $IMAGE_NAME
\r
81 if (PHASES.contains("DEPLOY") || PHASES.contains("UNDEPLOY")) {
\r
85 //check if helm exists if not install
\r
86 if(fileExists('linux-amd64/helm')){
\r
88 echo "helm is already installed"
\r
94 echo "installing helm"
\r
95 wget https://storage.googleapis.com/kubernetes-helm/helm-v2.8.2-linux-amd64.tar.gz
\r
96 tar -xf helm-v2.8.2-linux-amd64.tar.gz
\r
97 rm helm-v2.8.2-linux-amd64.tar.gz
\r
101 withCredentials([file(credentialsId: KUBE_CONFIG, variable: 'KUBECONFIG')]) {
\r
104 //check if charts are valid, and then perform dry run, if successful then upgrade/install charts
\r
106 if (PHASES.contains("UNDEPLOY") ) {
\r
110 helm delete --tiller-namespace=$TILLER_NAMESPACE --purge $ARTIFACT_ID
\r
114 //NOTE Double quotes are used below to access groovy variables like artifact_id and tiller_namespace
\r
115 if (PHASES.contains("DEPLOY") ){
\r
118 usernamePassword(credentialsId: OTF_MONGO_DB, usernameVariable: 'USERNAME_MONGO', passwordVariable: 'PASSWORD_MONGO'),
\r
119 usernamePassword(credentialsId: 'FEATHERS_AUTH', usernameVariable: 'USER', passwordVariable: 'AUTHENTICATION_SECRET')
\r
123 echo "Validate Yaml"
\r
124 helm lint $ARTIFACT_ID
\r
126 echo "View Helm Templates"
\r
127 helm template $ARTIFACT_ID \
\r
128 --set appName=$ARTIFACT_ID \
\r
129 --set version=$VERSION \
\r
130 --set image=$IMAGE_NAME \
\r
131 --set namespace=$TILLER_NAMESPACE \
\r
133 --set AUTHENTICATION_SECRET=$AUTHENTICATION_SECRET \
\r
134 --set mongo.username=$USERNAME_MONGO \
\r
135 --set mongo.password=$PASSWORD_MONGO
\r
137 echo "Perform Dry Run Of Install"
\r
138 helm upgrade --tiller-namespace=$TILLER_NAMESPACE --install --dry-run $ARTIFACT_ID $ARTIFACT_ID \
\r
139 --set appName=$ARTIFACT_ID \
\r
140 --set version=$VERSION \
\r
141 --set image=$IMAGE_NAME \
\r
142 --set namespace=$TILLER_NAMESPACE \
\r
144 --set AUTHENTICATION_SECRET=$AUTHENTICATION_SECRET \
\r
145 --set mongo.username=$USERNAME_MONGO \
\r
146 --set mongo.password=$PASSWORD_MONGO
\r
148 echo "Helm Install/Upgrade"
\r
149 helm upgrade --tiller-namespace=$TILLER_NAMESPACE --install --timeout 1000 $ARTIFACT_ID $ARTIFACT_ID \
\r
150 --set appName=$ARTIFACT_ID \
\r
151 --set version=$VERSION \
\r
152 --set image=$IMAGE_NAME \
\r
153 --set namespace=$TILLER_NAMESPACE \
\r
155 --set AUTHENTICATION_SECRET=$AUTHENTICATION_SECRET \
\r
156 --set mongo.username=$USERNAME_MONGO \
\r
157 --set mongo.password=$PASSWORD_MONGO
\r