From 74b7c860eac45aa54f33280261733edf59a95121 Mon Sep 17 00:00:00 2001 From: Kjeld Schouten-Lebbing Date: Wed, 13 Oct 2021 12:02:40 +0200 Subject: [PATCH] (feat) add postgresql to homeassistant (#1128) * (feat) add postgresql to homeassistant * bump --- charts/stable/home-assistant/Chart.yaml | 6 ++- .../home-assistant/SCALE/ix_values.yaml | 18 +++++++++ .../home-assistant/templates/_configmap.tpl | 38 +++++++++++++++++++ .../home-assistant/templates/common.yaml | 23 ++++++++++- charts/stable/home-assistant/values.yaml | 33 ++++++++-------- 5 files changed, 98 insertions(+), 20 deletions(-) create mode 100644 charts/stable/home-assistant/templates/_configmap.tpl diff --git a/charts/stable/home-assistant/Chart.yaml b/charts/stable/home-assistant/Chart.yaml index 2f1ab0b5444..1ddbbe8ed22 100644 --- a/charts/stable/home-assistant/Chart.yaml +++ b/charts/stable/home-assistant/Chart.yaml @@ -4,6 +4,10 @@ dependencies: - name: common repository: https://truecharts.org version: 8.3.5 +- condition: postgresql.enabled + name: postgresql + repository: https://truecharts.org/ + version: 3.0.14 deprecated: false description: home-assistant App for TrueNAS SCALE home: https://github.com/truecharts/apps/tree/master/charts/stable/home-assistant @@ -25,4 +29,4 @@ sources: - https://github.com/home-assistant/home-assistant - https://github.com/cdr/code-server type: application -version: 8.0.8 +version: 8.1.0 diff --git a/charts/stable/home-assistant/SCALE/ix_values.yaml b/charts/stable/home-assistant/SCALE/ix_values.yaml index 39f02fadb7e..ce1404f5e8a 100644 --- a/charts/stable/home-assistant/SCALE/ix_values.yaml +++ b/charts/stable/home-assistant/SCALE/ix_values.yaml @@ -9,6 +9,24 @@ image: pullPolicy: IfNotPresent tag: v2021.10.4@sha256:6f5892e307edd0b135f4ccab1ecee70518e0418b26e6264c23c67d1982eece86 +initContainers: + init-db: + image: "{{ .Values.alpineImage.repository }}:{{ .Values.alpineImage.tag }}" + command: ["/usr/sbin/init.sh"] + volumeMounts: + - name: init + mountPath: /usr/sbin + - name: config + mountPath: /config + +# -- Enable and configure postgresql database subchart under this key. +# For more options see [postgresql chart documentation](https://github.com/bitnami/charts/tree/master/bitnami/postgresql) +# @default -- See values.yaml +postgresql: + enabled: true + postgresqlUsername: home-assistant + postgresqlDatabase: home-assistant + ## # Most other defaults are set in questions.yaml # For other options please refer to the wiki, default_values.yaml or the common library chart diff --git a/charts/stable/home-assistant/templates/_configmap.tpl b/charts/stable/home-assistant/templates/_configmap.tpl new file mode 100644 index 00000000000..9ac47c9b2bc --- /dev/null +++ b/charts/stable/home-assistant/templates/_configmap.tpl @@ -0,0 +1,38 @@ +{{/* Define the configmap */}} +{{- define "hass.configmap" -}} +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "common.names.fullname" . }}-init +data: + init.sh: |- + #!/bin/sh + echo "postgresql password: {{ ( printf "%v%v:%v@%v-%v:%v/%v?client_encoding=utf8" "postgresql://" .Values.postgresql.postgresqlUsername .Values.postgresql.Password .Release.Name "postgresql" "5432" .Values.postgresql.postgresqlDatabase ) | quote }}" + if test -f "/config/configuration.yaml"; then + echo "configuration.yaml exists." + if grep -q recorder: "/config/configuration.yaml"; then + echo "configuration.yaml already contains recorder" + fi + else + echo "configuration.yaml does NOT exist." + cp /config/init/configuration.yaml.default /config/configuration.yaml + fi + configuration.yaml.default: |- + # Configure a default setup of Home Assistant (frontend, api, etc) + default_config: + + # Text to speech + tts: + - platform: google_translate + + # Example Includes + # group: !include groups.yaml + # automation: !include automations.yaml + # script: !include scripts.yaml + # scene: !include scenes.yaml + + recorder: + db_url: {{ ( printf "%s?client_encoding=utf8" ( .Values.postgresql.url.complete | trimAll "\"" ) ) | quote }} + +{{- end -}} diff --git a/charts/stable/home-assistant/templates/common.yaml b/charts/stable/home-assistant/templates/common.yaml index a6613c2ce21..0cc42ff47ee 100644 --- a/charts/stable/home-assistant/templates/common.yaml +++ b/charts/stable/home-assistant/templates/common.yaml @@ -1 +1,22 @@ -{{ include "common.all" . }} +{{/* Make sure all variables are set properly */}} +{{- include "common.setup" . }} + +{{/* Render configmap for hass */}} +{{- include "hass.configmap" . }} + +{{/* Append the general secret volumes to the volumes */}} +{{- define "hass.initvolume" -}} +enabled: "true" +mountPath: "/config/init" +readOnly: true +type: "custom" +volumeSpec: + configMap: + name: {{ include "common.names.fullname" . }}-init + defaultMode: 0777 +{{- end -}} + +{{- $_ := set .Values.persistence "init" (include "hass.initvolume" . | fromYaml) -}} + +{{/* Render the templates */}} +{{ include "common.postSetup" . }} diff --git a/charts/stable/home-assistant/values.yaml b/charts/stable/home-assistant/values.yaml index c1be9f87a7c..ea5b5c61ad3 100644 --- a/charts/stable/home-assistant/values.yaml +++ b/charts/stable/home-assistant/values.yaml @@ -14,6 +14,16 @@ service: main: port: 8123 +initContainers: + init-db: + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + command: ["/config/init/init.sh"] + volumeMounts: + - name: init + mountPath: /config/init + - name: config + mountPath: /config + # # Enable devices to be discoverable # hostNetwork: true @@ -44,27 +54,14 @@ persistence: varrun: enabled: true -# # Path to your Z-Wave / Zigbee device in the container -# additionalVolumeMounts: -# - name: zwave-usb -# mountPath: /dev/serial/by-id/usb-0658_0200-if00 - -# # Path to your Z-Wave / Zigbee device on the host -# additionalVolumes: -# - name: zwave-usb -# hostPath: -# path: /dev/serial/by-id/usb-0658_0200-if00 - -# Enabled postgres -# ... for more options see https://github.com/bitnami/charts/tree/master/bitnami/postgresql +# -- Enable and configure postgresql database subchart under this key. +# For more options see [postgresql chart documentation](https://github.com/bitnami/charts/tree/master/bitnami/postgresql) +# @default -- See values.yaml postgresql: - enabled: false + enabled: true postgresqlUsername: home-assistant - postgresqlPassword: home-assistant-pass postgresqlDatabase: home-assistant - persistence: - enabled: false - # storageClass: "" + existingSecret: "dbcreds" # Enable influxdb # ... for more options see https://github.com/bitnami/charts/tree/master/bitnami/influxdb