Browse Source

Add variability of REGISTRY in dependence of cluster

Vadim Surkov 6 years ago
parent
commit
7305123bd0
1 changed files with 24 additions and 23 deletions
  1. 24 23
      Jenkinsfile

+ 24 - 23
Jenkinsfile

@@ -1,10 +1,8 @@
-def NEWTAG
 pipeline {
   agent {
     label "swarm"
   }
   environment {
-    DOCKER_REGISTRY='dev-registry.infoclinica.ru:5000'
     DOCKER_IMAGE='admin'
     SWARM_GIT_URL='ssh://git@git.sdsys.ru:8022/iru/stack-deploy.git'
     SWARM_GIT_NAME='stack-deploy'
@@ -12,6 +10,12 @@ pipeline {
     CLUSTER_DEV='dev-iru-swarm.infoclinica.lan'
     CLUSTER_PROD='iru-swarm.infoclinica.ru'
     PACKAGE_NAME='web-registry-admin'
+    DEV_REGISTRY='dev-registry.infoclinica.ru:5000'
+    PROD_REGISTRY='registry.infoclinica.ru:5000'
+    DOCKER_CERT_PATH='/run/secrets/swarm'
+    DHOST=''
+    DOCKER_REGISTRY=''
+    NEWTAG=''
   }
   parameters {
     string(
@@ -38,6 +42,21 @@ pipeline {
   stages {
     stage("Build") {
       steps {
+        script {
+          switch (cluster) {
+             case 'prod':
+                DOCKER_REGISTRY=PROD_REGISTRY
+                DHOST="tcp://${CLUSTER_PROD}:2376 DOCKER_TLS_VERIFY=1"
+                break
+             case 'dev':
+                DOCKER_REGISTRY=DEV_REGISTRY
+                DHOST="tcp://${CLUSTER_DEV}:2376 DOCKER_TLS_VERIFY=1"
+                break
+             default:
+                currentBuild.result = 'ABORTED'
+                error('Unknown cluster')
+          }
+        }
         echo "Building ${DOCKER_REGISTRY}/iru/${DOCKER_IMAGE}:${repo}-${BUILD_NUMBER}."
         sh "docker build --build-arg repo=${repo} --no-cache -t ${DOCKER_REGISTRY}/iru/${DOCKER_IMAGE}:${repo}-${BUILD_NUMBER} ."
         script {
@@ -58,32 +77,14 @@ pipeline {
       when { expression { service_update != "" } }
       steps {
         script {
-          def CLUSTER_TGT
-          switch (cluster) {
-             case 'prod':
-                CLUSTER_TGT=CLUSTER_PROD
-                break
-             case 'dev':
-                CLUSTER_TGT=CLUSTER_DEV
-                break
-             default:
-                currentBuild.result = 'ABORTED'
-                error('Unknown cluster')
-          }
           for (String item : service_update.split()) {
+            echo "Updating ${item}"
             try{
-              echo "Updating $item, cluster $CLUSTER_TGT"
-              sh """export DOCKER_CERT_PATH=/run/secrets/swarm
-                    export DOCKER_HOST=tcp://${CLUSTER_TGT}:2376 DOCKER_TLS_VERIFY=1
-                    docker service update ${item} --image ${DOCKER_REGISTRY}/iru/${DOCKER_IMAGE}:${NEWTAG}
-                 """
+              sh "DOCKER_HOST=${DHOST} docker service update ${item} --image ${DOCKER_REGISTRY}/iru/${DOCKER_IMAGE}:${NEWTAG}"
             }
             catch(err){
               echo "Recovering service $item"
-              sh """export DOCKER_CERT_PATH=/run/secrets/swarm
-                    export DOCKER_HOST=tcp://${CLUSTER_TGT}:2376 DOCKER_TLS_VERIFY=1
-                    docker service rollback ${item}
-                 """
+              sh "DOCKER_HOST=${DHOST} docker service rollback ${item}"
               throw err
             }
           }