Browse Source

Simplify and correct Jenkinsfile

Wadim Surkov 6 years ago
parent
commit
73b5bb97b3
1 changed files with 17 additions and 25 deletions
  1. 17 25
      Jenkinsfile

+ 17 - 25
Jenkinsfile

@@ -1,5 +1,6 @@
 def SERIAL
 def CONTAINER_ID_CLIENT
+def CONTAINER_ID_SERVER
 def ENAMES = [ 'prod', 'dev' ]
 def CLUSTERS = ['prod': 'iru-swarm1-open.infoclinica.lan', 'dev': 'dev-iru-swarm.infoclinica.lan']
 def REGISTRIES = ['prod': 'registry.infoclinica.ru:5000', 'dev': 'dev-registry.infoclinica.ru:5000']
@@ -10,7 +11,7 @@ pipeline {
   }
   environment {
     DOCKER_REGISTRY='dev-registry.infoclinica.ru:5000'
-    DOCKER_IMAGE='ovpn-rsa'
+    DOCKER_IMAGE='iru/ovpn-rsa'
     SERVICE_NAME='ovpn-rsa_server'
     SWARM_GIT_URL='ssh://git@git.sdsys.ru:8022/iru/stack-deploy.git'
     SWARM_GIT_NAME='stack-deploy'
@@ -23,12 +24,12 @@ pipeline {
   parameters {
     string(
       name: "branch",
-      defaultValue: "97009",
+      defaultValue: "master",
       description: "Which branch to use"
     )
     string(
       name: "mailto",
-      defaultValue: "tomishinets.v@sdsys.ru",
+      defaultValue: "admin@sdsys.ru",
       description: "Email which has to be notified."
     )
   }
@@ -55,19 +56,17 @@ pipeline {
                 ${WORKSPACE}/openvpn-pki/open/easy-rsa/keys/sds-test.crt \
                 ${WORKSPACE}/openvpn-pki/open/easy-rsa/keys/sds-test.key \
                 ${WORKSPACE}/openvpn-pki/open/easy-rsa/keys/ta.key \
-                ${WORKSPACE}/openvpn-pki/open/easy-rsa/keys/stonevpn.crl \
                 ${WORKSPACE}/openvpn-pki/open/easy-rsa/keys/dh2048.pem \
                 ${WORKSPACE}/openvpn/keys
                 ls -al ${WORKSPACE}/openvpn/keys/
+                cp ${WORKSPACE}/openvpn-pki/open/easy-rsa/keys/stonevpn.crl ${WORKSPACE}/openvpn/persist
              '''
       }
     }
     stage("Build") {
       steps {
         echo "Building ${DOCKER_IMAGE}:${SERIAL}."
-        sh """docker build --no-cache -t ${DOCKER_IMAGE}:${SERIAL} .
-              if [ \$? != 0 ]; then echo 'The container was not built'; exit 1; fi
-           """
+        sh "docker build --no-cache -t ${DOCKER_IMAGE}:${SERIAL} ."
       }
     }
     stage ("Push to registry") {
@@ -75,29 +74,21 @@ pipeline {
         script {
           ENAMES.each { item ->
              echo "Pushing to: ${item}, CLUSTER ${CLUSTERS.get((item))}"
-             sh """docker tag ${DOCKER_IMAGE}:${SERIAL} ${REGISTRIES.get((item))}/iru/${DOCKER_IMAGE}:${SERIAL}
-                   docker push ${REGISTRIES.get((item))}/iru/${DOCKER_IMAGE}:${SERIAL}
+             sh """docker tag ${DOCKER_IMAGE}:${SERIAL} ${REGISTRIES.get((item))}/${DOCKER_IMAGE}:${SERIAL}
+                   docker push ${REGISTRIES.get((item))}/${DOCKER_IMAGE}:${SERIAL}
                 """
           }
         }
       }
     }
-    stage("Run in Prod-like") {
+    stage("Staging test") {
       steps {
         script {
-          echo "Check Prod-like cluster status"
-          sh "echo -n \${SERIAL} > \${SWARM_GIT_NAME}/tags/\${DOCKER_IMAGE}.version" 
-          sh """cd \${SWARM_GIT_NAME}/\${DOCKER_IMAGE}
-                DOCKER_HOST=tcp://${CLUSTERS.get((ENAMES[1]))}:2376 DOCKER_TLS_VERIFY=1 ./ovpn-rsa-open-staging.sh
-             """
-          def NODE = sh (script: "DOCKER_HOST=tcp://${CLUSTERS.get((ENAMES[1]))}:2376 DOCKER_TLS_VERIFY=1 docker service ps \${SERVICE_NAME} --format '{{.Node}}' --filter desired-state=Running" , returnStdout: true).trim()
-          echo "${NODE}"
-          CONTAINER_ID_CLIENT = sh (script: "docker run -e mode=client -e server=${NODE} --privileged -d --rm  ${DOCKER_IMAGE}:${SERIAL}" , returnStdout: true).trim()
+          CONTAINER_ID_SERVER = sh (script: "docker run -d --rm -e mode=server --privileged ${DOCKER_IMAGE}:${SERIAL}", returnStdout: true).trim()
+          CONTAINER_ID_CLIENT = sh (script: "docker run -d --rm -e mode=client server=127.0.0.1 --privileged -d --rm  ${DOCKER_IMAGE}:${SERIAL}" , returnStdout: true).trim()
           sh """docker exec -t ${CONTAINER_ID_CLIENT} ping -c 3 -q 10.10.20.1
                 if [ \$? != 0 ]; then exit 1; else echo 'OVPN_RSA is working!!!'; fi
              """
-          
-             
         }
       }
     }
@@ -106,8 +97,8 @@ pipeline {
         script {
           ENAMES.each { item ->
              echo "Setting latest tag for $item"
-             sh """docker tag ${DOCKER_IMAGE}:${SERIAL} ${REGISTRIES.get((item))}/iru/${DOCKER_IMAGE}:latest
-                   docker push ${REGISTRIES.get((item))}/iru/${DOCKER_IMAGE}:latest
+             sh """docker tag ${DOCKER_IMAGE}:${SERIAL} ${REGISTRIES.get((item))}/${DOCKER_IMAGE}:latest
+                   docker push ${REGISTRIES.get((item))}/${DOCKER_IMAGE}:latest
                 """
           }
         }
@@ -118,7 +109,7 @@ pipeline {
                 git add -A
                 git config --global user.email "${JENKINS_MAIL}"
                 git config --global user.name "Jenkins"
-                git commit -m 'Version update'
+                git commit -m '${DOCKER_IMAGE} version update'
                 GIT_SSH_COMMAND='ssh -i ${GIT_SSH_KEY} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' \
                 git push origin master
              """
@@ -129,7 +120,8 @@ pipeline {
   post {
     always {
       sh "docker stop ${CONTAINER_ID_CLIENT}"
-      sh "DOCKER_HOST=tcp://${CLUSTERS.get((ENAMES[1]))}:2376 DOCKER_TLS_VERIFY=1 docker stack rm ${DOCKER_IMAGE}"
+      sh "docker stop ${CONTAINER_ID_SERVER}"
+      sh "docker image rm ${DOCKER_IMAGE}:${SERIAL}"
       echo "CleaningUp work directory"
       deleteDir()
     }
@@ -148,4 +140,4 @@ pipeline {
            body: "<b>Congradulations!!!</b> <b><br> Jenkins job succefully finished.\n\n <b><br>Project Name:</b> ${env.JOB_NAME} <b><br>\nBuild Number:</b> ${env.BUILD_NUMBER} <b><br>\nURL Build:</b> ${RUN_DISPLAY_URL}"
     }
   }
-}
+}