From 685027bf18cbfe9ad79c64283fa6ea81abd5281b Mon Sep 17 00:00:00 2001 From: Alex van den Hoogen Date: Sun, 18 Nov 2018 16:28:11 +0100 Subject: [PATCH] Fixes and optimizes the Docker build (#206) This resolves issue #203 and also optimizes the Dockerfile to use less resources. Also the current version from the Git repo is copied to the Docker container for easy access. I've taken the liberty to also update the DTLSSocket requirement to version 0.1.7 which resolves an issue regarding cython. According to their repo, nothing else has changed [1]. The RPi and RPiW Dockerfiles were not updated because of compatibility reasons. I cannot easily test those files and do not want to break anything. **References** 1. https://git.fslab.de/jkonra2m/tinydtls-cython/commits/master --- Dockerfile | 27 +++++++++------------------ README.md | 2 ++ requirements.txt | 4 ++-- script/dev_docker | 7 ++----- 4 files changed, 15 insertions(+), 25 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9f8cc97c..968b8c51 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,22 +1,13 @@ -FROM debian:latest +FROM python:3.7-stretch -# https://community.home-assistant.io/t/ikea-tradfri-gateway-zigbee-very-basic-working-implementation/14788/19?u=balloob -RUN apt-get update -y && \ - apt-get install -y python3 python3-pip git autoconf automake libtool && \ - apt-get clean && \ - rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* build/ +COPY . /usr/src/app/ -RUN mkdir -p /usr/src/app /usr/src/build -WORKDIR /usr/src/build - -RUN python3 -m pip install --upgrade pip setuptools wheel cython - -COPY ./script/install-coap-client.sh install-coap-client.sh -RUN ./install-coap-client.sh - -COPY requirements.txt requirements.txt -RUN python3 -m pip install -r requirements.txt +RUN mkdir -p /usr/src/build && \ + cd /usr/src/build && \ + pip3 install --upgrade pip setuptools wheel cython && \ + pip3 install -r /usr/src/app/requirements.txt && \ + /usr/src/app/script/install-coap-client.sh && \ + python /usr/src/app/setup.py install WORKDIR /usr/src/app -ENV LANG=C.UTF-8 -CMD /bin/bash + diff --git a/README.md b/README.md index 7eac4ff7..eaf5546e 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,8 @@ Please see the example files. There is a Docker script available to bootstrap a dev environment. Run `./script/dev_docker` and you will build and launch a container that is ready to go for both sync and async. After launching, follow the above instructions to test the library stand-alone. +The working directory of the Docker image is `/usr/src/app`. The checked out version of this repo is added there and installed as a Python dependency for easy development and testing. When you want to use the latest stable version from pip, you only have to change to another working directory. + ## Acknowledgements This is an implementation based on analysis [I](https://github.com/ggravlingen/) found [here](https://bitsex.net/software/2017/coap-endpoints-on-ikea-tradfri/) by [vidarlo](https://bitsex.net/). diff --git a/requirements.txt b/requirements.txt index 2d2936fc..36fb3788 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ aiocoap==0.4a1 -DTLSSocket==0.1.4 -typing>=3,<4 \ No newline at end of file +DTLSSocket==0.1.7 +typing>=3,<4 diff --git a/script/dev_docker b/script/dev_docker index 731df08c..82ebb2f7 100755 --- a/script/dev_docker +++ b/script/dev_docker @@ -19,9 +19,6 @@ case "$MACHINE" in esac docker build -t tradfri-dev -f "$PWD/$DOCKERFILE" . +docker run -it --rm -v `pwd`:/usr/src/app -v /etc/localtime:/etc/localtime:ro \ + --net=host tradfri-dev bash -docker run \ - --net=host \ - -v /etc/localtime:/etc/localtime:ro \ - -v `pwd`:/usr/src/app \ - -t -i --rm tradfri-dev