New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: create environment variable for the config file #2519
Conversation
Signed-off-by: wilmardo <info@wilmardenouden.nl>
BTW, when you are open to merging this I will add some documentation :) |
Currently it is already possible to set a different location for the data directory (which contains |
Yes it does, I will try to elaborate it a bit more. This is an example deployment for the container on Kubernetes (simplified, full example here) ---
apiVersion: apps/v1
kind: Statefulset
metadata:
name: zigbee2mqtt
spec:
template:
spec:
containers:
- name: zigbee2mqtt
image: lansible/zigbee2mqtt:master
env:
- name: ZIGBEE2MQTT_DATA
value: /data
volumeMounts:
- name: zigbee2mqtt-data
mountPath: /data
- name: zigbee-usb
mountPath: /dev/ttyACM0
volumes:
- name: zigbee2mqtt-config
configMap:
name: zigbee2mqtt-config
- name: zigbee2mqtt-data
hostPath:
path: /data/zigbee2mqtt-zigbee2mqtt-data
- name: zigbee-usb
hostPath:
path: /dev/serial/by-id/usb-Texas_Instruments_TI_CC2531_USB_CDC___0X00124B00194AD7EC-if00
type: CharDevice This works as expected, the only thing is, I need to login to the node to edit the configuration.yaml. Kubernetes has a nice resource dedicated to this named configmap (docs) which can be deployed with the app. Example: ---
apiVersion: v1
kind: ConfigMap
metadata:
name: zigbee2mqtt-config
data:
configuration.yaml: |
# Home Assistant integration (MQTT discovery)
homeassistant: true
# allow new devices to join
permit_join: true
# MQTT settings
mqtt:
# MQTT base topic for zigbee2mqtt MQTT messages
base_topic: zigbee2mqtt
# MQTT server URL
server: 'mqtt://mosquitto:1883'
user: zigbee2mqtt
password: password
# Serial settings
serial:
# Location of CC2531 USB sniffer
port: /dev/ttyACM0
# Map devices to persistant storage
devices: /data/devices.yaml
groups: /data/groups.yaml
advanced:
log_output: ["console"]
log_level: debug The problem here is that the folder where the configmap gets mounted will become readonly by design (issue). The patched deployment with ---
apiVersion: apps/v1
kind: Statefulset
metadata:
name: zigbee2mqtt
spec:
template:
spec:
containers:
- name: zigbee2mqtt
image: lansible/zigbee2mqtt:master
env:
- name: ZIGBEE2MQTT_DATA
value: /data
- name: ZIGBEE2MQTT_CONFIG
value: /config
volumeMounts:
- name: zigbee2mqtt-config
mountPath: /config
- name: zigbee2mqtt-data
mountPath: /data
- name: zigbee-usb
mountPath: /dev/ttyACM0
volumes:
- name: zigbee2mqtt-config
configMap:
name: zigbee2mqtt-config
- name: zigbee2mqtt-data
hostPath:
path: /data/zigbee2mqtt-zigbee2mqtt-data
- name: zigbee-usb
hostPath:
path: /dev/serial/by-id/usb-Texas_Instruments_TI_CC2531_USB_CDC___0X00124B00194AD7EC-if00
type: CharDevice |
Definitely a valid case indeed, thanks for your comprehensive explanation! |
Introduces an environment variable for the configuration.yaml location.
Since the devices and groups can be split off this can be used to build the configuration into a Docker image since it doesn't require writing to.
For example:
This still persists the devices and groups to a volume but the configuration can be built into the image since it doesn't require changing.
I need this for to be able to use a Kubernetes configmap for the configuration. Kubernetes makes the folder where the configmap is mounted to read-only. In the current scenario this means that the whole /data directory becomes read-only. Zigbee2Mqtt tries to write the state.json to there so that results in an error.
This env var allows the configuration to exists in /config and keep the /data directory writable.