From 94aaf14588615d813fc6d06a5b13d53f296fa09f Mon Sep 17 00:00:00 2001 From: Tamas Molnar Date: Thu, 13 Jul 2017 15:25:42 +0300 Subject: [PATCH] Helm and Jenkins integration --- .gitignore | 2 +- Jenkinsfile | 7 ++ helm/v1-brands-transformer/.helmignore | 21 +++++ helm/v1-brands-transformer/Chart.yaml | 4 + .../v1-brands-transformer_publishing.yaml | 14 ++++ .../templates/_helpers.tpl | 16 ++++ .../templates/deployment.yaml | 82 +++++++++++++++++++ helm/v1-brands-transformer/templates/pv.yaml | 12 +++ helm/v1-brands-transformer/templates/pvc.yaml | 10 +++ .../templates/service.yaml | 16 ++++ helm/v1-brands-transformer/values.yaml | 23 ++++++ 11 files changed, 206 insertions(+), 1 deletion(-) create mode 100644 Jenkinsfile create mode 100644 helm/v1-brands-transformer/.helmignore create mode 100644 helm/v1-brands-transformer/Chart.yaml create mode 100644 helm/v1-brands-transformer/app-configs/v1-brands-transformer_publishing.yaml create mode 100644 helm/v1-brands-transformer/templates/_helpers.tpl create mode 100644 helm/v1-brands-transformer/templates/deployment.yaml create mode 100644 helm/v1-brands-transformer/templates/pv.yaml create mode 100644 helm/v1-brands-transformer/templates/pvc.yaml create mode 100644 helm/v1-brands-transformer/templates/service.yaml create mode 100644 helm/v1-brands-transformer/values.yaml diff --git a/.gitignore b/.gitignore index f864115..fd9244e 100644 --- a/.gitignore +++ b/.gitignore @@ -10,7 +10,7 @@ *.html *coverage.* *.iml -v1-brands-transformer +/v1-brands-transformer .idea/ *.db *.lock diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..5c52baf --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,7 @@ +@Library('k8s-pipeline-lib') _ + +import com.ft.jenkins.BuildConfig +import com.ft.jenkins.Cluster + +BuildConfig config = new BuildConfig() +entryPointForReleaseAndDev(config) diff --git a/helm/v1-brands-transformer/.helmignore b/helm/v1-brands-transformer/.helmignore new file mode 100644 index 0000000..f0c1319 --- /dev/null +++ b/helm/v1-brands-transformer/.helmignore @@ -0,0 +1,21 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*~ +# Various IDEs +.project +.idea/ +*.tmproj diff --git a/helm/v1-brands-transformer/Chart.yaml b/helm/v1-brands-transformer/Chart.yaml new file mode 100644 index 0000000..b672c84 --- /dev/null +++ b/helm/v1-brands-transformer/Chart.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +description: v1-brands-transformer Helm chart for Kubernetes +name: v1-brands-transformer +version: 0.0.0 # this entry can be left untouched as it is automatically handled by Jenkins pipeline diff --git a/helm/v1-brands-transformer/app-configs/v1-brands-transformer_publishing.yaml b/helm/v1-brands-transformer/app-configs/v1-brands-transformer_publishing.yaml new file mode 100644 index 0000000..554fb45 --- /dev/null +++ b/helm/v1-brands-transformer/app-configs/v1-brands-transformer_publishing.yaml @@ -0,0 +1,14 @@ +# Values used for the deployed application. +replicaCount: 1 +service: + name: v1-brands-transformer +cache: + size: 5Gi + nfsServer: fs-6330fcaa.efs.eu-west-1.amazonaws.com + path: "/" +env: + PORT: 8080 + BASE_URL: "http://v1-brands-transformer:8080/transformers/brands/" + CACHE_FILE_NAME: "/cache/v1-brands-transformer.db" + BERTHA_SOURCE_URL: "http://bertha.ig.ft.com/republish/publish/gss/1wEdVRLtayZ6-XBfYM3vKAGaOV64cNJD3L8MlLM8-uFY/TestBrands" + LOG_METRICS: false diff --git a/helm/v1-brands-transformer/templates/_helpers.tpl b/helm/v1-brands-transformer/templates/_helpers.tpl new file mode 100644 index 0000000..f7877c3 --- /dev/null +++ b/helm/v1-brands-transformer/templates/_helpers.tpl @@ -0,0 +1,16 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 24 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Create a default fully qualified app name. +We truncate at 24 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +*/}} +{{- define "fullname" -}} +{{- $name := default .Chart.Name .Values.nameOverride -}} +{{- printf "%s-%s" .Release.Name $name | trunc 24 | trimSuffix "-" -}} +{{- end -}} diff --git a/helm/v1-brands-transformer/templates/deployment.yaml b/helm/v1-brands-transformer/templates/deployment.yaml new file mode 100644 index 0000000..48ec614 --- /dev/null +++ b/helm/v1-brands-transformer/templates/deployment.yaml @@ -0,0 +1,82 @@ +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: {{ .Values.service.name }} + labels: + chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" + visualize: "true" + app: {{ .Values.service.name }} +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + app: {{ .Values.service.name }} + template: + metadata: + labels: + app: {{ .Values.service.name }} + visualize: "true" + spec: + containers: + - name: {{ .Values.service.name }} + image: "{{ .Values.image.repository }}:{{ .Chart.Version }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + env: + - name: TME_BASE_URL + valueFrom: + configMapKeyRef: + name: global-config + key: tme.url + - name: TME_USERNAME + valueFrom: + secretKeyRef: + name: global-secrets + key: tme.username + - name: TME_PASSWORD + valueFrom: + secretKeyRef: + name: global-secrets + key: tme.password + - name: TOKEN + valueFrom: + secretKeyRef: + name: global-secrets + key: tme.token + - name: GRAPHITE_ADDRESS + valueFrom: + configMapKeyRef: + name: global-config + key: graphite.address + - name: PORT + value: "{{ .Values.env.PORT }}" + - name: BASE_URL + value: {{ .Values.env.BASE_URL }} + - name: CACHE_FILE_NAME + value: {{ .Values.env.CACHE_FILE_NAME }} + - name: BERTHA_SOURCE_URL + value: {{ .Values.env.BERTHA_SOURCE_URL }} + - name: GRAPHITE_PREFIX + value: "coco.services.k8s.{{ .Values.service.name }}" + - name: LOG_METRICS + value: "{{ .Values.env.LOG_METRICS }}" + volumeMounts: + - name: "{{ .Values.service.name }}-cache" + mountPath: /cache + ports: + - containerPort: 8080 + livenessProbe: + tcpSocket: + port: 8080 + initialDelaySeconds: 5 + readinessProbe: + httpGet: + path: "/__gtg" + port: 8080 + initialDelaySeconds: 5 + periodSeconds: 30 + resources: +{{ toYaml .Values.resources | indent 12 }} + volumes: + - name: "{{ .Values.service.name }}-cache" + persistentVolumeClaim: + claimName: "{{ .Values.service.name }}-cache-pvc" diff --git a/helm/v1-brands-transformer/templates/pv.yaml b/helm/v1-brands-transformer/templates/pv.yaml new file mode 100644 index 0000000..5a7d61c --- /dev/null +++ b/helm/v1-brands-transformer/templates/pv.yaml @@ -0,0 +1,12 @@ +kind: PersistentVolume +apiVersion: v1 +metadata: + name: "{{ .Values.service.name }}-cache-pv" +spec: + capacity: + storage: {{ .Values.cache.size }} + accessModes: + - ReadWriteMany + nfs: + server: {{ .Values.cache.nfsServer }} + path: {{ .Values.cache.path }} diff --git a/helm/v1-brands-transformer/templates/pvc.yaml b/helm/v1-brands-transformer/templates/pvc.yaml new file mode 100644 index 0000000..feb2418 --- /dev/null +++ b/helm/v1-brands-transformer/templates/pvc.yaml @@ -0,0 +1,10 @@ +kind: PersistentVolumeClaim +apiVersion: v1 +metadata: + name: {{ .Values.service.name }}-cache-pvc +spec: + accessModes: + - ReadWriteMany + resources: + requests: + storage: {{ .Values.cache.size }} diff --git a/helm/v1-brands-transformer/templates/service.yaml b/helm/v1-brands-transformer/templates/service.yaml new file mode 100644 index 0000000..d5ed575 --- /dev/null +++ b/helm/v1-brands-transformer/templates/service.yaml @@ -0,0 +1,16 @@ +kind: Service +apiVersion: v1 +metadata: + name: {{.Values.service.name}} + labels: + chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" + app: {{.Values.service.name}} + visualize: "true" + hasHealthcheck: "{{ .Values.service.hasHealthcheck }}" +spec: + ports: + - port: 8080 +# name: # The name of this port within the service. Optional if only one port is defined on this service + targetPort: 8080 + selector: + app: {{ .Values.service.name }} diff --git a/helm/v1-brands-transformer/values.yaml b/helm/v1-brands-transformer/values.yaml new file mode 100644 index 0000000..830771c --- /dev/null +++ b/helm/v1-brands-transformer/values.yaml @@ -0,0 +1,23 @@ +# Default values for v1-brands-transformer. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. +service: + name: "" # The name of the service, should be defined in the specific app-configs folder. + hasHealthcheck: "true" +replicaCount: 1 +image: + repository: coco/v1-brands-transformer + pullPolicy: IfNotPresent +resources: + limits: + memory: 1536Mi +cache: + size: 5Gi + nfsServer: "" + path: "" +env: + PORT: 8080 + BASE_URL: "" + CACHE_FILE_NAME: "" + BERTHA_SOURCE_URL: "" + LOG_METRICS: false