Skip to content

Commit

Permalink
switch to multistage docker build
Browse files Browse the repository at this point in the history
  • Loading branch information
jochocki committed Jan 20, 2020
1 parent 7037d90 commit f9eda29
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 32 deletions.
77 changes: 46 additions & 31 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,7 @@
#
# docker run --name rtl_433 -d -e MQTT_HOST=<mqtt-broker.example.com> --privileged -v /dev/bus/usb:/dev/bus/usb <image>

FROM debian:stretch

LABEL Description="This image is used to start a script that will monitor for events on 433,92 Mhz" Vendor="MarCoach" Version="1.0"
LABEL Maintainer="Jordan Ochocki"

#
# Define environment variables
#
# Use this variable when creating a container to specify the MQTT broker host.
ENV MQTT_HOST ""
ENV MQTT_PORT 1883
ENV MQTT_TOPIC rtl_433/+/events
ENV DISCOVERY_PREFIX homeassistant
ENV DISCOVERY_INTERVAL 600
FROM debian:stretch AS intermediate

#
# First install software packages needed to compile RTL-SDR and rtl_433
Expand All @@ -46,11 +33,6 @@ RUN apt-get update && apt-get install --no-install-recommends -y \
python-pip \
&& rm -rf /var/lib/apt/lists/*

#
# Install Paho-MQTT client
#
RUN pip install paho-mqtt

#
# Pull RTL_433 source code from GIT, compile it and install it
#
Expand All @@ -63,6 +45,51 @@ RUN git clone https://github.com/merbanan/rtl_433.git \
&& make \
&& make install

#
# Cleanup
#
#RUN apt-get purge -y \
# git \
# build-essential \
# autoconf \
# cmake \
# pkg-config \
# && apt-get autoremove -y \
# && rm -r /~/rtl_433

FROM debian:stretch AS final

#
# Define environment variables
#
# Use this variable when creating a container to specify the MQTT broker host.
ENV MQTT_HOST ""
ENV MQTT_PORT 1883
ENV MQTT_TOPIC rtl_433/+/events
ENV DISCOVERY_PREFIX homeassistant
ENV DISCOVERY_INTERVAL 600

RUN apt-get update && apt-get install --no-install-recommends -y \
libtool \
libusb-1.0.0-dev \
librtlsdr-dev \
rtl-sdr \
python \
python-setuptools \
python-wheel \
python-pip \
&& rm -rf /var/lib/apt/lists/*

COPY --from=intermediate /usr/local/include/rtl_433.h /usr/local/include/rtl_433.h
COPY --from=intermediate /usr/local/include/rtl_433_devices.h /usr/local/include/rtl_433_devices.h
COPY --from=intermediate /usr/local/bin/rtl_433 /usr/local/bin/rtl_433
COPY --from=intermediate /usr/local/etc/rtl_433 /usr/local/etc/rtl_433

#
# Install Paho-MQTT client
#
RUN pip install paho-mqtt

#
# Blacklist kernel modules for RTL devices
#
Expand All @@ -74,18 +101,6 @@ COPY rtl.blacklist.conf /etc/modprobe.d/rtl.blacklist.conf
COPY entry.sh rtl_433_mqtt_hass.py /scripts/
RUN chmod +x /scripts/entry.sh

#
# Cleanup
#
RUN apt-get purge -y \
git \
build-essential \
autoconf \
cmake \
pkg-config \
&& apt-get autoremove -y \
&& rm -r /~/rtl_433

#
# Execute entry script
#
Expand Down
2 changes: 1 addition & 1 deletion entry.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/sh
rtl_433 -F $MQTT_HOST -M utc | python /scripts/rtl_433_mqtt_hass.py
rtl_433 -F mqtt://$MQTT_HOST:$MQTT_PORT -M utc | python /scripts/rtl_433_mqtt_hass.py

0 comments on commit f9eda29

Please sign in to comment.