Browse Source

change build for k8s

Tomishinets Vladimir 4 years ago
parent
commit
399b055293
4 changed files with 53 additions and 55 deletions
  1. 4 5
      Dockerfile
  2. 43 44
      devK8s.Jenkinsfile
  3. 6 3
      entrypoint.sh
  4. 0 3
      healthcheck.sh

+ 4 - 5
Dockerfile

@@ -1,15 +1,14 @@
 FROM jcr.infoclinica.ru/sys/iru-base:7.6
 FROM jcr.infoclinica.ru/sys/iru-base:7.6
-ENTRYPOINT ["entrypoint.sh"]
-COPY entrypoint.sh healthcheck.sh /usr/share/web-registry-portal/bin/
+ENTRYPOINT ["/entrypoint.sh"]
+COPY entrypoint.sh /
 COPY application-logger.xml application.conf /etc/web-registry-portal/
 COPY application-logger.xml application.conf /etc/web-registry-portal/
-ENV PATH=/usr/share/web-registry-portal/bin:$PATH LANG="en_US.UTF-8" ADMIN_HOST=admin
+ENV PATH="$PATH:/usr/share/web-registry-portal/bin" LANG="en_US.UTF-8" ADMIN_HOST=admin
 EXPOSE 9000 2551 2552
 EXPOSE 9000 2551 2552
 HEALTHCHECK --start-period=30s --interval=20s --timeout=10s --retries=2 CMD healthcheck.sh
 HEALTHCHECK --start-period=30s --interval=20s --timeout=10s --retries=2 CMD healthcheck.sh
 ARG repo=prod
 ARG repo=prod
 RUN set -x \
 RUN set -x \
            && curl https://repo.infoclinica.ru/yum/centos/sds-${repo}-portal.repo -o /etc/yum.repos.d/sds-${repo}-portal.repo \
            && curl https://repo.infoclinica.ru/yum/centos/sds-${repo}-portal.repo -o /etc/yum.repos.d/sds-${repo}-portal.repo \
-           && chmod +x /usr/share/web-registry-portal/bin/entrypoint.sh \
-           && chmod +x /usr/share/web-registry-portal/bin/healthcheck.sh \
+           && chmod +x /entrypoint.sh \
            && yum install web-registry-portal iputils openssl -y \
            && yum install web-registry-portal iputils openssl -y \
            && yum update tzdata -y \
            && yum update tzdata -y \
            && yum clean all \
            && yum clean all \

+ 43 - 44
devK8s.Jenkinsfile

@@ -1,9 +1,10 @@
 @Library('jenkins-library@master') _
 @Library('jenkins-library@master') _
