From 53553aae0a139823dd7abab0d06cdd179eafa4e8 Mon Sep 17 00:00:00 2001 From: dnviti Date: Sun, 14 Dec 2025 23:03:42 +0100 Subject: [PATCH] feat: Introduce a Helm chart for deploying the mtg-draft-maker application to Kubernetes and update the devlog. --- ...25-12-14-235700_docker_containerization.md | 8 +- helm/mtg-draft-maker/Chart.yaml | 6 ++ helm/mtg-draft-maker/templates/_helpers.tpl | 62 ++++++++++++++ .../mtg-draft-maker/templates/deployment.yaml | 61 ++++++++++++++ helm/mtg-draft-maker/templates/ingress.yaml | 45 ++++++++++ helm/mtg-draft-maker/templates/service.yaml | 15 ++++ .../templates/serviceaccount.yaml | 10 +++ helm/mtg-draft-maker/values.yaml | 82 +++++++++++++++++++ 8 files changed, 288 insertions(+), 1 deletion(-) create mode 100644 helm/mtg-draft-maker/Chart.yaml create mode 100644 helm/mtg-draft-maker/templates/_helpers.tpl create mode 100644 helm/mtg-draft-maker/templates/deployment.yaml create mode 100644 helm/mtg-draft-maker/templates/ingress.yaml create mode 100644 helm/mtg-draft-maker/templates/service.yaml create mode 100644 helm/mtg-draft-maker/templates/serviceaccount.yaml create mode 100644 helm/mtg-draft-maker/values.yaml diff --git a/docs/development/devlog/2025-12-14-235700_docker_containerization.md b/docs/development/devlog/2025-12-14-235700_docker_containerization.md index 3935f58..e01a4ad 100644 --- a/docs/development/devlog/2025-12-14-235700_docker_containerization.md +++ b/docs/development/devlog/2025-12-14-235700_docker_containerization.md @@ -18,7 +18,13 @@ - `GameView.tsx`: Removed unused `myCommand`, `oppGraveyard`. - `DraftManager.ts`: Removed unused `numPlayers`, `cardIndex`. - `GameManager.ts`: Renamed unused args in `shuffleLibrary`. +- **Helm Chart**: Created a complete Helm chart configuration in `helm/mtg-draft-maker`: + - `Chart.yaml`: Defined chart metadata. + - `values.yaml`: Configured defaults (Image `mtg-draft-maker:latest`, Port 3000). + - `templates/`: Added Deployment, Service, Ingress, and ServiceAccount manifests. + - Linted successfully. ## Status - Docker build successful (`docker build -t mtg-draft-maker .`). -- Image ready for deployment. +- Helm chart created and linted. +- Ready for K8s deployment. diff --git a/helm/mtg-draft-maker/Chart.yaml b/helm/mtg-draft-maker/Chart.yaml new file mode 100644 index 0000000..11b1b85 --- /dev/null +++ b/helm/mtg-draft-maker/Chart.yaml @@ -0,0 +1,6 @@ +apiVersion: v2 +name: mtg-draft-maker +description: A Helm chart for the MTG Draft Maker application +type: application +version: 0.1.0 +appVersion: "1.0.0" diff --git a/helm/mtg-draft-maker/templates/_helpers.tpl b/helm/mtg-draft-maker/templates/_helpers.tpl new file mode 100644 index 0000000..8ab7175 --- /dev/null +++ b/helm/mtg-draft-maker/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "mtg-draft-maker.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 "mtg-draft-maker.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 "mtg-draft-maker.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "mtg-draft-maker.labels" -}} +helm.sh/chart: {{ include "mtg-draft-maker.chart" . }} +{{ include "mtg-draft-maker.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "mtg-draft-maker.selectorLabels" -}} +app.kubernetes.io/name: {{ include "mtg-draft-maker.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "mtg-draft-maker.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "mtg-draft-maker.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/helm/mtg-draft-maker/templates/deployment.yaml b/helm/mtg-draft-maker/templates/deployment.yaml new file mode 100644 index 0000000..5d831a8 --- /dev/null +++ b/helm/mtg-draft-maker/templates/deployment.yaml @@ -0,0 +1,61 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "mtg-draft-maker.fullname" . }} + labels: + {{- include "mtg-draft-maker.labels" . | nindent 4 }} +spec: + {{- if not .Values.autoscaling.enabled }} + replicas: {{ .Values.replicaCount }} + {{- end }} + selector: + matchLabels: + {{- include "mtg-draft-maker.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "mtg-draft-maker.selectorLabels" . | nindent 8 }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "mtg-draft-maker.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: 3000 + protocol: TCP + livenessProbe: + httpGet: + path: /api/health + port: http + readinessProbe: + httpGet: + path: /api/health + port: http + resources: + {{- toYaml .Values.resources | nindent 12 }} + {{- 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/helm/mtg-draft-maker/templates/ingress.yaml b/helm/mtg-draft-maker/templates/ingress.yaml new file mode 100644 index 0000000..74449fd --- /dev/null +++ b/helm/mtg-draft-maker/templates/ingress.yaml @@ -0,0 +1,45 @@ +{{- if .Values.ingress.enabled -}} +{{- $fullName := include "mtg-draft-maker.fullname" . -}} +{{- $svcPort := .Values.service.port -}} +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: {{ $fullName }} + labels: + {{- include "mtg-draft-maker.labels" . | nindent 4 }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- if .Values.ingress.className }} + 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: {{ .path }} + {{- if .pathType }} + pathType: {{ .pathType }} + {{- end }} + backend: + service: + name: {{ $fullName }} + port: + number: {{ $svcPort }} + {{- end }} + {{- end }} +{{- end }} diff --git a/helm/mtg-draft-maker/templates/service.yaml b/helm/mtg-draft-maker/templates/service.yaml new file mode 100644 index 0000000..4b7a518 --- /dev/null +++ b/helm/mtg-draft-maker/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "mtg-draft-maker.fullname" . }} + labels: + {{- include "mtg-draft-maker.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + name: http + selector: + {{- include "mtg-draft-maker.selectorLabels" . | nindent 4 }} diff --git a/helm/mtg-draft-maker/templates/serviceaccount.yaml b/helm/mtg-draft-maker/templates/serviceaccount.yaml new file mode 100644 index 0000000..af4839c --- /dev/null +++ b/helm/mtg-draft-maker/templates/serviceaccount.yaml @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "mtg-draft-maker.serviceAccountName" . }} + labels: + {{- include "mtg-draft-maker.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} diff --git a/helm/mtg-draft-maker/values.yaml b/helm/mtg-draft-maker/values.yaml new file mode 100644 index 0000000..e35c43e --- /dev/null +++ b/helm/mtg-draft-maker/values.yaml @@ -0,0 +1,82 @@ +# Default values for mtg-draft-maker. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: mtg-draft-maker + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "latest" + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +serviceAccount: + # Specifies whether a service account should be created + create: 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: {} + +podSecurityContext: {} + # fsGroup: 2000 + +securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + +service: + type: ClusterIP + port: 3000 + +ingress: + enabled: false + className: "" + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + hosts: + - host: chart-example.local + paths: + - path: / + pathType: ImplementationSpecific + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.local + +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 + +autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + +nodeSelector: {} + +tolerations: [] + +affinity: {}