From 28ee17bf164464340e204d63d74c15913b93498f Mon Sep 17 00:00:00 2001 From: Marcel Hoppe Date: Wed, 26 Jun 2019 08:40:34 +0200 Subject: [PATCH] add docker support (#75) * add docker support * exit with gateway status on debug mode * Remove timezone variable * remove copying sample config --- Dockerfile | 37 +++++++++++++++++++++++++++++++++++++ start.sh | 19 +++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 Dockerfile create mode 100644 start.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..23221e4 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,37 @@ +FROM alpine:3.8 + +RUN mkdir application +WORKDIR /application +ADD . /application + +RUN apk add --no-cache tzdata python3 git bluez glib-dev make bluez-dev bluez-libs musl-dev linux-headers gcc grep && \ + python3 -m ensurepip && \ + rm -r /usr/lib/python*/ensurepip && \ + pip3 install --upgrade pip setuptools && \ + if [ ! -e /usr/bin/pip ]; then \ + ln -s pip3 /usr/bin/pip ; \ + fi && \ + if [[ ! -e /usr/bin/python ]]; then \ + ln -sf /usr/bin/python3 /usr/bin/python; \ + fi && \ + rm -r /root/.cache && \ + mkdir /config && \ + pip install -r requirements.txt && \ + ln -s /config/config.yaml ./config.yaml && \ + apk del --no-cache bluez-dev musl-dev gcc make git glib-dev linux-headers grep python2 + +RUN apk add --no-cache tzdata python3 git bluez glib-dev make bluez-dev bluez-libs musl-dev linux-headers gcc grep && \ + grep -P "(?<=REQUIREMENTS).*" workers/*.py | grep -Po "(?<=\[).*(?=\])" | tr ',' '\n' | tr "'" " "| tr "\"" " " > /tmp/requirements.txt && \ + cat /tmp/requirements.txt && \ + pip install -r /tmp/requirements.txt && \ + rm /tmp/requirements.txt && \ + apk del --no-cache bluez-dev musl-dev gcc make git glib-dev linux-headers grep python2 + +ADD ./start.sh /start.sh +RUN chmod +x /start.sh + +ENV DEBUG false + +VOLUME ["/config"] + +ENTRYPOINT ["/bin/sh", "-c", "/start.sh"] diff --git a/start.sh b/start.sh new file mode 100644 index 0000000..799bae8 --- /dev/null +++ b/start.sh @@ -0,0 +1,19 @@ + #!/bin/sh + +if ! [ -f '/config/config.yaml' ]; then + echo "There is no config.yaml! An example is created." + cp /application/config.yaml.example /config/config.yaml.example + exit 1 +fi + +cd /application +if [ "$DEBUG" = 'true' ]; then + echo "Start in debug mode" + python3 ./gateway.py -d + status=$? + echo "Gateway died..." + exit $status +else + echo "Start in normal mode" + python3 ./gateway.py +fi