From 8ac548bf6fbd1bbe4719c1217d2766e703fb5f62 Mon Sep 17 00:00:00 2001 From: Antoine Millet Date: Wed, 20 Nov 2024 14:04:31 +0100 Subject: [PATCH 1/2] chore: added umap helm chart This helm chart allow to deploy umap on a Kubernetes cluster easily. --- .gitignore | 5 + charts/umap/.helmignore | 23 +++++ charts/umap/Chart.yaml | 16 +++ charts/umap/templates/_helpers.tpl | 73 +++++++++++++ charts/umap/templates/deployment.yaml | 102 +++++++++++++++++++ charts/umap/templates/ingress.yaml | 31 ++++++ charts/umap/templates/pvc.yaml | 24 +++++ charts/umap/templates/secret-config.yaml | 9 ++ charts/umap/templates/secret-env.yaml | 11 ++ charts/umap/templates/service.yaml | 15 +++ charts/umap/templates/serviceaccount.yaml | 13 +++ charts/umap/values.yaml | 118 ++++++++++++++++++++++ 12 files changed, 440 insertions(+) create mode 100644 charts/umap/.helmignore create mode 100644 charts/umap/Chart.yaml create mode 100644 charts/umap/templates/_helpers.tpl create mode 100644 charts/umap/templates/deployment.yaml create mode 100644 charts/umap/templates/ingress.yaml create mode 100644 charts/umap/templates/pvc.yaml create mode 100644 charts/umap/templates/secret-config.yaml create mode 100644 charts/umap/templates/secret-env.yaml create mode 100644 charts/umap/templates/service.yaml create mode 100644 charts/umap/templates/serviceaccount.yaml create mode 100644 charts/umap/values.yaml diff --git a/.gitignore b/.gitignore index aed59988c..58ee69ec6 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,8 @@ test-results/ ### Transifex ### tx + +# Helm +charts/*/charts +helmfile.yaml +charts/*/Chart.lock \ No newline at end of file diff --git a/charts/umap/.helmignore b/charts/umap/.helmignore new file mode 100644 index 000000000..0e8a0eb36 --- /dev/null +++ b/charts/umap/.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/charts/umap/Chart.yaml b/charts/umap/Chart.yaml new file mode 100644 index 000000000..4c3bdbb81 --- /dev/null +++ b/charts/umap/Chart.yaml @@ -0,0 +1,16 @@ +apiVersion: v2 +name: umap +description: A Helm chart to deploy umap on Kubernetes + +type: application + +version: 0.1.0 + +appVersion: "2.7.2" + +dependencies: + - name: cnpg-cluster + version: 2.0.1 + repository: https://charts.enix.io/ + alias: cnpg + condition: cnpg.enabled \ No newline at end of file diff --git a/charts/umap/templates/_helpers.tpl b/charts/umap/templates/_helpers.tpl new file mode 100644 index 000000000..c575bcbe4 --- /dev/null +++ b/charts/umap/templates/_helpers.tpl @@ -0,0 +1,73 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "umap.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 "umap.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 "umap.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "umap.labels" -}} +helm.sh/chart: {{ include "umap.chart" . }} +{{ include "umap.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "umap.selectorLabels" -}} +app.kubernetes.io/name: {{ include "umap.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "umap.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "umap.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} + +{{/* +Get the name of the persistent volume claim +*/}} +{{- define "umap.pvcName" -}} + {{- if .Values.persistence.existingClaim -}} + {{- printf "%s" (tpl .Values.persistence.existingClaim $) -}} + {{- else -}} + {{- printf "%s" (include "umap.fullname" .) -}} + {{- end -}} +{{- end -}} \ No newline at end of file diff --git a/charts/umap/templates/deployment.yaml b/charts/umap/templates/deployment.yaml new file mode 100644 index 000000000..96780f959 --- /dev/null +++ b/charts/umap/templates/deployment.yaml @@ -0,0 +1,102 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "umap.fullname" . }} + labels: + {{- include "umap.labels" . | nindent 4 }} +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + {{- include "umap.selectorLabels" . | nindent 6 }} + template: + metadata: + annotations: + checksum/config: {{ include (print $.Template.BasePath "/secret-config.yaml") . | sha256sum }} + checksum/env: {{ include (print $.Template.BasePath "/secret-env.yaml") . | sha256sum }} + {{- with .Values.podAnnotations }} + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "umap.labels" . | nindent 8 }} + {{- with .Values.podLabels }} + {{- toYaml . | nindent 8 }} + {{- end }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "umap.serviceAccountName" . }} + 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: {{ .Values.service.port }} + protocol: TCP + startupProbe: + httpGet: + path: /stats + port: http + livenessProbe: + httpGet: + path: /stats + port: http + readinessProbe: + httpGet: + path: /stats + port: http + resources: + {{- toYaml .Values.resources | nindent 12 }} + {{- if .Values.cnpg.enabled }} + env: + - name: DATABASE_URL + valueFrom: + secretKeyRef: + name: {{ .Release.Name }}-cnpg-app + key: uri + - name: UMAP_SETTINGS + value: /etc/umap/umap.conf + {{- end }} + envFrom: + - secretRef: + name: {{ .Release.Name }}-env + volumeMounts: + - name: config + mountPath: /etc/umap/ + readOnly: true + - name: statics + mountPath: /srv/umap/static + {{- if .Values.persistence.enabled }} + - name: data + mountPath: /srv/umap/uploads/ + {{- end }} + volumes: + - name: config + secret: + secretName: {{ .Release.Name }}-config + - name: statics + emptyDir: {} + {{- if .Values.persistence.enabled }} + - name: data + persistentVolumeClaim: + claimName: {{ include "umap.pvcName" . }} + {{- 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/charts/umap/templates/ingress.yaml b/charts/umap/templates/ingress.yaml new file mode 100644 index 000000000..c8d2a00ad --- /dev/null +++ b/charts/umap/templates/ingress.yaml @@ -0,0 +1,31 @@ +{{- if .Values.ingress.enabled -}} +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: {{ include "umap.fullname" . }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + ingressClassName: {{ .Values.ingress.className }} + tls: + - hosts: + {{- range .Values.ingress.hosts }} + - {{ . | quote }} + {{- end }} + secretName: {{ include "umap.fullname" . }}-tls + rules: + {{- range .Values.ingress.hosts }} + - host: {{ . | quote }} + http: + paths: + - path: / + pathType: Prefix + backend: + service: + name: {{ include "umap.fullname" $ }} + port: + number: {{ $.Values.service.port }} + {{- end }} +{{- end }} \ No newline at end of file diff --git a/charts/umap/templates/pvc.yaml b/charts/umap/templates/pvc.yaml new file mode 100644 index 000000000..0f67cfcb0 --- /dev/null +++ b/charts/umap/templates/pvc.yaml @@ -0,0 +1,24 @@ +{{- if and (.Values.persistence.enabled) (not .Values.persistence.existingClaim) }} +kind: PersistentVolumeClaim +apiVersion: v1 +metadata: + {{- if .Values.persistence.annotations }} + annotations: + {{- toYaml .Values.persistence.annotations | nindent 4 }} + {{- end }} + name: {{ include "umap.pvcName" . }} + labels: + {{- include "umap.labels" . | nindent 4 }} +spec: + accessModes: + {{- range .Values.persistence.accessModes }} + - {{ . | quote }} + {{- end }} + {{- with .Values.persistence.resources }} + resources: + {{- toYaml . | nindent 4 }} + {{- end }} + {{- if .Values.persistence.storageClassName }} + storageClassName: {{ .Values.persistence.storageClassName | quote }} + {{- end }} +{{- end }} \ No newline at end of file diff --git a/charts/umap/templates/secret-config.yaml b/charts/umap/templates/secret-config.yaml new file mode 100644 index 000000000..fa6f83591 --- /dev/null +++ b/charts/umap/templates/secret-config.yaml @@ -0,0 +1,9 @@ +apiVersion: v1 +kind: Secret +metadata: + name: {{ include "umap.fullname" . }}-config + labels: + {{- include "umap.labels" . | nindent 4 }} +type: Opaque +data: + umap.conf: {{ .Values.umap.config | b64enc }} \ No newline at end of file diff --git a/charts/umap/templates/secret-env.yaml b/charts/umap/templates/secret-env.yaml new file mode 100644 index 000000000..4e718d0f5 --- /dev/null +++ b/charts/umap/templates/secret-env.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: Secret +metadata: + name: {{ include "umap.fullname" . }}-env + labels: + {{- include "umap.labels" . | nindent 4 }} +type: Opaque +data: +{{- range $key, $value := .Values.umap.environment }} + {{ $key }}: "{{ $value | b64enc }}" +{{- end }} \ No newline at end of file diff --git a/charts/umap/templates/service.yaml b/charts/umap/templates/service.yaml new file mode 100644 index 000000000..c2893ea42 --- /dev/null +++ b/charts/umap/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "umap.fullname" . }} + labels: + {{- include "umap.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + name: http + selector: + {{- include "umap.selectorLabels" . | nindent 4 }} diff --git a/charts/umap/templates/serviceaccount.yaml b/charts/umap/templates/serviceaccount.yaml new file mode 100644 index 000000000..a694537a3 --- /dev/null +++ b/charts/umap/templates/serviceaccount.yaml @@ -0,0 +1,13 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "umap.serviceAccountName" . }} + labels: + {{- include "umap.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +automountServiceAccountToken: {{ .Values.serviceAccount.automount }} +{{- end }} diff --git a/charts/umap/values.yaml b/charts/umap/values.yaml new file mode 100644 index 000000000..de72d63b8 --- /dev/null +++ b/charts/umap/values.yaml @@ -0,0 +1,118 @@ +# Default values for umap. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: umap/umap + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "" + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +serviceAccount: + # Specifies whether a service account should be created + create: true + # Automatically mount a ServiceAccount's API credentials? + automount: true + # Annotations to add to the service account + annotations: {} + # The name of the service account to use. + # If not set and create is true, a name is generated using the fullname template + name: "" + +podAnnotations: {} +podLabels: {} + +podSecurityContext: + runAsUser: 1000 + runAsGroup: 1000 + fsGroup: 1000 + +securityContext: + capabilities: + drop: + - ALL + readOnlyRootFilesystem: true + runAsNonRoot: true + runAsUser: 1000 + +service: + type: ClusterIP + port: 8000 + +ingress: + enabled: false + className: "" + annotations: {} + hosts: + - example.org + +resources: {} + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + +nodeSelector: {} + +tolerations: [] + +affinity: {} + +umap: + # Set environment variables supported by umap here + # see: https://docs.umap-project.org/en/stable/config/settings/ + environment: + SECRET_KEY: CHANGE_ME + STATIC_ROOT: /srv/umap/static + MEDIA_ROOT: /srv/umap/uploads + # You can also provide umap.conf content here: + config: | + from umap.settings.base import * + + # See: https://github.com/umap-project/umap/blob/master/umap/settings/local.py.sample + +persistence: + enabled: true + accessModes: + - ReadWriteOnce + annotations: {} + existingClaim: "" + storageClassName: "" + resources: + requests: + storage: 1Gi + +# Configure Cloudnative-pg operator for Postgis database +# Alternatively, you can disable CNPG and provide your own +# Postgis database by setting the `umap.environment.DATABASE_URL` +cnpg: + enabled: true + replicaCount: 2 + image: + repository: ghcr.io/cloudnative-pg/postgis + tag: 14 + persistence: + storageClass: "" + size: 1Gi + clusterExtraSpec: + bootstrap: + initdb: + postInitTemplateSQL: + - CREATE EXTENSION postgis; + - CREATE EXTENSION postgis_topology; + - CREATE EXTENSION fuzzystrmatch; + - CREATE EXTENSION postgis_tiger_geocoder; + + # See available values here: https://artifacthub.io/packages/helm/enix/cnpg-cluster?modal=values \ No newline at end of file From b76861489e2c46b1b34cefc2f1ae31977bfbf905 Mon Sep 17 00:00:00 2001 From: Antoine Millet Date: Thu, 21 Nov 2024 15:13:25 +0100 Subject: [PATCH 2/2] chore: added "helm" job in Makefile to build & push helm chart --- Makefile | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Makefile b/Makefile index 36b5110c4..2db66401f 100644 --- a/Makefile +++ b/Makefile @@ -46,6 +46,13 @@ docker: ## Create a new Docker image and publish it docker build -t umap/umap:${VERSION} . docker push umap/umap:${VERSION} +.PHONY: helm +helm: ## Build the helm chart and publish it + $(eval VERSION=$(shell hatch version)) + $(eval PACKAGE=$(shell helm package --app-version ${VERSION} ./charts/umap | grep "Successfully packaged" | awk '{print $$NF}')) + @echo "Successfully packaged helm chart in: ${PACKAGE}" + helm push ${PACKAGE} oci://registry-1.docker.io/umap + .PHONY: build build: ## Build the Python package before release @hatch build --clean