From d454ec8fc9b861f42887a7332c869eedafd37484 Mon Sep 17 00:00:00 2001 From: Vojtech Mares Date: Mon, 3 Jul 2023 17:59:20 +0200 Subject: [PATCH] feat: add helm chart --- charts/backoffice/Chart.yaml | 6 +++ charts/backoffice/templates/NOTES.txt | 3 ++ charts/backoffice/templates/configmap.yaml | 11 +++++ charts/backoffice/templates/deployment.yaml | 44 +++++++++++++++++++ charts/backoffice/templates/ingress.yaml | 30 +++++++++++++ .../backoffice/templates/job-migration.yaml | 26 +++++++++++ charts/backoffice/templates/job-seed.yaml | 26 +++++++++++ .../backoffice/templates/secret-database.yaml | 9 ++++ .../backoffice/templates/secret-nextauth.yaml | 12 +++++ charts/backoffice/templates/service.yaml | 18 ++++++++ charts/backoffice/values.staging.yaml | 8 ++++ charts/backoffice/values.yaml | 38 ++++++++++++++++ 12 files changed, 231 insertions(+) create mode 100644 charts/backoffice/Chart.yaml create mode 100644 charts/backoffice/templates/NOTES.txt create mode 100644 charts/backoffice/templates/configmap.yaml create mode 100644 charts/backoffice/templates/deployment.yaml create mode 100644 charts/backoffice/templates/ingress.yaml create mode 100644 charts/backoffice/templates/job-migration.yaml create mode 100644 charts/backoffice/templates/job-seed.yaml create mode 100644 charts/backoffice/templates/secret-database.yaml create mode 100644 charts/backoffice/templates/secret-nextauth.yaml create mode 100644 charts/backoffice/templates/service.yaml create mode 100644 charts/backoffice/values.staging.yaml create mode 100644 charts/backoffice/values.yaml diff --git a/charts/backoffice/Chart.yaml b/charts/backoffice/Chart.yaml new file mode 100644 index 0000000..4e38881 --- /dev/null +++ b/charts/backoffice/Chart.yaml @@ -0,0 +1,6 @@ +apiVersion: v2 +name: backoffice +description: A Kubernetes Helm chart for backoffice +type: application +version: 0.1.0 +appVersion: 0.1.0 diff --git a/charts/backoffice/templates/NOTES.txt b/charts/backoffice/templates/NOTES.txt new file mode 100644 index 0000000..571fe88 --- /dev/null +++ b/charts/backoffice/templates/NOTES.txt @@ -0,0 +1,3 @@ +{{- if .Values.ingress.enabled }} +URL: https://{{ .Values.ingress.host }} +{{- end }} diff --git a/charts/backoffice/templates/configmap.yaml b/charts/backoffice/templates/configmap.yaml new file mode 100644 index 0000000..5bc9d64 --- /dev/null +++ b/charts/backoffice/templates/configmap.yaml @@ -0,0 +1,11 @@ +kind: kind: ConfigMap +apiVersion: v1 +metadata: + name: {{ .Release.Name }}-config + annotations: + "helm.sh/hook": pre-install,pre-upgrade + "helm.sh/hook-weight": "-15" +data: + NODE_ENV: {{ .Values.env }} + NEXTAUTH_URL: "https://{{ .Values.ingress.host }}/" + PORT: {{ .Values.service.portNumber | quote }} diff --git a/charts/backoffice/templates/deployment.yaml b/charts/backoffice/templates/deployment.yaml new file mode 100644 index 0000000..a5411b5 --- /dev/null +++ b/charts/backoffice/templates/deployment.yaml @@ -0,0 +1,44 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ .Release.Name }} + labels: + app.kubernetes.io/managed-by: {{ .Release.Service }} + +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + app.kubernetes.io/name: {{ .Chart.Name }} + app.kubernetes.io/instance: {{ .Release.Name }} + template: + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: Always + ports: + - name: {{ .Values.service.portName }} + containerPort: {{ .Values.service.portNumber }} + protocol: TCP + livenessProbe: + httpGet: + path: / + port: {{ .Values.service.portName }} + readinessProbe: + httpGet: + path: / + port: {{ .Values.service.portName }} + envFrom: + - configMapRef: + name: {{ .Release.Name }}-config + - secretRef: + name: {{ .Release.Name }}-database + - secretRef: + name: {{ .Release.Name }}-nextauth + resources: + {{- toYaml .Values.resources | nindent 12 }} diff --git a/charts/backoffice/templates/ingress.yaml b/charts/backoffice/templates/ingress.yaml new file mode 100644 index 0000000..c462053 --- /dev/null +++ b/charts/backoffice/templates/ingress.yaml @@ -0,0 +1,30 @@ +{{- if .Values.ingress.enabled -}} +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: {{ .Release.Name }} + labels: + app.kubernetes.io/managed-by: {{ .Release.Service }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} +spec: + ingressClassName: {{ .Values.ingress.className }} + tls: + - hosts: + - {{ .Values.ingress.host | quote }} + secretName: {{ .Release.Name }}-tls + + rules: + - host: {{ .Values.ingress.host | quote }} + http: + paths: + - path: {{ .Values.ingress.path }} + pathType: {{ .Values.ingress.pathType }} + backend: + service: + name: {{ .Release.Name }} + port: + name: {{ .Values.service.port.name }} +{{- end -}} diff --git a/charts/backoffice/templates/job-migration.yaml b/charts/backoffice/templates/job-migration.yaml new file mode 100644 index 0000000..8b27232 --- /dev/null +++ b/charts/backoffice/templates/job-migration.yaml @@ -0,0 +1,26 @@ +apiVersion: batch/v1 +kind: Job +metadata: + name: {{ .Release.Name }} + annotations: + "helm.sh/hook": pre-install,pre-upgrade + "helm.sh/hook-weight": "-10" + "helm.sh/hook-delete-policy": before-hook-creation #,hook-succeeded +spec: + backoffLimit: 1 + ttlSecondsAfterFinished: 86400 # 1 day + activeDeadlineSeconds: 120 # 2 minutes + template: + spec: + containers: + - name: {{ .Chart.Name }}-migration + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + command: ["npx", "prisma", "migrate", "deploy"] + envFrom: + - configMapRef: + name: {{ .Release.Name }}-config + - secretRef: + name: {{ .Release.Name }}-database + - secretRef: + name: {{ .Release.Name }}-nextauth + restartPolicy: Never diff --git a/charts/backoffice/templates/job-seed.yaml b/charts/backoffice/templates/job-seed.yaml new file mode 100644 index 0000000..8c5ff26 --- /dev/null +++ b/charts/backoffice/templates/job-seed.yaml @@ -0,0 +1,26 @@ +apiVersion: batch/v1 +kind: Job +metadata: + name: {{ .Release.Name }} + annotations: + "helm.sh/hook": pre-install,pre-upgrade + "helm.sh/hook-weight": "-5" + "helm.sh/hook-delete-policy": before-hook-creation #,hook-succeeded +spec: + backoffLimit: 1 + ttlSecondsAfterFinished: 86400 # 1 day + activeDeadlineSeconds: 120 # 2 minutes + template: + spec: + containers: + - name: {{ .Chart.Name }}-seed + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + command: ["npx", "prisma", "db", "seed"] + envFrom: + - configMapRef: + name: {{ .Release.Name }}-config + - secretRef: + name: {{ .Release.Name }}-database + - secretRef: + name: {{ .Release.Name }}-nextauth + restartPolicy: Never diff --git a/charts/backoffice/templates/secret-database.yaml b/charts/backoffice/templates/secret-database.yaml new file mode 100644 index 0000000..c5feadd --- /dev/null +++ b/charts/backoffice/templates/secret-database.yaml @@ -0,0 +1,9 @@ +apiVersion: v1 +kind: Secret +metadata: + name: {{ .Release.Name }}-database + annotations: + "helm.sh/hook": pre-install,pre-upgrade + "helm.sh/hook-weight": "-15" +stringData: + DATABASE_URL: {{ .Values.backoffice.secrets.databaseURL }} diff --git a/charts/backoffice/templates/secret-nextauth.yaml b/charts/backoffice/templates/secret-nextauth.yaml new file mode 100644 index 0000000..36a8400 --- /dev/null +++ b/charts/backoffice/templates/secret-nextauth.yaml @@ -0,0 +1,12 @@ + +apiVersion: v1 +kind: Secret +metadata: + name: {{ .Release.Name }}-nextauth + annotations: + "helm.sh/hook": pre-install,pre-upgrade + "helm.sh/hook-weight": "-15" +stringData: + NEXTAUTH_SECRET: {{ .Values.backoffice.secrets.nextauthSecret }} + GOOGLE_CLIENT_ID: {{ .Values.backoffice.secrets.googleClientID }} + GOOGLE_CLIENT_SECRET: {{ .Values.backoffice.secrets.googleClientSecret }} diff --git a/charts/backoffice/templates/service.yaml b/charts/backoffice/templates/service.yaml new file mode 100644 index 0000000..4f63529 --- /dev/null +++ b/charts/backoffice/templates/service.yaml @@ -0,0 +1,18 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ .Release.Name }} + labels: + app.kubernetes.io/managed-by: {{ .Release.Service }} + +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.portNumber }} + targetPort: {{ .Values.service.portNumber }} + protocol: TCP + name: {{ .Values.service.portName }} + + selector: + app.kubernetes.io/name: {{ .Chart.Name }} + app.kubernetes.io/instance: {{ .Release.Name }} diff --git a/charts/backoffice/values.staging.yaml b/charts/backoffice/values.staging.yaml new file mode 100644 index 0000000..a19b524 --- /dev/null +++ b/charts/backoffice/values.staging.yaml @@ -0,0 +1,8 @@ +ingress: + enabled: true + host: staging.backoffice.mareshq.com + annotations: + cert-manager.io/cluster-issuer: letsencrypt-prod + cert-manager.io/issuer: letsencrypt-prod + +env: staging diff --git a/charts/backoffice/values.yaml b/charts/backoffice/values.yaml new file mode 100644 index 0000000..492a3fe --- /dev/null +++ b/charts/backoffice/values.yaml @@ -0,0 +1,38 @@ +replicaCount: 1 + +image: + repository: ghcr.io/vojtechmares/backoffice + tag: + +imagePullSecrets: {} + +ingress: + enabled: false + host: example.com + ingressClass: nginx + path: / + pathType: Prefix + annotations: + {} + # cert-manager.io/cluster-issuer: letsencrypt-prod + # cert-manager.io/issuer: letsencrypt-prod + +service: + portName: http + portNumber: 3000 + +resources: + limits: + cpu: 300m + memory: 512Mi + requests: + cpu: 100m + memory: 128Mi + +env: null + +secrets: + databaseURL: null + nextauthSecret: null + googleClientID: null + googleClientSecret: null