Skip to content

Commit

Permalink
meshtasticd-docker: simplify, add USB compose
Browse files Browse the repository at this point in the history
  • Loading branch information
vidplace7 authored and fifieldt committed Dec 25, 2024
1 parent fbdd6e7 commit cec075b
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 44 deletions.
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Absolute path to the local meshtastic config.yaml file
CONFIG_PATH=/path/to/meshtastic/config.yaml
# USB device to passthrough (`lsusb -t`: look for `ch341`)
USB_DEVICE=/dev/bus/usb/001/037
63 changes: 28 additions & 35 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,32 +1,23 @@
FROM debian:bookworm-slim AS builder

FROM python:3.12-bookworm AS builder
ENV DEBIAN_FRONTEND=noninteractive
ENV TZ=Etc/UTC

# http://bugs.python.org/issue19846
# > At the moment, setting "LANG=C" on a Linux system *fundamentally breaks Python 3*, and that's not OK.
ENV LANG C.UTF-8

# Install build deps
USER root

# trunk-ignore(terrascan/AC_DOCKER_0002): Known terrascan issue
# trunk-ignore(hadolint/DL3008): Use latest version of packages for buildchain
RUN apt-get update && apt-get install --no-install-recommends -y wget python3 python3-pip python3-wheel python3-venv g++ zip git \
ca-certificates libgpiod-dev libyaml-cpp-dev libbluetooth-dev \
libusb-1.0-0-dev libulfius-dev liborcania-dev libssl-dev pkg-config && \
apt-get clean && rm -rf /var/lib/apt/lists/* && mkdir /tmp/firmware

RUN groupadd -g 1000 mesh && useradd -ml -u 1000 -g 1000 mesh && chown mesh:mesh /tmp/firmware
USER mesh
# Install Dependencies
ENV PIP_ROOT_USER_ACTION=ignore
RUN apt-get update && apt-get install --no-install-recommends -y wget g++ zip git ca-certificates \
libgpiod-dev libyaml-cpp-dev libbluetooth-dev libi2c-dev \
libusb-1.0-0-dev libulfius-dev liborcania-dev libssl-dev pkg-config && \
apt-get clean && rm -rf /var/lib/apt/lists/* && \
pip install --no-cache-dir -U platformio==6.1.16 && \
mkdir /tmp/firmware

# Copy source code
WORKDIR /tmp/firmware
RUN python3 -m venv /tmp/firmware
RUN bash -o pipefail -c "source bin/activate; pip3 install --no-cache-dir -U platformio==6.1.15"
# trunk-ignore(terrascan/AC_DOCKER_00024): We would actually like these files to be owned by mesh tyvm
COPY --chown=mesh:mesh . /tmp/firmware
RUN bash -o pipefail -c "source ./bin/activate && bash ./bin/build-native.sh"
RUN cp "/tmp/firmware/release/meshtasticd_linux_$(uname -m)" "/tmp/firmware/release/meshtasticd"
COPY . /tmp/firmware

# Build
RUN bash ./bin/build-native.sh && \
cp "/tmp/firmware/release/meshtasticd_linux_$(uname -m)" "/tmp/firmware/release/meshtasticd"


##### PRODUCTION BUILD #############
Expand All @@ -35,20 +26,22 @@ FROM debian:bookworm-slim
ENV DEBIAN_FRONTEND=noninteractive
ENV TZ=Etc/UTC

# trunk-ignore(terrascan/AC_DOCKER_0002): Known terrascan issue
# trunk-ignore(hadolint/DL3008): Use latest version of packages for buildchain
RUN apt-get update && apt-get --no-install-recommends -y install libc-bin libc6 libgpiod2 libyaml-cpp0.7 libulfius2.7 libusb-1.0-0-dev liborcania2.3 libssl3 && \
apt-get clean && rm -rf /var/lib/apt/lists/*
RUN apt-get update && apt-get --no-install-recommends -y install libc-bin libc6 libgpiod2 libyaml-cpp0.7 libi2c0 libulfius2.7 libusb-1.0-0-dev liborcania2.3 libssl3 && \
apt-get clean && rm -rf /var/lib/apt/lists/* \
&& mkdir -p /var/lib/meshtasticd \
&& mkdir -p /etc/meshtasticd/config.d

RUN groupadd -g 1000 mesh && useradd -ml -u 1000 -g 1000 mesh
USER mesh
# Fetch compiled binary from the builder
COPY --from=builder /tmp/firmware/release/meshtasticd /usr/sbin/
# Copy config templates
COPY ./bin/config.d /etc/meshtasticd/available.d

WORKDIR /home/mesh
COPY --from=builder /tmp/firmware/release/meshtasticd /home/mesh/
WORKDIR /var/lib/meshtasticd
VOLUME /var/lib/meshtasticd

RUN mkdir data
VOLUME /home/mesh/data
# Expose Meshtastic TCP API port from the host
EXPOSE 4403

CMD [ "sh", "-cx", "./meshtasticd -d /home/mesh/data --hwid=${HWID:-$RANDOM}" ]
CMD [ "sh", "-cx", "meshtasticd -d /var/lib/meshtasticd" ]

HEALTHCHECK NONE
31 changes: 22 additions & 9 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
version: "3.7"
# USB-Based Meshtastic container-node!

# Copy .env.example to .env and set the USB_DEVICE and CONFIG_PATH variables

services:
meshtastic-node:
build: .
deploy:
mode: replicated
replicas: 4
networks:
- mesh

networks:
mesh:
container_name: meshtasticd

# Pass USB device through to the container
devices:
- "${USB_DEVICE}"

# Mount local config file and named volume for data persistence
volumes:
- "${CONFIG_PATH}:/etc/meshtasticd/config.yaml:ro"
- "meshtastic_data:/var/lib/meshtasticd"

# Forward the container’s port 4403 to the host
ports:
- "4403:4403"

restart: unless-stopped

volumes:
meshtastic_data:

0 comments on commit cec075b

Please sign in to comment.