robertmuth / PyZwaver

Z-Wave library written in Python3
GNU General Public License v3.0
38 stars 9 forks source link

Docker Compatibility #9

Closed OnnoH closed 5 years ago

OnnoH commented 5 years ago

Use Python 3.7 (I guess 3.6 might also work), because of the used variable annotation syntax.

The default path of 3.7 is /usr/local/bin instead of /usr/bin used in the scripts. Adjust the scripts or add a symbolic link: ln -s /usr/local/bin/python3 /usr/bin/python3

I installed a Docker image on my Raspberry Pi 3: Python 3.7.0 on Alpine 3.8.1 docker pull python@sha256:7c03d9ec02119be8365d1860d909f1f62e10067399775703949e429b67d4f093

and tag it docker tag $(docker image ls --digests | grep sha256:7c03d9ec02119be8365d1860d909f1f62e10067399775703949e429b67d4f093 | awk '{{ print $4 }}') python:3.7

The code depends on the serial library (ModuleNotFoundError: No module named 'serial') pip install pyserial

OnnoH commented 5 years ago

The Dockerfile below uses the image mentioned above as base and installs the PyZwaver latest with the dependencies.

Build it: docker build -t pyzwaver .

Run it: docker run --detach --name=zwvr -p 44444:44444 --device=/dev/ttyUSB0:/dev/ttyUSB0 pyzwaver

View UI: http://raspberrypi.ip:44444

View logs: docker logs -f zwvr

Dockerfile

FROM python:3.7

RUN pip install pyserial \
    && pip install tornado \
    && ln -s /usr/local/bin/python3 /usr/bin/python3 \
    && wget -O /tmp/master.zip https://github.com/robertmuth/PyZwaver/archive/master.zip \
    && mkdir -p /opt \
    && unzip /tmp/master.zip -d /opt \
    && mv /opt/PyZwaver-master /opt/pyzwaver \
    && rm /tmp/master.zip

EXPOSE 44444

WORKDIR /opt/pyzwaver

CMD ["/opt/pyzwaver/example_webserver.py", "--port=44444"]