diff --git a/Dockerfile b/Dockerfile index 7f1e404..0029eba 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,11 +7,13 @@ ENV LC_ALL en_US.UTF-8 RUN apt-get update RUN apt-get install -y --no-install-recommends \ - build-essential \ avahi-daemon \ avahi-discover \ - libnss-mdns \ - libavahi-compat-libdnssd-dev + build-essential \ + libavahi-compat-libdnssd-dev \ + libnss-mdns && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* RUN npm install -g --unsafe-perm \ homebridge \ @@ -22,11 +24,16 @@ RUN npm install -g --unsafe-perm \ cd /usr/local/lib/node_modules/hap-nodejs/node_modules/mdns && \ node-gyp BUILDTYPE=Release rebuild +EXPOSE 5353 51826 + +RUN mkdir -p /var/run/dbus/ + USER root + RUN mkdir -p /root/.homebridge VOLUME /root/.homebridge WORKDIR /root/.homebridge -EXPOSE 5353 51826 +ADD start.sh /root/.homebridge/start.sh -CMD cat /root/.homebridge/plugins.txt | xargs npm install -g --unsafe-perm && homebridge +CMD /root/.homebridge/start.sh diff --git a/Makefile b/Makefile index 221cf5e..4c97e73 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,29 @@ -build: - docker build -t rpi-homebridge . +default: build +# Default target to build the image +build: + docker build -t rpi-homebridge-dev . + +# Target to build and run and subsequently remove image run: build docker run --net=host --rm \ + -p "localhost:51826:51826" -v "$(shell pwd)/config.json:/root/.homebridge/config.json" \ -v "$(shell pwd)/plugins.txt:/root/.homebridge/plugins.txt" \ - rpi-homebridge + rpi-homebridge-dev +# Target to drop into an interractive shell shell: build docker run --net=host --rm \ + -p "localhost:51826:51826" -v "$(shell pwd)/config.json:/root/.homebridge/config.json" \ -v "$(shell pwd)/plugins.txt:/root/.homebridge/plugins.txt" \ - -it rpi-homebridge bash + -it rpi-homebridge-dev bash + +# Tags dev image so it can be pushed +tag: build + docker tag rpi-homebridge-dev vividboarder/rpi-homebridge + +# Pushes tagged image to docker hub +push: tag + docker push vividboarder/rpi-homebridge diff --git a/docker-compose.yaml b/docker-compose.yaml index 49142b9..e66da06 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,5 +1,7 @@ homebridge: build: . + ports: + - "51826:51826" net: host volumes: - ./config.json:/root/.homebridge/config.json diff --git a/start.sh b/start.sh new file mode 100755 index 0000000..a94afe1 --- /dev/null +++ b/start.sh @@ -0,0 +1,14 @@ +#! /bin/sh + +# Fix avahi +sed -i "s/rlimit-nproc=3/#rlimit-nproc=3/" /etc/avahi/avahi-daemon.conf +dbus-daemon --system +avahi-daemon -D +service dbus start +service avahi-daemon start + +# Install desired plugins +cat /root/.homebridge/plugins.txt | xargs npm install -g --unsafe-perm + +# Start service +homebridge