فهرست منبع

Add Dockerfile and docker usage details (#43)

* Added config dir to simplify docker handling

* Added a Dockerfile

* Implement suggested fix for issue #39

* Improved documentation

* Added documentation on homeasssistant-mqtt reporting mode

* Use local directory as default for config

* Update README.md
LarsAC 7 سال پیش
والد
کامیت
b795a42c50
3فایلهای تغییر یافته به همراه48 افزوده شده و 1 حذف شده
  1. 15 0
      Dockerfile
  2. 29 0
      README.md
  3. 4 1
      miflora-mqtt-daemon.py

+ 15 - 0
Dockerfile

@@ -0,0 +1,15 @@
+FROM python:3-stretch
+MAINTAINER Lars von Wedel <vonwedel@me.com>
+
+RUN mkdir -p /usr/src/app
+WORKDIR /usr/src/app
+
+RUN apt-get update && apt-get install -y bluez
+
+COPY requirements.txt requirements.txt
+RUN pip install --upgrade pip
+RUN pip install --no-cache-dir -r requirements.txt
+
+COPY . .
+
+CMD [ "python3", "./miflora-mqtt-daemon.py", "--config_dir", "/config" ]

+ 29 - 0
README.md

@@ -103,6 +103,12 @@ python3 /opt/miflora-mqtt-daemon/miflora-mqtt-daemon.py
 With a correct configuration the result should look similar to the the screencap above.
 Pay attention to communication errors due to distance related weak BLE connections.
 
+Using the command line argument `--config`, a directory where to read the config.ini file from can be specified, e.g.
+
+```shell
+python3 /opt/miflora-mqtt-daemon/miflora-mqtt-daemon.py --config /opt/miflora-config
+```
+
 The extensive output can be reduced to error messages:
 
 ```shell
@@ -135,6 +141,29 @@ This can be done either by using the internal daemon or cron.
    screen -S miflora-mqtt-daemon -d -m python3 /path/to/miflora-mqtt-daemon.py
    ```
 
+## Usage with Docker
+
+A Dockerfile in the repository can be used to build a docker container from the sources with a command such as:
+
+```shell
+docker build -t miflora-mqtt-daemon .
+```
+
+Running the container in interactive mode works like this:
+
+```shell
+docker run -it --name miflora-mqtt-daemon -v .:/config miflora-mqtt-daemon
+```
+
+To run the container in daemon mode use `-d` flag:
+
+```shell
+docker run -d --name miflora-mqtt-daemon -v .:/config miflora-mqtt-daemon
+```
+
+The `/config` volume can be used to provide a directory on the host which contains your `config.ini` file (e.g. the `.` in the above example could represent `/opt/miflora-mqtt-daemon`).
+You may need to tweak the network settings (e.g. `--network host`) for Docker depending on how your system is set up.
+
 ## Integration
 
 In the "mqtt-json" reporting mode, data will be published to the MQTT broker topic "`miflora/sensorname`" (e.g. `miflora/petunia`, names configurable).

+ 4 - 1
miflora-mqtt-daemon.py

@@ -35,6 +35,7 @@ if False:
 # Argparse
 parser = argparse.ArgumentParser(description=project_name, epilog='For further details see: ' + project_url)
 parser.add_argument('--gen-openhab', help='generate openHAB items based on configured sensors', action='store_true')
+parser.add_argument('--config_dir', help='set directory where config.ini is located', default=sys.path[0])
 parse_args = parser.parse_args()
 
 # Intro
@@ -116,9 +117,11 @@ def flores_to_openhab_items(flores, reporting_mode):
 
 
 # Load configuration file
+config_dir = parse_args.config_dir
+
 config = ConfigParser(delimiters=('=', ))
 config.optionxform = str
-config.read([os.path.join(sys.path[0], 'config.ini.dist'), os.path.join(sys.path[0], 'config.ini')])
+config.read([os.path.join(config_dir, 'config.ini.dist'), os.path.join(config_dir, 'config.ini')])
 
 reporting_mode = config['General'].get('reporting_method', 'mqtt-json')
 used_adapter = config['General'].get('adapter', 'hci0')