|
| 1 | +# syntax=docker/dockerfile:1.7 |
| 2 | +# |
| 3 | +# taptap-mqtt — Tigo TAP/CCA optimizer data → MQTT, packaged as a multi-arch container. |
| 4 | +# |
| 5 | +# Bundles two upstream projects at pinned versions: |
| 6 | +# - taptap (Rust, MIT) https://github.com/litinoveweedle/taptap — reads the Tigo RS-485 bus |
| 7 | +# - taptap-mqtt (Python, GPL) https://github.com/litinoveweedle/taptap-mqtt — publishes to MQTT (HA discovery) |
| 8 | +# |
| 9 | +# Build args let you bump either version without touching the file: |
| 10 | +# docker build --build-arg TAPTAP_VERSION=v0.2.6 --build-arg TAPTAP_MQTT_VERSION=v0.2.6 . |
| 11 | +# |
| 12 | +# Supported platforms (mapped to the upstream musl release assets): |
| 13 | +# linux/amd64 → x86_64, linux/arm64 → arm64, linux/arm/v7 → armv7, linux/arm/v6 → arm, linux/386 → i686 |
| 14 | + |
| 15 | +ARG PYTHON_VERSION=3.12 |
| 16 | + |
| 17 | +# ---------------------------------------------------------------- stage 1: fetch upstream artefacts |
| 18 | +FROM --platform=$BUILDPLATFORM debian:bookworm-slim AS fetch |
| 19 | + |
| 20 | +ARG TAPTAP_VERSION=v0.2.6 |
| 21 | +ARG TAPTAP_MQTT_VERSION=v0.2.6 |
| 22 | +ARG TARGETARCH |
| 23 | +ARG TARGETVARIANT |
| 24 | + |
| 25 | +RUN apt-get update \ |
| 26 | + && apt-get install -y --no-install-recommends ca-certificates curl \ |
| 27 | + && rm -rf /var/lib/apt/lists/* |
| 28 | + |
| 29 | +# taptap: pick the release asset for the *target* platform, verify the published SHA-256, extract the binary. |
| 30 | +RUN set -eu; \ |
| 31 | + case "${TARGETARCH}/${TARGETVARIANT:-}" in \ |
| 32 | + amd64/*) asset=taptap-Linux-musl-x86_64 ;; \ |
| 33 | + arm64/*) asset=taptap-Linux-musl-arm64 ;; \ |
| 34 | + arm/v7) asset=taptap-Linux-musleabihf-armv7 ;; \ |
| 35 | + arm/v6) asset=taptap-Linux-musleabihf-arm ;; \ |
| 36 | + 386/*) asset=taptap-Linux-musl-i686 ;; \ |
| 37 | + *) echo "unsupported platform ${TARGETARCH}/${TARGETVARIANT:-}" >&2; exit 1 ;; \ |
| 38 | + esac; \ |
| 39 | + base="https://github.com/litinoveweedle/taptap/releases/download/${TAPTAP_VERSION}"; \ |
| 40 | + mkdir -p /out/taptap && cd /out/taptap; \ |
| 41 | + curl -fsSLo "${asset}.tar.gz" "${base}/${asset}.tar.gz"; \ |
| 42 | + curl -fsSLo "${asset}.tar.gz.sha256" "${base}/${asset}.tar.gz.sha256"; \ |
| 43 | + sha256sum -c "${asset}.tar.gz.sha256"; \ |
| 44 | + tar -xzf "${asset}.tar.gz" taptap; \ |
| 45 | + rm -f "${asset}.tar.gz" "${asset}.tar.gz.sha256"; \ |
| 46 | + chmod 0755 taptap |
| 47 | + |
| 48 | +# taptap-mqtt: source tarball of the tagged release (no git needed in the image). |
| 49 | +RUN set -eu; \ |
| 50 | + mkdir -p /out/taptap-mqtt; \ |
| 51 | + curl -fsSL "https://github.com/litinoveweedle/taptap-mqtt/archive/refs/tags/${TAPTAP_MQTT_VERSION}.tar.gz" \ |
| 52 | + | tar -xz --strip-components=1 -C /out/taptap-mqtt |
| 53 | + |
| 54 | +# ---------------------------------------------------------------- stage 2: runtime image |
| 55 | +FROM python:${PYTHON_VERSION}-slim |
| 56 | + |
| 57 | +ARG TAPTAP_VERSION=v0.2.6 |
| 58 | +ARG TAPTAP_MQTT_VERSION=v0.2.6 |
| 59 | + |
| 60 | +LABEL org.opencontainers.image.title="taptap-mqtt" \ |
| 61 | + org.opencontainers.image.description="Tigo TAP/CCA optimizer data to MQTT (taptap + taptap-mqtt), multi-arch" \ |
| 62 | + org.opencontainers.image.source="https://github.com/SmartNightly/taptap-mqtt-docker" \ |
| 63 | + org.opencontainers.image.licenses="MIT AND GPL-3.0-only" \ |
| 64 | + taptap.version="${TAPTAP_VERSION}" \ |
| 65 | + taptap-mqtt.version="${TAPTAP_MQTT_VERSION}" |
| 66 | + |
| 67 | +# Python deps of taptap-mqtt (paho-mqtt, python-dateutil, uptime) |
| 68 | +COPY --from=fetch /out/taptap-mqtt/requirements.txt /tmp/requirements.txt |
| 69 | +RUN pip install --no-cache-dir -r /tmp/requirements.txt && rm -f /tmp/requirements.txt |
| 70 | + |
| 71 | +COPY --from=fetch /out/taptap/taptap /usr/local/bin/taptap |
| 72 | +COPY --from=fetch /out/taptap-mqtt/taptap-mqtt.py /opt/taptap-mqtt/taptap-mqtt.py |
| 73 | +COPY --from=fetch /out/taptap-mqtt/LICENSE /opt/taptap-mqtt/LICENSE |
| 74 | +COPY --from=fetch /out/taptap-mqtt/README.md /opt/taptap-mqtt/README.md |
| 75 | + |
| 76 | +# Unprivileged runtime user. /config holds config.ini (read-only bind mount), |
| 77 | +# /data the persisted optimizer topology (STATE_FILE), /run/taptap the RUN_FILE heartbeat. |
| 78 | +RUN groupadd --gid 1000 taptap \ |
| 79 | + && useradd --uid 1000 --gid taptap --home-dir /opt/taptap-mqtt --no-create-home --shell /usr/sbin/nologin taptap \ |
| 80 | + && mkdir -p /config /data /run/taptap \ |
| 81 | + && chown -R taptap:taptap /data /run/taptap \ |
| 82 | + && /usr/local/bin/taptap --version |
| 83 | + |
| 84 | +USER taptap |
| 85 | +WORKDIR /opt/taptap-mqtt |
| 86 | +VOLUME ["/data"] |
| 87 | + |
| 88 | +# taptap-mqtt touches RUN_FILE while it runs and removes it on shutdown → cheap liveness probe. |
| 89 | +HEALTHCHECK --interval=60s --timeout=5s --start-period=90s --retries=3 \ |
| 90 | + CMD test -f /run/taptap/taptap.run || exit 1 |
| 91 | + |
| 92 | +ENTRYPOINT ["python3", "/opt/taptap-mqtt/taptap-mqtt.py"] |
| 93 | +CMD ["/config/config.ini"] |
0 commit comments