Immich: Add Immich installer configuration

Change-Id: I88796e42d0b0b14d84b094d4a1c5213b43c56f2a
diff --git a/charts/immich/templates/checks.yaml b/charts/immich/templates/checks.yaml
new file mode 100644
index 0000000..b67aa67
--- /dev/null
+++ b/charts/immich/templates/checks.yaml
@@ -0,0 +1,7 @@
+{{- $name := .Values.immich.persistence.library.existingClaim | required ".Values.immich.persistence.library.existingClaim is required." -}}
+
+{{ if .Values.postgresql.enabled }}
+  {{ if not .Values.useDeprecatedPostgresChart}}
+    {{ fail "The postgres subchart is deprecated. Please see https://github.com/immich-app/immich-charts/issues/149 for more detail." }}
+  {{ end }}
+{{ end }}
diff --git a/charts/immich/templates/immich-config.yml b/charts/immich/templates/immich-config.yml
new file mode 100644
index 0000000..1a23cf9
--- /dev/null
+++ b/charts/immich/templates/immich-config.yml
@@ -0,0 +1,15 @@
+{{- if .Values.immich.configuration }}
+apiVersion: v1
+kind: ConfigMap
+metadata:
+  name: {{ .Release.Name }}-immich-config
+  labels:
+    app.kubernetes.io/instance: {{ .Release.Name }}
+    app.kubernetes.io/managed-by: {{ .Release.Service }}
+    app.kubernetes.io/name: {{ .Chart.Name }}
+    app.kubernetes.io/version: {{ .Chart.AppVersion }}
+    helm.sh/chart: {{ printf "%s-%s\n" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
+data:
+  immich-config.yaml: |
+{{- .Values.immich.configuration | toYaml | nindent 4 }}
+{{- end }}
diff --git a/charts/immich/templates/machine-learning.yaml b/charts/immich/templates/machine-learning.yaml
new file mode 100644
index 0000000..2ab84f4
--- /dev/null
+++ b/charts/immich/templates/machine-learning.yaml
@@ -0,0 +1,52 @@
+{{- define "immich.machine-learning.hardcodedValues" -}}
+global:
+  nameOverride: machine-learning
+
+controller:
+  strategy: RollingUpdate
+
+service:
+  main:
+    enabled: true
+    primary: true
+    type: ClusterIP
+    ports:
+      http:
+        enabled: true
+        primary: true
+        port: 3003
+        protocol: HTTP
+
+probes:
+  liveness: &probes
+    enabled: true
+    custom: true
+    spec:
+      httpGet:
+        path: /ping
+        port: http
+      initialDelaySeconds: 0
+      periodSeconds: 10
+      timeoutSeconds: 1
+      failureThreshold: 3
+  readiness: *probes
+  startup:
+    enabled: true
+    custom: true
+    spec:
+      httpGet:
+        path: /ping
+        port: http
+      initialDelaySeconds: 0
+      periodSeconds: 10
+      timeoutSeconds: 1
+      failureThreshold: 60
+{{- end }}
+
+{{- /* Have to reference with index here because the dash breaks a normal dereference */}}
+{{ if (index .Values "machine-learning").enabled }}
+{{- $ctx := deepCopy . -}}
+{{- $_ := get .Values "machine-learning" | mergeOverwrite $ctx.Values -}}
+{{- $_ = include "immich.machine-learning.hardcodedValues" . | fromYaml | merge $ctx.Values -}}
+{{- include "bjw-s.common.loader.all" $ctx }}
+{{ end }}
diff --git a/charts/immich/templates/server.yaml b/charts/immich/templates/server.yaml
new file mode 100644
index 0000000..5b63583
--- /dev/null
+++ b/charts/immich/templates/server.yaml
@@ -0,0 +1,101 @@
+{{- define "immich.server.hardcodedValues" -}}
+global:
+  nameOverride: server
+
+env:
+  {{ if .Values.immich.metrics.enabled }}
+      IMMICH_TELEMETRY_INCLUDE: all
+  {{ end }}
+  {{- if .Values.immich.existingConfiguration }}
+      IMMICH_CONFIG_FILE: /config/immich-config.json
+  {{- else if .Values.immich.configuration }}
+      IMMICH_CONFIG_FILE: /config/immich-config.yaml
+  {{- end }}
+
+{{- if .Values.immich.configuration }}
+podAnnotations:
+  checksum/config: {{ .Values.immich.configuration | toYaml | sha256sum }}
+{{- end }}
+
+controller:
+  strategy: RollingUpdate
+
+service:
+  main:
+    enabled: true
+    primary: true
+    type: ClusterIP
+    ports:
+      http:
+        enabled: true
+        primary: true
+        port: 2283
+        protocol: HTTP
+      metrics-api:
+        enabled: {{ .Values.immich.metrics.enabled }}
+        port: 8081
+        protocol: HTTP
+      metrics-ms:
+        enabled: {{ .Values.immich.metrics.enabled }}
+        port: 8082
+        protocol: HTTP
+
+
+serviceMonitor:
+  main:
+    enabled: {{ .Values.immich.metrics.enabled }}
+    endpoints:
+      - port: metrics-api
+        scheme: http
+      - port: metrics-ms
+        scheme: http
+
+probes:
+  liveness: &probes
+    enabled: true
+    custom: true
+    spec:
+      httpGet:
+        path: /api/server/ping
+        port: http
+      initialDelaySeconds: 0
+      periodSeconds: 10
+      timeoutSeconds: 1
+      failureThreshold: 3
+  readiness: *probes
+  startup:
+    enabled: true
+    custom: true
+    spec:
+      httpGet:
+        path: /api/server/ping
+        port: http
+      initialDelaySeconds: 0
+      periodSeconds: 10
+      timeoutSeconds: 1
+      failureThreshold: 30
+
+persistence:
+{{- if .Values.immich.existingConfiguration }}
+  config:
+    enabled: true
+    type: configMap
+    name: {{ .Values.immich.existingConfiguration }}
+{{- else if .Values.immich.configuration }}
+  config:
+    enabled: true
+    type: configMap
+    name: {{ .Release.Name }}-immich-config
+{{- end }}
+  library:
+    enabled: true
+    mountPath: /usr/src/app/upload
+    existingClaim: {{ .Values.immich.persistence.library.existingClaim }}
+{{- end }}
+
+{{ if .Values.server.enabled }}
+{{- $ctx := deepCopy . -}}
+{{- $_ := get .Values "server" | mergeOverwrite $ctx.Values -}}
+{{- $_ = include "immich.server.hardcodedValues" . | fromYaml | merge $ctx.Values -}}
+{{- include "bjw-s.common.loader.all" $ctx }}
+{{ end }}