Browse Source

See Redmine 116244

Владимир Томишинец 5 years ago
parent
commit
f2b8759209
2 changed files with 63 additions and 34 deletions
  1. 31 17
      updateToTargetVersionJenkinsfile
  2. 32 17
      updateVersionJenkinsfile

+ 31 - 17
updateToTargetVersionJenkinsfile

@@ -1,10 +1,20 @@
-// def ENAMES = [ 'prod', 'dev' ]
-def ENAMES = [ 'prod' ]
-def CLUSTERS = ['prod': 'iru-swarm.infoclinica.lan', 'dev': 'dev-iru-swarm.infoclinica.lan']
-def REGISTRIES = ['prod': 'registry.infoclinica.ru:5000', 'dev': 'dev-registry.infoclinica.ru:5000']
-def DHOST = ['prod': 'tcp://iru-swarm.infoclinica.lan:2376', 'dev': 'tcp://dev-iru-swarm.infoclinica.lan:2376']
-def LIST_SERVICE = []
-def TO_ROLLBACK = []
+def ENAMES = [ 'prod-open', 'prod' ]
+//def def ENAMES = [ 'dev-open', 'dev' ]
+def CLUSTERS = ['prod': 'iru-swarm.infoclinica.lan',
+                'prod-open': 'iru-swarm1-open.infoclinica.ru',
+                'dev': 'dev-iru-swarm.infoclinica.lan',
+                'dev-open': 'dev-iru-swarm1-open.infoclinica.lan']
+def REGISTRIES = ['prod': 'registry.infoclinica.ru:5000',
+                  'prod-open': 'registry.infoclinica.ru:5000',
+                  'dev': 'dev-registry.infoclinica.ru:5000',
+                  'dev-open': 'dev-registry.infoclinica.ru:5000']
+def DHOST = ['prod': 'tcp://iru-swarm.infoclinica.lan:2376',
+             'prod-open': 'tcp://iru-swarm1-open.infoclinica.ru:2376',
+             'dev': 'tcp://dev-iru-swarm.infoclinica.lan:2376',
+             'dev-open': 'tcp://dev-iru-swarm1-open.infoclinica.lan:2376']
+
+def LIST_SERVICE = [:]
+def TO_ROLLBACK = [:]
 def ERROR_JOB
 def VERSION_TO_UPDATE
 pipeline {
@@ -23,7 +33,7 @@ pipeline {
   parameters {
     string(
       name: "mailto",
-      defaultValue: "admin@sdsys.ru",
+      defaultValue: "admin.v@sdsys.ru",
       description: "Email which has to be notified."
     )
     string(
@@ -50,8 +60,8 @@ pipeline {
         script {
           ENAMES.each { item ->
             echo "Viewing: ${item} services, on ${CLUSTERS.get((item))}"
-            LIST_SERVICE = sh (script: "set +x && DOCKER_HOST=${DHOST.get((item))} DOCKER_TLS_VERIFY=1 docker service ls -f label=com.docker.stack.namespace=$STACK_LABEL -f label=ru.infoclinica.service=$SERVICE_LABEL --format '{{.Name}}'" , returnStdout: true).split('\n')
-            echo "These services will be updated $LIST_SERVICE to version $toVersion"
+            LIST_SERVICE[item] = sh (script: "set +x && DOCKER_HOST=${DHOST.get((item))} DOCKER_TLS_VERIFY=1 docker service ls -f label=com.docker.stack.namespace=$STACK_LABEL -f label=ru.infoclinica.service=$SERVICE_LABEL --format '{{.Name}}'" , returnStdout: true).split('\n')
+            echo "These services will be updated ${LIST_SERVICE.get(item)} to version $toVersion"
           }
         }
       }
@@ -60,21 +70,25 @@ pipeline {
       steps {
         script {
           ENAMES.each { item ->
+            TO_ROLLBACK[item] = []
             try {
-              for (name in LIST_SERVICE) {
-                TO_ROLLBACK.add(name)
+              for (name in LIST_SERVICE.get(item)) {
+                TO_ROLLBACK[item].add(name)
+                echo "Update service $name"
                 sh "set +x && DOCKER_HOST=${DHOST.get((item))} DOCKER_TLS_VERIFY=1 docker service update $name --image ${REGISTRIES.get((item))}/lab/$DOCKER_IMAGE:$toVersion"
               }
             }
             catch (err) {
               def STABLE_VERSION = sh (script: "set +x && cat $SWARM_GIT_NAME/tags/lab/analis-wineservice.stable-version" , returnStdout: true).trim()
-              for (names_falure in TO_ROLLBACK) {
-                echo "Recoverig $names_falure to $STABLE_VERSION"
-                sh "set +x && DOCKER_HOST=${DHOST.get((item))} DOCKER_TLS_VERIFY=1 docker service rollback $names_falure"
+              TO_ROLLBACK.each { target, value ->
+                for (service_name in value) {
+                  echo "Recoverig $service_name running in $target to $STABLE_VERSION"
+                  sh "set +x && DOCKER_HOST=${DHOST.get((item))} DOCKER_TLS_VERIFY=1 docker service rollback $service_name"
+                }
               }
-              ERROR_JOB = TO_ROLLBACK.last()
+              ERROR_JOB = TO_ROLLBACK[item][-1]
               currentBuild.result = 'FAILURE'
-              error ("Failure on update $ERROR_JOB. The service $TO_ROLLBACK was rollback!")
+              error ("Failure on update $ERROR_JOB. The service(s) $ERROR_JOB was rollback!")
             }
           }
         }

+ 32 - 17
updateVersionJenkinsfile

@@ -1,12 +1,23 @@
-// def ENAMES = [ 'prod', 'dev' ]
-def ENAMES = [ 'prod' ]
-def CLUSTERS = ['prod': 'iru-swarm.infoclinica.lan', 'dev': 'dev-iru-swarm.infoclinica.lan']
-def REGISTRIES = ['prod': 'registry.infoclinica.ru:5000', 'dev': 'dev-registry.infoclinica.ru:5000']
-def DHOST = ['prod': 'tcp://iru-swarm.infoclinica.lan:2376', 'dev': 'tcp://dev-iru-swarm.infoclinica.lan:2376']
-def LIST_SERVICE = []
-def TO_ROLLBACK = []
+def ENAMES = [ 'prod-open', 'prod' ]
+//def def ENAMES = [ 'dev-open', 'dev' ]
+def CLUSTERS = ['prod': 'iru-swarm.infoclinica.lan',
+                'prod-open': 'iru-swarm1-open.infoclinica.ru',
+                'dev': 'dev-iru-swarm.infoclinica.lan',
+                'dev-open': 'dev-iru-swarm1-open.infoclinica.lan']
+def REGISTRIES = ['prod': 'registry.infoclinica.ru:5000',
+                  'prod-open': 'registry.infoclinica.ru:5000',
+                  'dev': 'dev-registry.infoclinica.ru:5000',
+                  'dev-open': 'dev-registry.infoclinica.ru:5000']
+def DHOST = ['prod': 'tcp://iru-swarm.infoclinica.lan:2376',
+             'prod-open': 'tcp://iru-swarm1-open.infoclinica.ru:2376',
+             'dev': 'tcp://dev-iru-swarm.infoclinica.lan:2376',
+             'dev-open': 'tcp://dev-iru-swarm1-open.infoclinica.lan:2376']
+
+def LIST_SERVICE = [:]
+def TO_ROLLBACK = [:]
 def ERROR_JOB
 def VERSION_TO_UPDATE
+
 pipeline {
   agent {
     label "swarm"
@@ -59,13 +70,13 @@ pipeline {
         script {
           ENAMES.each { item ->
             echo "Viewing: ${item} services, on ${CLUSTERS.get((item))}"
-            LIST_SERVICE = sh (script: "set +x && DOCKER_HOST=${DHOST.get((item))} DOCKER_TLS_VERIFY=1 docker service ls -f label=com.docker.stack.namespace=$STACK_LABEL -f label=ru.infoclinica.service=$SERVICE_LABEL --format '{{.Name}}'" , returnStdout: true).split('\n')
+            LIST_SERVICE[item] = sh (script: "set +x && DOCKER_HOST=${DHOST.get((item))} DOCKER_TLS_VERIFY=1 docker service ls -f label=com.docker.stack.namespace=$STACK_LABEL -f label=ru.infoclinica.service=$SERVICE_LABEL --format '{{.Name}}'" , returnStdout: true).split('\n')
             switch (TASK_ACTION) {
               case 'up':
-                echo "These services will be updated $LIST_SERVICE to version $VERSION_TO_UPDATE"
+                echo "These services will be updated to version $VERSION_TO_UPDATE: ${LIST_SERVICE.get(item)}"
                 break
               case 'down':
-                echo "These services will be downgraded $LIST_SERVICE to version $VERSION_TO_UPDATE"
+                echo "These services will be downgraded to version $VERSION_TO_UPDATE ${LIST_SERVICE.get(item)}"
                 break
             }
           }
@@ -76,21 +87,25 @@ pipeline {
       steps {
         script {
           ENAMES.each { item ->
+            TO_ROLLBACK[item] = []
             try {
-              for (name in LIST_SERVICE) {
-                TO_ROLLBACK.add(name)
+              for (name in LIST_SERVICE.get(item)) {
+                TO_ROLLBACK[item].add(name)
+                echo "Update service $name"
                 sh "set +x && DOCKER_HOST=${DHOST.get((item))} DOCKER_TLS_VERIFY=1 docker service update $name --image ${REGISTRIES.get((item))}/lab/$DOCKER_IMAGE:$VERSION_TO_UPDATE"
               }
             }
             catch (err) {
               def STABLE_VERSION = sh (script: "set +x && cat $SWARM_GIT_NAME/tags/lab/analis-wineservice.stable-version" , returnStdout: true).trim()
-              for (names_falure in TO_ROLLBACK) {
-                echo "Recoverig $names_falure to $STABLE_VERSION"
-                sh "set +x && DOCKER_HOST=${DHOST.get((item))} DOCKER_TLS_VERIFY=1 docker service rollback $names_falure"
+              TO_ROLLBACK.each { target, value ->
+                for (service_name in value) {
+                  echo "Recoverig $service_name running in $target to $STABLE_VERSION"
+                  sh "set +x && DOCKER_HOST=${DHOST.get((item))} DOCKER_TLS_VERIFY=1 docker service rollback $service_name"
+                }
               }
-              ERROR_JOB = TO_ROLLBACK.last()
+              ERROR_JOB = TO_ROLLBACK[item][-1]
               currentBuild.result = 'FAILURE'
-              error ("Failure on update $ERROR_JOB. The service $TO_ROLLBACK was rollback!")
+              error ("Failure on update $ERROR_JOB. The service(s) $ERROR_JOB was rollback!")
             }
           }
         }