Skip to content

Commit

Permalink
Add umap helm chart for Kubernetes deployment (#2286)
Browse files Browse the repository at this point in the history
This helm chart allow to deploy umap on a Kubernetes cluster easily.
  • Loading branch information
yohanboniface authored Nov 21, 2024
2 parents ccd6a21 + b768614 commit 3e6f8a6
Show file tree
Hide file tree
Showing 13 changed files with 447 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,8 @@ test-results/

### Transifex ###
tx

# Helm
charts/*/charts
helmfile.yaml
charts/*/Chart.lock
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions charts/umap/.helmignore
Original file line number Diff line number Diff line change
@@ -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/
16 changes: 16 additions & 0 deletions charts/umap/Chart.yaml
Original file line number Diff line number Diff line change
@@ -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
73 changes: 73 additions & 0 deletions charts/umap/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -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 -}}
102 changes: 102 additions & 0 deletions charts/umap/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
31 changes: 31 additions & 0 deletions charts/umap/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
24 changes: 24 additions & 0 deletions charts/umap/templates/pvc.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
9 changes: 9 additions & 0 deletions charts/umap/templates/secret-config.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
11 changes: 11 additions & 0 deletions charts/umap/templates/secret-env.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
15 changes: 15 additions & 0 deletions charts/umap/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
13 changes: 13 additions & 0 deletions charts/umap/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
Loading

0 comments on commit 3e6f8a6

Please sign in to comment.