Bläddra i källkod

debug, см. Redmine 186407

Tomishinets Vladimir 3 år sedan
förälder
incheckning
4236035f19
2 ändrade filer med 81 tillägg och 59 borttagningar
  1. 2 1
      Dockerfile
  2. 79 58
      Jenkinsfile-dev

+ 2 - 1
Dockerfile

@@ -1,4 +1,5 @@
 FROM registry.sdsys.ru/build-image:alpine-3.10-2 as build
+ARG git_repo=git@github.com:icruportal/web-registration.git
 ARG branch=release
 ARG gradle_version=5.2.1
 COPY id_rsa /root/.ssh
@@ -6,7 +7,7 @@ RUN export GRADLE_HOME=/opt/gradle/gradle-${gradle_version} \
     && export PATH=${GRADLE_HOME}/bin:${PATH} \
     && gradle -v \
     && printf "Host github.com \n\tStrictHostKeyChecking no" > /root/.ssh/config \
-    && git clone git@github.com:icruportal/web-registration.git \
+    && git clone ${git_repo} \
     && cd web-registration && git checkout ${branch} \
     && echo $(git log -p -1 --pretty=format:"%h"|head -n1) > /tmp/version  \
     && cd customer-api && mvn clean install \

+ 79 - 58
Jenkinsfile-dev

