Skip to content
This repository has been archived by the owner on Oct 26, 2023. It is now read-only.

Commit

Permalink
Improve docker setup (#146)
Browse files Browse the repository at this point in the history
* Improve docker setup

* More fixes

* Readme update
  • Loading branch information
zewelor authored Jan 27, 2020
1 parent 8bfb5b2 commit c6373e7
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 92 deletions.
8 changes: 8 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/config.yaml
Dockerfile*
.git
.idea
.venv
.github
__pycache__
__pycache__/*
46 changes: 16 additions & 30 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,37 +1,23 @@
FROM alpine:3.8
FROM python:3.8-alpine3.11

ENV DEBUG false

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 bluez-deprecated musl-dev linux-headers gcc grep sudo && \
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
COPY requirements.txt /application

VOLUME ["/config"]
RUN apk add --no-cache tzdata bluez bluez-libs sudo bluez-deprecated && \
ln -s /config.yaml ./config.yaml && \
pip install -r requirements.txt

COPY . /application

RUN apk add --no-cache --virtual build-dependencies git bluez-dev musl-dev make gcc glib-dev musl-dev && \
pip install `./gateway.py -r all` && \
apk del build-dependencies

COPY ./start.sh /start.sh
RUN chmod +x /start.sh

ENTRYPOINT ["/bin/sh", "-c", "/start.sh"]
47 changes: 17 additions & 30 deletions Dockerfile.arm32v7
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,28 @@ FROM alpine AS builder
ENV QEMU_URL https://github.com/balena-io/qemu/releases/download/v3.0.0%2Bresin/qemu-3.0.0+resin-arm.tar.gz
RUN apk add curl && curl -L ${QEMU_URL} | tar zxvf - -C . --strip-components 1

FROM arm32v7/alpine:3.9
FROM arm32v7/python:3.8-alpine3.11

COPY --from=builder qemu-arm-static /usr/bin

ENV DEBUG false

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 bluez-deprecated musl-dev linux-headers gcc grep sudo && \
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
COPY requirements.txt /application

VOLUME ["/config"]
RUN apk add --no-cache tzdata bluez bluez-libs sudo bluez-deprecated && \
ln -s /config.yaml ./config.yaml && \
pip install -r requirements.txt

COPY . /application

RUN apk add --no-cache --virtual build-dependencies git bluez-dev musl-dev make gcc glib-dev musl-dev && \
pip install `./gateway.py -r all` && \
apk del build-dependencies

COPY ./start.sh /start.sh
RUN chmod +x /start.sh

ENTRYPOINT ["/bin/sh", "-c", "/start.sh"]
47 changes: 17 additions & 30 deletions Dockerfile.arm64v8
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,28 @@ FROM alpine AS builder
ENV QEMU_URL https://github.com/balena-io/qemu/releases/download/v3.0.0%2Bresin/qemu-3.0.0+resin-aarch64.tar.gz
RUN apk add curl && curl -L ${QEMU_URL} | tar zxvf - -C . --strip-components 1

FROM arm64v8/alpine:3.9
FROM arm64v8/python:3.8-alpine3.11

COPY --from=builder qemu-aarch64-static /usr/bin

ENV DEBUG false

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 bluez-deprecated musl-dev linux-headers gcc grep sudo && \
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
COPY requirements.txt /application

VOLUME ["/config"]
RUN apk add --no-cache tzdata bluez bluez-libs sudo bluez-deprecated && \
ln -s /config.yaml ./config.yaml && \
pip install -r requirements.txt

COPY . /application

RUN apk add --no-cache --virtual build-dependencies git bluez-dev musl-dev make gcc glib-dev musl-dev && \
pip install `./gateway.py -r all` && \
apk del build-dependencies

COPY ./start.sh /start.sh
RUN chmod +x /start.sh

ENTRYPOINT ["/bin/sh", "-c", "/start.sh"]
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,24 @@ source .venv/bin/activate
pip3 install -r requirements.txt
```

All needed python libs, per each worker, should be auto installed on run. If now you can install them manually:

```shell
pip3 install `./gateway.py -r configured`
```

### Docker
There are prebuilt docker images at https://hub.docker.com/r/zewelor/bt-mqtt-gateway/tags.
Thanks @hobbypunk90 and @krasnoukhov for docker work.

Mount config.yaml as /config.yaml volume

Example exec

```shell
docker run -d --name bt-mqtt-gateway --network=host -v $PWD/config.yaml:/config.yaml zewelor/bt-mqtt-gateway
```

## Configuration

All worker configuration is done in the file [`config.yaml`](config.yaml.example).
Expand Down
4 changes: 2 additions & 2 deletions start.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/sh

if ! [ -f '/config/config.yaml' ]; then
if ! [ -f '/config.yaml' ]; then
echo "There is no config.yaml! An example is created."
cp /application/config.yaml.example /config/config.yaml.example
cp /application/config.yaml.example /config.yaml.example
exit 1
fi

Expand Down

0 comments on commit c6373e7

Please sign in to comment.