From d17ecf57d9463405cea6c8fe608f06c09a705a8e Mon Sep 17 00:00:00 2001 From: Emilien Devos Date: Thu, 26 Oct 2023 11:38:34 +0200 Subject: [PATCH] add mviewer helm chart --- mviewer/.helmignore | 23 +++++ mviewer/Chart.yaml | 9 ++ mviewer/README.md | 79 ++++++++++++++++++ .../_bootstrap-mviewer-configuration.tpl | 25 ++++++ mviewer/templates/_helpers.tpl | 62 ++++++++++++++ mviewer/templates/mviewer-deployment.yaml | 83 +++++++++++++++++++ mviewer/templates/mviewer-ingress.yaml | 57 +++++++++++++ mviewer/templates/mviewer-svc.yaml | 15 ++++ mviewer/values.yaml | 73 ++++++++++++++++ 9 files changed, 426 insertions(+) create mode 100644 mviewer/.helmignore create mode 100644 mviewer/Chart.yaml create mode 100644 mviewer/README.md create mode 100644 mviewer/templates/_bootstrap-mviewer-configuration.tpl create mode 100644 mviewer/templates/_helpers.tpl create mode 100644 mviewer/templates/mviewer-deployment.yaml create mode 100644 mviewer/templates/mviewer-ingress.yaml create mode 100644 mviewer/templates/mviewer-svc.yaml create mode 100644 mviewer/values.yaml diff --git a/mviewer/.helmignore b/mviewer/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/mviewer/.helmignore @@ -0,0 +1,23 @@ +# 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 +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/mviewer/Chart.yaml b/mviewer/Chart.yaml new file mode 100644 index 0000000..98a2c02 --- /dev/null +++ b/mviewer/Chart.yaml @@ -0,0 +1,9 @@ +apiVersion: v2 +name: mviewer +description: A Helm chart to deploy the mviewer application +type: application +version: 0.1.0 +appVersion: "3.9" +maintainers: + - name: geOrchestra + url: https://www.georchestra.org diff --git a/mviewer/README.md b/mviewer/README.md new file mode 100644 index 0000000..04aa343 --- /dev/null +++ b/mviewer/README.md @@ -0,0 +1,79 @@ +# Mviewer + +mviewer est une application cartographique initiée et développée par la Région Bretagne, sous le nom de Kartenn (carte en breton). + +Le code source de cette application est librement réutilisable depuis 2014. + +De nombreuses collectivités mais également des entreprises, le secteur de la recherche et de l’enseignement utilisent librement cette application et participent à son évolution. + +## Source Code + +* https://github.com/mviewer/mviewer + +## Requirements + +Kubernetes: `>=1.14.0-0` + +## Dependencies + +None + +## Installing the Chart + +To install the chart with the release name `mviewer` + +```console +helm repo add charts-gs https://camptocamp.github.io/charts-gs/ +helm repo update +helm install mviewer charts-gs/mviewer +``` + +## Uninstalling the Chart + +To uninstall the `mviewer` deployment + +```console +helm uninstall mviewer +``` + +The command removes all the Kubernetes components associated with the chart **including persistent volumes** and deletes the release. + +## Configuration + +Read through the [values.yaml](./values.yaml) file. It has several commented out suggested values. + +Specify each parameter using the `--set key=value[,key=value]` argument to `helm install`. + +```console +helm install mviewer \ + --set replicaCount="2" \ + charts-gs/mviewer +``` + +Alternatively, a YAML file that specifies the values for the above parameters can be provided while installing the chart. + +```console +helm install mviewer charts-gs/mviewer -f values.yaml +``` + +## mviewer configuration + +Through the parameter `configuration.git`, you can set a git repository that will be used for configuring mviewer. + +Please refer to the docker documentation for more explanations about this custom configuration: https://mviewerdoc.readthedocs.io/fr/latest/doc_tech/deploy.html#avec-docker + +## Values + +**Important**: Some values here are not documented because those are obvious parameters that you can find the meaning and the usuability through the Kubernetes configuration: https://kubernetes.io/docs/home/ + +| Key | Type | Default | Description | +|-----|------|---------|-------------| +| image | object | See values.yaml | Set the docker image to use. | +| configuration | object | See values.yaml | [See above](#mviewer-configuration) | +| ingress | object | See values.yaml | Configurations for configuring ingress | + +## Changelog + +### Version 0.1.0 + +Initial version diff --git a/mviewer/templates/_bootstrap-mviewer-configuration.tpl b/mviewer/templates/_bootstrap-mviewer-configuration.tpl new file mode 100644 index 0000000..036d269 --- /dev/null +++ b/mviewer/templates/_bootstrap-mviewer-configuration.tpl @@ -0,0 +1,25 @@ +{{- define "mviewer.bootstrap_mviewer_configuration" -}} +- name: bootstrap-mviewer-configuration + image: bitnami/git + command: + - /bin/sh + - -c + - {{- if .Values.configuration.git.ssh_secret }} + mkdir -p /root/.ssh ; + cp /ssh-secret/ssh-privatekey /root/.ssh/id_rsa ; + chmod 0600 /root/.ssh/id_rsa ; + {{- end }} + git clone --depth 1 --single-branch {{ .Values.configuration.git.url }} -b {{ .Values.configuration.git.ref }} /usr/share/nginx/html/apps ; + {{- if .Values.configuration.git.ssh_secret }} + env: + - name: GIT_SSH_COMMAND + value: ssh -o "IdentitiesOnly=yes" -o "StrictHostKeyChecking no" + {{- end }} + volumeMounts: + - mountPath: /usr/share/nginx/html/apps + name: mviewer-configuration + {{- if .Values.configuration.git.ssh_secret }} + - mountPath: /ssh-secret + name: ssh-secret + {{- end }} +{{- end -}} diff --git a/mviewer/templates/_helpers.tpl b/mviewer/templates/_helpers.tpl new file mode 100644 index 0000000..fda6fad --- /dev/null +++ b/mviewer/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "helm-mviewer.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "helm-mviewer.fullname" -}} +{{- if .Values.fullnameOverride }} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- $name := default .Chart.Name .Values.nameOverride }} +{{- if contains $name .Release.Name }} +{{- .Release.Name | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} +{{- end }} +{{- end }} +{{- end }} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "helm-mviewer.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "helm-mviewer.labels" -}} +helm.sh/chart: {{ include "helm-mviewer.chart" . }} +{{ include "helm-mviewer.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "helm-mviewer.selectorLabels" -}} +app.kubernetes.io/name: {{ include "helm-mviewer.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "helm-mviewer.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "helm-mviewer.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/mviewer/templates/mviewer-deployment.yaml b/mviewer/templates/mviewer-deployment.yaml new file mode 100644 index 0000000..157da32 --- /dev/null +++ b/mviewer/templates/mviewer-deployment.yaml @@ -0,0 +1,83 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "helm-mviewer.fullname" . }}-mviewer-deployment + labels: + {{- include "helm-mviewer.labels" . | nindent 4 }} +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + {{- include "helm-mviewer.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "helm-mviewer.selectorLabels" . | nindent 8 }} + application/name: {{ include "helm-mviewer.fullname" . }}-mviewer-deployment + spec: + {{- if .Values.configuration.git.url }} + initContainers: + {{- include "mviewer.bootstrap_mviewer_configuration" $ | nindent 6 }} + {{- end }} + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + containers: + - name: {{ .Chart.Name }} + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - name: http + containerPort: 80 + protocol: TCP + livenessProbe: + httpGet: + path: / + port: http + readinessProbe: + httpGet: + path: / + port: http + {{- with .Values.lifecycle }} + lifecycle: + {{- toYaml . | nindent 12 }} + {{- end }} + resources: + {{- toYaml .Values.resources | nindent 12 }} + {{- with .Values.extra_environment }} + env: + {{- toYaml . | nindent 12 }} + {{- end }} + volumeMounts: + - name: mviewer-configuration + mountPath: /etc/mviewer + volumes: + - name: mviewer-configuration + emptyDir: {} + {{- if .Values.configuration.git.ssh_secret }} + - name: ssh-secret + secret: + secretName: {{ .Values.configuration.git.ssh_secret }} + defaultMode: 0400 + {{- end }} + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/mviewer/templates/mviewer-ingress.yaml b/mviewer/templates/mviewer-ingress.yaml new file mode 100644 index 0000000..b8a2257 --- /dev/null +++ b/mviewer/templates/mviewer-ingress.yaml @@ -0,0 +1,57 @@ +{{- if .Values.ingress.enabled -}} +{{- $fullName := include "helm-mviewer.fullname" . -}} +{{- $svcPort := .Values.service.port -}} +{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1 +{{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1beta1 +{{- else -}} +apiVersion: extensions/v1beta1 +{{- end }} + +kind: Ingress +metadata: + name: {{ $fullName }} + labels: + {{- include "helm-mviewer.labels" . | nindent 4 }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- if and .Values.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }} + ingressClassName: {{ .Values.ingress.className }} + {{- end }} + {{- if .Values.ingress.tls }} + tls: + {{- range .Values.ingress.tls }} + - hosts: + {{- range .hosts }} + - {{ . | quote }} + {{- end }} + secretName: {{ .secretName }} + {{- end }} + {{- end }} + rules: + {{- range .Values.ingress.hosts }} + - host: {{ .host | quote }} + http: + paths: + {{- range .paths }} + - path: {{ . }} + {{- if semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion }} + pathType: Prefix + {{- end }} + backend: + {{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }} + service: + name: {{ $fullName }}-mviewer-svc + port: + number: {{ $svcPort }} + {{- else }} + serviceName: {{ $fullName }} + servicePort: {{ $svcPort }} + {{- end }} + {{- end }} + {{- end }} + {{- end }} \ No newline at end of file diff --git a/mviewer/templates/mviewer-svc.yaml b/mviewer/templates/mviewer-svc.yaml new file mode 100644 index 0000000..485b11b --- /dev/null +++ b/mviewer/templates/mviewer-svc.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "helm-mviewer.fullname" . }}-mviewer-svc + labels: + {{- include "helm-mviewer.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + name: http + selector: + application/name: {{ include "helm-mviewer.fullname" . }}-mviewer-deployment diff --git a/mviewer/values.yaml b/mviewer/values.yaml new file mode 100644 index 0000000..6bb5c30 --- /dev/null +++ b/mviewer/values.yaml @@ -0,0 +1,73 @@ +replicaCount: 1 + +image: + repository: mviewer/mviewer + tag: latest + pullPolicy: Always + +configuration: + git: + url: {} + ref: {} + ssh_secret: {} + +ingress: + enabled: true + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + hosts: + - host: mymviewer.org + paths: + - "/mymviewer" + tls: [] + # - secretName: chart-example-tls + # hosts: + # - mymviewer.org + + # define a custom incressClassName, like "traefik" or "nginx" + className: "" + +extra_environment: [] + # - name: MY_ENV + # value: myvalue + +podAnnotations: {} + +podSecurityContext: {} + +securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + +service: + type: ClusterIP + port: 80 + annotations: {} + +#lifecycle: +# postStart: +# exec: +# command: ["/bin/sh", "-c", "echo Hello from the postStart handler > /usr/share/message"] +# preStop: +# exec: +# command: ["/bin/sh","-c","nginx -s quit; while killall -0 nginx; do sleep 1; done"] + +resources: + limits: + cpu: 100m + memory: 128Mi + requests: + cpu: 100m + memory: 128Mi + + +nodeSelector: {} + +tolerations: [] + +affinity: {} \ No newline at end of file