Browse Source

docker: add env vars $MQTT_HOST/PORT/USERNAME/PASSWORD

https://github.com/fphammerle/switchbot-mqtt/pull/16
Fabian Peter Hammerle 3 years ago
parent
commit
5f7ed542c9
3 changed files with 31 additions and 2 deletions
  1. 3 0
      CHANGELOG.md
  2. 6 1
      Dockerfile
  3. 22 1
      README.md

+ 3 - 0
CHANGELOG.md

@@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
 and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
 
 ## [Unreleased]
+### Added
+- Support parametrization via environment variables:
+  `MQTT_HOST`, `MQTT_PORT`, `MQTT_USERNAME` & `MQTT_PASSWORD`
 
 ## [0.4.1] - 2020-06-18
 ### Fixed

+ 6 - 1
Dockerfile

@@ -52,5 +52,10 @@ ARG SOURCE_DIR_PATH
 COPY --from=build $SOURCE_DIR_PATH $SOURCE_DIR_PATH
 ARG VIRTUALENV_PATH
 ENV PATH=$VIRTUALENV_PATH/bin:$PATH
+
+ENV MQTT_HOST ""
+ENV MQTT_PORT "1883"
+ENV MQTT_USERNAME ""
+ENV MQTT_PASSWORD ""
 ENTRYPOINT ["tini", "--"]
-CMD ["switchbot-mqtt", "--help"]
+CMD ["sh", "-c", "switchbot-mqtt --mqtt-host \"$MQTT_HOST\" --mqtt-port \"$MQTT_PORT\" --mqtt-username \"$MQTT_USERNAME\" --mqtt-password \"$MQTT_PASSWORD\""]

+ 22 - 1
README.md

@@ -71,7 +71,7 @@ switch:
 
 ## Docker 🐳
 
-Pre-built docker image are available at https://hub.docker.com/r/fphammerle/switchbot-mqtt/tags
+Pre-built docker images are available at https://hub.docker.com/r/fphammerle/switchbot-mqtt/tags
 
 Annotation of signed tags `docker/*` contains docker image digests: https://github.com/fphammerle/switchbot-mqtt/tags
 
@@ -83,6 +83,24 @@ $ docker run --name spelunca_switchbot \
     switchbot-mqtt --mqtt-host HOSTNAME_OR_IP_ADDRESS
 ```
 
+Alternatively, you can use `docker-compose`:
+```yaml
+version: '3.8'
+
+services:
+  switchbot-mqtt:
+    image: switchbot-mqtt
+    container_name: switchbot-mqtt
+    network_mode: host
+    userns_mode: host
+    environment:
+    - MQTT_HOST=localhost
+    - MQTT_PORT=1883
+    #- MQTT_USERNAME=username
+    #- MQTT_PASSWORD=password
+    restart: unless-stopped
+```
+
 ## MQTT Authentication
 
 ```sh
@@ -91,6 +109,9 @@ switchbot-mqtt --mqtt-username me --mqtt-password secret …
 switchbot-mqtt --mqtt-username me --mqtt-password-file /var/lib/secrets/mqtt/password …
 ```
 
+⚠️  `--mqtt-password` leaks the password to other users on the same machine,
+if `/proc` is mounted with `hidepid=0` (default).
+
 ## Alternatives
 
 * https://github.com/binsentsu/switchbot-ctrl