Browse Source

add Jenkinsfile, change Dockerfile

Tomishinets Vladimir 4 years ago
parent
commit
0b7b0d4ea3
2 changed files with 91 additions and 21 deletions
  1. 5 21
      Dockerfile
  2. 86 0
      devK8s.Jenkinsfile

+ 5 - 21
Dockerfile

@@ -1,24 +1,8 @@
-FROM registry.sdsys.ru/build-image:alpine-3.10-1 as build
-ARG branch=release
-ARG gradle_version=5.2.1
-COPY id_rsa /root/.ssh
-RUN export GRADLE_HOME=/opt/gradle/gradle-${gradle_version} \
-    && export PATH=${GRADLE_HOME}/bin:${PATH} \
-    && gradle -v \
-    && printf "Host git.alfatell.ru \n\tStrictHostKeyChecking no" > /root/.ssh/config \
-    && git clone ssh://gitolite@git.alfatell.ru:2223/web-registration-cloud.git \
-    && cd web-registration-cloud && git checkout ${branch} \
-    && echo $(git log -p -1 --pretty=format:"%h"|head -n1) > /tmp/version && cd customer-api \
-    && mvn clean install && cd ../promo/ \
-    && figlet -c Building Promo \
-    && gradle tasks bootWar \
-    && rm -rf /root/.ssh/id_rsa
-
-FROM registry.sdsys.ru/iru/iru-base:7.6
+FROM openjdk:8-jre
 ARG DB_CLUSTER=mongodb1:27017,mongodb2:27018,mongodb3:27019
 ARG SERVER_PORT=9000
-    
+
 HEALTHCHECK --start-period=30s --interval=15s --timeout=5s --retries=2 CMD curl -f 127.0.0.1:${SERVER_PORT} || exit 1
-COPY --from=build /web-registration-cloud/promo/build/libs/promo-0.0.1-SNAPSHOT.war /opt/
-COPY --from=build /tmp/version /tmp/
-CMD ["java", "-jar", "/opt/promo-0.0.1-SNAPSHOT.war"]
+COPY promo-0.0.1-SNAPSHOT.war /
+COPY version /tmp/
+CMD ["java", "-jar", "/promo-0.0.1-SNAPSHOT.war"]

+ 86 - 0
devK8s.Jenkinsfile

@@ -0,0 +1,86 @@
+@Library('jenkins-library@master') _
+def Label = "promo-build-${UUID.randomUUID().toString()}"
+pipeline {
+  options {
+    buildDiscarder logRotator(numToKeepStr: '10')
+    disableConcurrentBuilds()
+  }
+  agent {
+    kubernetes {
+      label Label
+      yaml libraryResource('promoPodDefinition.yaml')
+    }
+  }
+  environment {
+    CLOUD='cloud-it-k8s'
+    DOCKER_IMAGE='iru/promo'
+    CHART_PATH='helm/info'
+    NAMESPACE='info'
+    HELM_GIT_URL='ssh://git@git.sdsys.ru:8022/iru/k8s.git'
+    APP_GIT_URL='ssh://gitolite@git.alfatell.ru:2223/web-registration-cloud.git'
+    JENKINS_MAIL='jenkins.dev@sdsys.ru'
+    DOCKER_REGISTRY='jcr.infoclinica.ru'
+    CHART_NAME=''
+    APP_DIR=''
+    HELM_DIR=''
+    TAG=''
+  }
+  parameters {
+    string(
+      name: "branch",
+      defaultValue: "release",
+      description: "Which branch to use"
+    )
+    string(
+      name: "mailto",
+      defaultValue: "admin@sdsys.ru",
+      description: "Email which has to be notified."
+    )
+  }
+  stages {
+    stage("Prepare to build") {
+      steps {
+        script {
+          echo "Pull ${APP_GIT_URL}"
+          gitOps.clone(APP_GIT_URL)
+          APP_DIR = dirOps.calculateDir(APP_GIT_URL)
+          echo "CheckOut ${branch}"
+          gitOps.checkout(APP_DIR, branch)
+          echo "Save Version"
+          dir(APP_DIR) {
+            sh 'echo $(git log -p -1 --pretty=format:"%h"|head -n1) > version'
+          }
+        }
+      }
+    }
+    stage("Build APP") {
+      steps {
+        script {
+          echo "Build customer-api"
+          dir("${APP_DIR}/customer-api") {
+            maven()
+          }
+          echo "Build Promo"
+          dir("${APP_DIR}/promo") {
+            gradle()
+          }
+        }
+      }
+    }
+    stage("Build Image") {
+      steps {
+        script {
+          sh "cp ${APP_DIR}/promo/build/libs/promo-0.0.1-SNAPSHOT.war ."
+          sh "cp ${APP_DIR}/version ."
+          REGISTRY = DOCKER_REGISTRY + "/" + DOCKER_IMAGE
+          COMMIT = sh(script: "cat version 2> /dev/null", returnStdout: true).trim()
+          TAG = "${COMMIT}-${BUILD_NUMBER}"
+          echo "Build Image with Kaniko with parameters"
+          echo "Repository: ${REGISTRY}"
+          echo "Tag: ${TAG}"
+          k8sBuildImage.kaniko(REGISTRY, TAG)
+        }
+      }
+    }
+  }
+}