From 4615c1a0c1bfa82ea3b744ea269bb6ba638b6d34 Mon Sep 17 00:00:00 2001 From: andyjk15 Date: Sat, 15 Feb 2020 16:51:47 +0000 Subject: [PATCH] [15.02.20] kubernetes configs and application yamls --- Dockerfile | 1 - configuration/pipelines/build.groovy | 23 ++++ configuration/templates/deploy-config.yaml | 118 +++++++++++++++++++++ src/main/resources/application.yaml | 24 +++++ 4 files changed, 165 insertions(+), 1 deletion(-) create mode 100644 configuration/templates/deploy-config.yaml create mode 100644 src/main/resources/application.yaml diff --git a/Dockerfile b/Dockerfile index b8a19bd..8fd0a6d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,5 +2,4 @@ FROM openjdk:8-jre-alpine MAINTAINER Andrew Sotheran COPY /target/cryptosky-db-gateway.jar /home EXPOSE 9090 -CMD ["/bin/bash"] CMD ["java", "-jar", "/home/cryptosky-db-gateway.jar"] \ No newline at end of file diff --git a/configuration/pipelines/build.groovy b/configuration/pipelines/build.groovy index dba445e..fd2c857 100644 --- a/configuration/pipelines/build.groovy +++ b/configuration/pipelines/build.groovy @@ -26,6 +26,28 @@ String get_application_version() { "${pom.version}-b${env.BUILD_NUMBER}" } +@NonCPS +def applyResource(String environment, String resourcePath, Map parameters) { + String command = "kubectl apply --filename ${resourcePath}" + parameters.each { String key, Object value -> + command += " --param=${key}='${value}'" + } + command += "| oc --namespace ${environment} apply --filename -" + + sh "${command}" +} + +def updateBuildResources(String environment) { + Map buildConfigParameters = [ + RESOURCE_NAME : env.APPLICATION_NAME, + APP_LABEL : env.APPLICATION_LABEL, + DOCKER_REGISTRY: env.DOCKER_REGISTRY, + IMAGE_VERSION : env.APPLICATION_VERSION + ] + + applyResource(environment, 'configuration/templates/build-config.yaml', buildConfigParameters) +} + def deploy( Integer replicas ) { // rollout latest // get rollout status @@ -61,6 +83,7 @@ try { stage('Build Image') { mvn 'clean package -DskipTests' + sh "sed -i 's/BUILD_NUMBER/${env.APPLICATION_VERSION}/g' deploy-config.yaml" // Update build config for kubernetes // Update Service yaml for kubernetes // Update route yaml for kubernetes diff --git a/configuration/templates/deploy-config.yaml b/configuration/templates/deploy-config.yaml new file mode 100644 index 0000000..69c4369 --- /dev/null +++ b/configuration/templates/deploy-config.yaml @@ -0,0 +1,118 @@ +apiVersion: v1 +kind: Deployment +metadata: + labels: + name: db-gateway + name: db-gateway +spec: + replicas: 1 + selector: + app: db-gateway + strategy: + type: Rolling + rollingParams: + updatePeriodSeconds: 1 + intervalSeconds: 1 + timeoutSeconds: 300 + maxSurge: 1 + maxUnavailable: 0 + template: + metadata: + labels: + app: db-gateway + spec: + containers: + - name: db-gateway + image: registry.cryptosky.me:4243/ + env: + - name: KUBERNETES_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: CONTAINER_CORE_LIMIT + valueFrom: + resourceFieldRef: + resource: limits.cpu + - name: CONTAINER_MAX_MEMORY + valueFrom: + resourceFieldRef: + resource: limits.memory + + - name: JDBC_URL + valueFrom: + secretKeyRef: + name: jdbc + key: jdbc.url + - name: JDBC_USERNAME + valueFrom: + secretKeyRef: + name: jdbc + key: jdbc.username + - name: JDBC_PASSWORD + valueFrom: + secretKeyRef: + name: jdbc + key: jdbc.password + - name: TZ + value: Europe/London + image: ${IMAGE}:${IMAGE_VERSION} + imagePullPolicy: Always + name: db-gateway + livenessProbe: + httpGet: + path: ${LIVENESS_PATH} + port: 9090 + initialDelaySeconds: 90 + periodSeconds: 30 + timeoutSeconds: 1 + successThreshold: 1 + failureThreshold: 3 + readinessProbe: + httpGet: + path: ${READINESS_PATH} + port: 9090 + initialDelaySeconds: 90 + periodSeconds: 5 + timeoutSeconds: 1 + successThreshold: 1 + failureThreshold: 10 + resources: + requests: + cpu: 10m + memory: 128Mi + limits: + cpu: 500m + memory: 256Mi + restartPolicy: Always + triggers: [] +parameters: + - name: RESOURCE_NAME + displayName: Resource Name + description: The name of the deployment configuration resource that also matches other resources. + required: true + - name: APP_LABEL + displayName: Application Label + description: Name of the application label that should be used in all resources. + required: true + - name: IMAGE + displayName: Image Reference + description: Complete reference to an image in external Docker Registry. + required: true + - name: IMAGE_VERSION + displayName: Image Version + description: Version of specific image to pull from external Docker registry. + required: true + - name: LIVENESS_PATH + displayName: Liveness Probe Path + description: Path to use in HTTP Get for the liveness probe. + value: /health + required: false + - name: READINESS_PATH + displayName: Readiness Probe Path + description: Path to use in HTTP Get for the readiness probe. + value: /info + required: false + - name: SPRING_PROFILES_ACTIVE + displayName: Spring Profiles Active + description: The active Spring profile(s) + required: false diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml new file mode 100644 index 0000000..ebf6499 --- /dev/null +++ b/src/main/resources/application.yaml @@ -0,0 +1,24 @@ +spring: + application: + name: @project.artifactId@ + datasource: + url: ${JDBC_URL} + username: ${JDBC_USERNAME} + password: ${JDBC_PASSWORD} + driver-class-name: org.postgresql.Driver + hikari: + maximum-pool-size: 100 + minimum-idle: 1 + jpa: + hibernate: + ddl-auto: validate + show-sql: true + properties: + org.hibernate.envers.revision_field_name: revision_id + org.hibernate.envers.revision_type_field_name: revision_type + org.hibernate.jdbc.lob.non_contextual_creation: true + format_sql: true + database: postgresql + +server: + port: 9090 \ No newline at end of file