Browse Source

Change build for k8s

Tomishinets Vladimir 4 years ago
parent
commit
c65f3b423b
2 changed files with 107 additions and 6 deletions
  1. 7 6
      Dockerfile
  2. 100 0
      buildImage.Jenkinsfile

+ 7 - 6
Dockerfile

@@ -1,14 +1,15 @@
-FROM registry.sdsys.ru/wine:fedora-30
+FROM jcr.infoclinica.ru/sys/wine:fedora30-1
+ENV WINEARCH=win32
+
+
+COPY analis pdf2png /opt/analis/
+COPY healthcheck.sh entrypoint.sh /
 
 RUN rm -rf /root/.wine && \
     mv /root/wine32 /root/.wine && \
     mkdir -p /root/.wine/drive_c/services/analis && \
-    mkdir -p /opt/analis
-
-COPY analis pdf2png /opt/analis/
-COPY healthcheck.sh entrypoint.sh /opt/
+    chmod +x /healthcheck.sh /entrypoint.sh
 
 HEALTHCHECK --interval=5s --start-period=3m CMD /opt/healthcheck.sh
 
-
 ENTRYPOINT ["/opt/entrypoint.sh"]

+ 100 - 0
buildImage.Jenkinsfile

@@ -0,0 +1,100 @@
+@Library('jenkins-library@master') _
+def Label = "analis-iru-build-${UUID.randomUUID().toString()}"
+pipeline {
+  options {
+    buildDiscarder logRotator(numToKeepStr: '10')
+    disableConcurrentBuilds()
+    timeout(time: 10, unit: 'MINUTES')
+  }
+  agent {
+    kubernetes {
+      label Label
+      yaml """
+spec:
+  containers:
+  - name: svn
+    image: jgsqware/svn-client
+    command:
+    - cat
+    tty: true
+"""
+    }
+  }
+  environment {
+    CLOUD='cloud-it-k8s'
+    JENKINS_MAIL='jenkins.dev@sdsys.ru'
+    DOCKER_REGISTRY='jcr.infoclinica.ru'
+    DOCKER_IMAGE='lab/analis'
+    REPO='svn://192.168.21.250/programs/trunk/Services/Analis/Win32'
+    SVN_DIR='analis'
+    REV_NUMBER=''
+    PROJECT=''
+    CHART_NAME=''
+    CHART_PATH=''
+    HELM_DIR=''
+    TAG=''
+  }
+  parameters {
+    string(
+      name: "REVNUM",
+      defaultValue: "HEAD",
+      description: "Revision number"
+    )
+    string(
+      name: "mailto",
+      defaultValue: "admin@sdsys.ru",
+      description: "Email which has to be notified."
+    )
+  }
+  stages {
+    stage("SVN Checkout") {
+      steps {
+        script {
+          svnOps.checkout(REPO, SVN_DIR, REVNUM)
+          REV_NUMBER = svnOps.RevNumber(SVN_DIR)
+          echo REV_NUMBER
+          PROJECT = DOCKER_IMAGE.split("/")[1]
+        }
+      }
+    }
+    stage("Build Image") {
+      steps {
+        script {
+          echo "Build Image with Kaniko"
+          REGISTRY = "${DOCKER_REGISTRY}/${DOCKER_IMAGE}"
+          TAG = "${REV_NUMBER}-${BUILD_NUMBER}"
+          k8sBuildImage.kaniko(REGISTRY, TAG)
+        }
+      }
+    }
+    stage("Update Helm Chart values.yaml") {
+      steps {
+        script {
+          echo "Update Helm Chart"
+          def data = readYaml file: "${CHART_PATH}/values.yaml"
+          TAG_PATH = "images.${PROJECT}.build"
+          yamlOps.updateBuilder(TAG_PATH, data, TAG)
+          writeYaml file: "${CHART_PATH}/values.yaml", data: data, overwrite: true
+        }
+      }
+    }
+    stage("Push changes to REPO") {
+      steps {
+        script {
+          echo "Push changes to Repo"
+          COMMIT = "Version update ${PROJECT}"
+          gitOps.push(HELM_DIR, COMMIT)
+        }
+      }
+    }
+  }
+  post {
+    failure {
+      mail charset: 'UTF-8',
+           subject: "Jenkins build ERROR",
+           mimeType: 'text/html',
+           to: "${mailto}",
+           body: "<b>ATTENTION!!!</b> <b><br> Jenkins job failed.\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}"
+    }
+  }
+}