-def Label = "node-build-${UUID.randomUUID().toString()}"
+def Label = "node-iru-build-${UUID.randomUUID().toString()}"
 pipeline {
 pipeline {
   options {
   options {
     buildDiscarder logRotator(numToKeepStr: '10')
     buildDiscarder logRotator(numToKeepStr: '10')
     disableConcurrentBuilds()
     disableConcurrentBuilds()
+    timeout(time: 10, unit: 'MINUTES')
   }
   }
   agent {
   agent {
     kubernetes {
     kubernetes {
@@ -14,14 +15,15 @@ pipeline {
   environment {
   environment {
     CLOUD='cloud-it-k8s'
     CLOUD='cloud-it-k8s'
     DOCKER_IMAGE='iru/node'
     DOCKER_IMAGE='iru/node'
-    CHART_PATH='helm/info'
+    CHART_SUBPATH='helm/info'
     NAMESPACE='info'
     NAMESPACE='info'
     HELM_GIT_URL='ssh://git@git.sdsys.ru:8022/iru/k8s.git'
     HELM_GIT_URL='ssh://git@git.sdsys.ru:8022/iru/k8s.git'
     APP_GIT_URL='ssh://git@git.sdsys.ru:8022/iru/node.git'
     APP_GIT_URL='ssh://git@git.sdsys.ru:8022/iru/node.git'
     JENKINS_MAIL='jenkins.dev@sdsys.ru'
     JENKINS_MAIL='jenkins.dev@sdsys.ru'
     DOCKER_REGISTRY='jcr.infoclinica.ru'
     DOCKER_REGISTRY='jcr.infoclinica.ru'
+    PROJECT=''
     CHART_NAME=''
     CHART_NAME=''
-    APP_DIR=''
+    CHART_PATH=''
     HELM_DIR=''
     HELM_DIR=''
     TAG=''
     TAG=''
   }
   }
@@ -29,7 +31,7 @@ pipeline {
     string(
     string(
       name: "repo",
       name: "repo",
       defaultValue: "prod",
       defaultValue: "prod",
-      description: "Repository to build and/or deploy from. Values - dev, prod."
+      description: "Repository to build and/or deploy from."
     )
     )
     string(
     string(
       name: "mailto",
       name: "mailto",
@@ -41,21 +43,21 @@ pipeline {
     stage("Prepare to Build") {
     stage("Prepare to Build") {
       steps {
       steps {
         script {
         script {
-          gitOps.clone(APP_GIT_URL)
-          APP_DIR = dirOps.calculateDir(APP_GIT_URL)
+          gitOps.clone(HELM_GIT_URL)
+          HELM_DIR = dirOps.calculateDir(HELM_GIT_URL)
+          CHART_PATH = "${HELM_DIR}/${CHART_SUBPATH}"
+          PROJECT = DOCKER_IMAGE.split("/")[1]
         }
         }
       }
       }
     }
     }
     stage("Build Image") {
     stage("Build Image") {
       steps {
       steps {
         script {
         script {
-          dir (APP_DIR) {
-            echo "Build Image with Kaniko"
-            REGISTRY = DOCKER_REGISTRY + "/" + DOCKER_IMAGE
-            ARGS = [ "repo=${repo}" ]
-            TAG = "${repo}-${BUILD_NUMBER}"
-            k8sBuildImage.kaniko(REGISTRY, TAG, ARGS)
-          }
+          echo "Build Image with Kaniko"
+          REGISTRY = "${DOCKER_REGISTRY}/${DOCKER_IMAGE}"
+          ARGS = [ "repo=${repo}", "version=${version}" ]
+          TAG = "${repo}-${BUILD_NUMBER}"
+          k8sBuildImage.kaniko(REGISTRY, TAG, ARGS)
         }
         }
       }
       }
     }
     }
@@ -63,41 +65,38 @@ pipeline {
       steps {
       steps {
         script {
         script {
           echo "Update Helm Chart"
           echo "Update Helm Chart"
-          gitOps.clone(HELM_GIT_URL)
-          HELM_DIR = dirOps.calculateDir(HELM_GIT_URL)
-          def data = readYaml file: "${HELM_DIR}/${CHART_PATH}/values.yaml"
-          TAG_PATH = "images.${APP_DIR}.dev"
+          def data = readYaml file: "${CHART_PATH}/values.yaml"
+          TAG_PATH = "images.${PROJECT}.dev"
           yamlOps.updateBuilder(TAG_PATH, data, TAG)
           yamlOps.updateBuilder(TAG_PATH, data, TAG)
-          writeYaml file: "${HELM_DIR}/${CHART_PATH}/values.yaml", data: data, overwrite: true
-        }
-      }
-    }
-    stage("Update APP") {
-      steps {
-        script {
-          CHART = "${HELM_DIR}/${CHART_PATH}"
-          CHART_NAME = CHART_PATH.split("/")[1]
-          try {
-            echo "Update APP"
-            k8sHelmOps.upgrade(CLOUD, NAMESPACE, CHART_NAME, CHART)
-          }
-          catch(err) {
-            echo "Recovering APP"
-            k8sHelmOps.rollback(CLOUD, NAMESPACE, CHART_NAME)
-            throw err
-          }
-        }
-      }
-    }
-    stage("Push changes to REPO") {
-      steps {
-        script {
-          echo "Push changes to Repo"
-          COMMIT = "Version update ${APP_DIR}"
-          gitOps.push(HELM_DIR, COMMIT)
+          writeYaml file: "${CHART_PATH}/values.yaml", data: data, overwrite: true
         }
         }
       }
       }
     }
     }
+    // stage("Update APP") {
+    //   steps {
+    //     script {
+    //       RELEASENAME = CHART_SUBPATH.split("/")[1]
+    //       try {
+    //         echo "Update APP"
+    //         k8sHelmOps.upgrade(CLOUD, NAMESPACE, RELEASENAME, CHART_PATH)
+    //       }
+    //       catch(err) {
+    //         echo "Recovering APP"
+    //         k8sHelmOps.rollback(CLOUD, NAMESPACE, RELEASENAME)
+    //         throw err
+    //       }
+    //     }
+    //   }
+    // }
+    // stage("Push changes to REPO") {
+    //   steps {
+    //     script {
+    //       echo "Push changes to Repo"
+    //       COMMIT = "Version update ${PROJECT}"
+    //       gitOps.push(HELM_DIR, COMMIT)
+    //     }
+    //   }
+    // }
   }
   }
   post {
   post {
     failure {
     failure {

+ 6 - 3
entrypoint.sh

@@ -1,12 +1,15 @@
 #!/usr/bin/env bash
 #!/usr/bin/env bash
+export akka_interface=$(hostname -i)
 
 
 echo "#Dummy" >> /etc/rc.d/init.d/functions
 echo "#Dummy" >> /etc/rc.d/init.d/functions
 source /etc/init.d/web-registry-portal status
 source /etc/init.d/web-registry-portal status
 rm -rf /var/run/web-registry-portal/play.pid
 rm -rf /var/run/web-registry-portal/play.pid
 
 
+for i in $(ls -d /configs/*.conf); do ln -sf ${i} /etc/web-registry-portal/;done
+
 if [ ! -z "$*" ]
 if [ ! -z "$*" ]
-then
+  then
     exec "$@"
     exec "$@"
-else
+  else
     exec ${WEB_REGISTRY_BIN} ${WEB_REGISTRY_CUSTOM_OPTS} ${WEB_REGISTRY_OPTS}
     exec ${WEB_REGISTRY_BIN} ${WEB_REGISTRY_CUSTOM_OPTS} ${WEB_REGISTRY_OPTS}
-fi
+fi

+ 0 - 3
healthcheck.sh

@@ -1,3 +0,0 @@
-#!/bin/bash
-
-curl -f -H 'Host:demo.infoclinica.ru' 127.0.0.1:9000/login || exit 1