@@ -1,3 +1,6 @@
+def REPO=''
+def DOCKER_IMAGE=''
+def SERVICE_NAME=''
 pipeline {
   agent {
     label "swarm"
@@ -7,7 +10,12 @@ pipeline {
     timeout(time: 20, unit: 'MINUTES')
   }
   environment {
-    DOCKER_IMAGE='iru/promo'
+    SERVICE_NAME_SDK='info_promo-sdk'
+    DOCKER_IMAGE_SDK='iru/promo-sdk'
+    GIT_REPO_SDK='git@github.com:icruportal/web-sdk-demo.git'
+    SERVICE_NAME_SEO='info_promo-seo'
+    DOCKER_IMAGE_SEO='iru/promo-seo'
+    GIT_REPO_SEO='git@github.com:icruportal/web-registration.git'
     SWARM_GIT_URL='ssh://git@git.sdsys.ru:8022/iru/stack-deploy.git'
     SWARM_GIT_NAME='stack-deploy'
     JENKINS_MAIL='jenkins@sdsys.ru'
@@ -18,16 +26,15 @@ pipeline {
     NEWTAG=''
   }
   parameters {
+    choice (
+      choices: 'promo-sdk\npromo-seo',
+      description: 'Which repo to use?',
+      name: 'GIT_REPO')
     string(
       name: "branch",
       defaultValue: "release",
       description: "Which branch to use"
     )
-    string(
-      name: "service_update",
-      defaultValue: "info_promo",
-      description: "Services to update."
-    )
     string(
       name: "mailto",
       defaultValue: "admin@sdsys.ru",
@@ -35,69 +42,83 @@ pipeline {
     )
   }
   stages {
-    stage("Build") {
+    stage("Calculate Variables") {
       steps {
-        echo "Building ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${BUILD_NUMBER}."
-        withCredentials([sshUserPrivateKey(credentialsId: 'provision', keyFileVariable: 'GIT_SSH_KEY', passphraseVariable: '', usernameVariable: 'GIT_SSH_USERNAME')]) {
-          sh """set +x
-                cat ${GIT_SSH_KEY} > ${WORKSPACE}/id_rsa 
-                chmod 600 ${WORKSPACE}/id_rsa
-             """
-        }
-        sh "docker build --build-arg branch=${branch} --no-cache -t ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${BUILD_NUMBER} ."
         script {
-           NEWTAG = sh(script: "docker run --rm ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${BUILD_NUMBER} cat /tmp/version 2> /dev/null", returnStdout: true).trim()
-           NEWTAG = branch + "-" + NEWTAG + "_" + BUILD_NUMBER
-           echo "NEWTAG is $NEWTAG"
+          switch (GIT_REPO) {
+            case 'promo-sdk':
+              REPO=${GIT_REPO_SDK}
+              DOCKER_IMAGE=${DOCKER_IMAGE_SDK}
+              SERVICE_NAME=${SERVICE_NAME_SDK}
+              break
+            case 'promo-seo':
+              REPO=${GIT_REPO_SEO}
+              DOCKER_IMAGE=${DOCKER_IMAGE_SEO}
+              SERVICE_NAME=${SERVICE_NAME_SEO}
+              break
+          }
         }
-        sh "docker tag ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${BUILD_NUMBER} ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${NEWTAG}"
-      }
-    }
-    stage("Publish") {
-      steps {
-        echo "Publishing ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${NEWTAG}"
-        sh "docker push ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${NEWTAG}"
       }
     }
-    stage("Update") {
-      when { expression { service_update != "" } }
+    stage("Build") {
       steps {
         script {
-          for (String item : service_update.split()) {
-            echo "Updating ${item}"
-            try{
-               sh "DOCKER_HOST=${DHOST} docker service update ${item} --image ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${NEWTAG}"
-            }
-            catch(err){
-               echo "Recovering service $item"
-               sh "DOCKER_HOST=${DHOST} docker service rollback ${item}"
-               throw err
-            }
+          echo "Building ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${BUILD_NUMBER}."
+          withCredentials([sshUserPrivateKey(credentialsId: 'provision', keyFileVariable: 'GIT_SSH_KEY', passphraseVariable: '', usernameVariable: 'GIT_SSH_USERNAME')]) {
+            sh """set +x
+                  cat ${GIT_SSH_KEY} > ${WORKSPACE}/id_rsa
+                  chmod 600 ${WORKSPACE}/id_rsa
+               """
           }
+          sh "docker build --build-arg branch=${branch} --build-arg git_repo=${REPO} --no-cache -t ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${BUILD_NUMBER} ."
+          NEWTAG = sh(script: "docker run --rm ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${BUILD_NUMBER} cat /tmp/version 2> /dev/null", returnStdout: true).trim()
+          NEWTAG = branch + "-" + NEWTAG + "_" + BUILD_NUMBER
+          echo "NEWTAG is $NEWTAG"
+          sh "docker tag ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${BUILD_NUMBER} ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${NEWTAG}"
         }
       }
     }
-    stage("Tagging"){
-      steps{
-        echo "Setting latest tag"
-        sh """docker tag ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${NEWTAG} ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:latest
-              docker push ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:latest"""
-        echo "Updating tag info in ${SWARM_GIT_NAME} repository"
-        withCredentials([sshUserPrivateKey(credentialsId: 'provision', keyFileVariable: 'GIT_SSH_KEY', passphraseVariable: '', usernameVariable: 'GIT_SSH_USERNAME')]) {
-          sh """GIT_SSH_COMMAND='ssh -i ${GIT_SSH_KEY} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' \
-                  git clone ${SWARM_GIT_URL}
-                cd ${SWARM_GIT_NAME}
-                echo -n ${NEWTAG} > tags/${DOCKER_IMAGE}.dev-version
-                git add -A
-                git config --global user.email "${JENKINS_MAIL}"
-                git config --global user.name "Jenkins"
-                git commit -m 'Version update'
-                GIT_SSH_COMMAND='ssh -i ${GIT_SSH_KEY} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' \
-                  git push origin master
-             """
-        }
-      }
-    }
+    // stage("Publish") {
+    //   steps {
+    //     echo "Publishing ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${NEWTAG}"
+    //     sh "docker push ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${NEWTAG}"
+    //   }
+    // }
+    // stage("Update") {
+    //   steps {
+    //     script {
+    //       try{
+    //          sh "DOCKER_HOST=${DHOST} docker service update ${SERVICE_NAME} --image ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${NEWTAG}"
+    //       }
+    //       catch(err){
+    //          echo "Recovering service $item"
+    //          sh "DOCKER_HOST=${DHOST} docker service rollback ${SERVICE_NAME}"
+    //          throw err
+    //       }
+    //     }
+    //   }
+    // }
+    // stage("Tagging"){
+    //   steps{
+    //     echo "Setting latest tag"
+    //     sh """docker tag ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${NEWTAG} ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:latest
+    //           docker push ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:latest"""
+    //     echo "Updating tag info in ${SWARM_GIT_NAME} repository"
+    //     withCredentials([sshUserPrivateKey(credentialsId: 'provision', keyFileVariable: 'GIT_SSH_KEY', passphraseVariable: '', usernameVariable: 'GIT_SSH_USERNAME')]) {
+    //       sh """GIT_SSH_COMMAND='ssh -i ${GIT_SSH_KEY} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' \
+    //               git clone ${SWARM_GIT_URL}
+    //             cd ${SWARM_GIT_NAME}
+    //             echo -n ${NEWTAG} > tags/${DOCKER_IMAGE}.dev-version
+    //             git add -A
+    //             git config --global user.email "${JENKINS_MAIL}"
+    //             git config --global user.name "Jenkins"
+    //             git commit -m 'Version update'
+    //             GIT_SSH_COMMAND='ssh -i ${GIT_SSH_KEY} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' \
+    //               git push origin master
+    //          """
+    //     }
+    //   }
+    // }
   }
   post {
     always {