Skip to content

Commit 2fca36b

Browse files
committed
Merge branch 'review/pr-847'
2 parents 6037944 + b164413 commit 2fca36b

8 files changed

Lines changed: 190 additions & 0 deletions

File tree

.dockerignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
*
2+
!Containerfile*
3+
!Dockerfile
4+
!README.md
5+
!bin/container-entrypoint.sh
6+
!examples/
7+
!extra/
8+
!meshtastic/
9+
!poetry.lock
10+
!pyproject.toml
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: Create and publish Container image
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
tags:
8+
- '*.*.*'
9+
pull_request:
10+
branches:
11+
- master
12+
13+
env:
14+
REGISTRY: ghcr.io
15+
IMAGE_NAME: ${{ github.repository }}
16+
17+
jobs:
18+
build-and-push-image:
19+
runs-on: ubuntu-latest
20+
permissions:
21+
contents: read
22+
packages: write
23+
strategy:
24+
matrix:
25+
include:
26+
- container: Containerfile.debian
27+
autotag: false
28+
suffix: -debian
29+
- container: Containerfile.alpine
30+
autotag: ${{ github.ref == 'refs/heads/master' && 'true' || 'auto' }}
31+
32+
steps:
33+
- name: Checkout repository
34+
uses: actions/checkout@v4
35+
with:
36+
fetch-depth: 0
37+
38+
- name: Set up QEMU
39+
uses: docker/setup-qemu-action@v3
40+
41+
- name: Set up Docker Buildx
42+
uses: docker/setup-buildx-action@v3
43+
44+
- name: Login to Container registry
45+
if: github.event_name != 'pull_request'
46+
uses: docker/login-action@v3
47+
with:
48+
registry: ${{ env.REGISTRY }}
49+
username: ${{ github.actor }}
50+
password: ${{ secrets.GITHUB_TOKEN }}
51+
52+
- name: Docker meta
53+
id: meta
54+
uses: docker/metadata-action@v5
55+
with:
56+
images: |
57+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
58+
tags: |
59+
type=ref,event=branch
60+
type=ref,event=pr
61+
type=edge
62+
type=semver,pattern={{version}}
63+
type=semver,pattern={{major}}.{{minor}}
64+
type=semver,pattern={{major}}
65+
flavor: |
66+
latest=${{ matrix.autotag }}
67+
suffix=${{ matrix.suffix }}
68+
69+
- name: Build and push
70+
uses: docker/build-push-action@v6
71+
with:
72+
platforms: linux/amd64,linux/arm64,linux/arm/v7
73+
context: .
74+
file: ${{ matrix.container }}
75+
push: ${{ github.event_name != 'pull_request' }}
76+
tags: ${{ steps.meta.outputs.tags }}
77+
labels: ${{ steps.meta.outputs.labels }}

Containerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Containerfile.alpine

Containerfile.alpine

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# SPDX-License-Identifier: GPL-3.0-or-later
2+
#
3+
# Copyright (C) 2025 Olliver Schinagl <oliver@schinagl.nl>
4+
5+
ARG TARGET_VERSION="3.11-alpine"
6+
ARG TARGET_ARCH="library"
7+
8+
FROM docker.io/${TARGET_ARCH}/python:${TARGET_VERSION}
9+
10+
WORKDIR /tmp/build
11+
12+
COPY . /tmp/build
13+
14+
RUN _poetry_venv_dir="$(mktemp -d -p "${TMPDIR:-/tmp}" 'poetry_venv.XXXXXX')" && \
15+
python -m 'venv' "${_poetry_venv_dir}" && \
16+
"${_poetry_venv_dir}/bin/pip" install --no-cache-dir 'poetry' && \
17+
"${_poetry_venv_dir}/bin/poetry" config --local virtualenvs.create false && \
18+
"${_poetry_venv_dir}/bin/poetry" install --without dev --extras cli --extras tunnel --no-interaction --no-ansi && \
19+
addgroup -S meshtastic && \
20+
adduser -S -G meshtastic -h /home/meshtastic meshtastic && \
21+
rm -f -r "${_poetry_venv_dir}" && \
22+
rm -f -r "/tmp/build"
23+
24+
COPY "./bin/container-entrypoint.sh" "/init"
25+
RUN chmod 0755 /init
26+
27+
WORKDIR /home/meshtastic
28+
USER meshtastic
29+
30+
ENTRYPOINT [ "/init" ]

Containerfile.debian

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# SPDX-License-Identifier: GPL-3.0-or-later
2+
#
3+
# Copyright (C) 2025 Olliver Schinagl <oliver@schinagl.nl>
4+
5+
ARG TARGET_VERSION="3.11"
6+
ARG TARGET_ARCH="library"
7+
8+
FROM docker.io/${TARGET_ARCH}/python:${TARGET_VERSION}
9+
10+
WORKDIR /tmp/build
11+
12+
COPY . /tmp/build
13+
14+
RUN _poetry_venv_dir="$(mktemp -d -p "${TMPDIR:-/tmp}" 'poetry_venv.XXXXXX')" && \
15+
python -m 'venv' "${_poetry_venv_dir}" && \
16+
"${_poetry_venv_dir}/bin/pip" install --no-cache-dir 'poetry' && \
17+
"${_poetry_venv_dir}/bin/poetry" config --local virtualenvs.create false && \
18+
"${_poetry_venv_dir}/bin/poetry" install --without dev --extras cli --extras tunnel --no-interaction --no-ansi && \
19+
useradd --system --create-home --home-dir /home/meshtastic meshtastic && \
20+
rm -f -r "${_poetry_venv_dir}" && \
21+
rm -f -r "/tmp/build"
22+
23+
COPY "./bin/container-entrypoint.sh" "/init"
24+
RUN chmod 0755 /init
25+
26+
WORKDIR /home/meshtastic
27+
USER meshtastic
28+
29+
ENTRYPOINT [ "/init" ]

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Containerfile

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,24 @@ This small library (and example application) provides an easy API for sending an
2727
It also provides access to any of the operations/data available in the device user interface or the Android application.
2828
Events are delivered using a publish-subscribe model, and you can subscribe to only the message types you are interested in.
2929

30+
## Container usage
31+
32+
Container images are published to GHCR for this repository. The container entrypoint defaults to running `meshtastic`,
33+
so CLI flags can be passed directly:
34+
35+
```bash
36+
docker run --rm ghcr.io/meshtastic/python --help
37+
```
38+
39+
To run another command, pass it explicitly (for example, a shell):
40+
41+
```bash
42+
docker run --rm -it --entrypoint /bin/sh ghcr.io/meshtastic/python
43+
```
44+
45+
The container runs as a non-root user by default. When talking to local hardware, pass the serial device through
46+
explicitly (for example `--device /dev/ttyUSB0:/dev/ttyUSB0`) and ensure host device permissions allow access.
47+
3048
## Call for Contributors
3149

3250
This library and CLI has gone without a consistent maintainer for a while, and there's many improvements that could be made. We're all volunteers here and help is extremely appreciated, whether in implementing your own needs or helping maintain the library and CLI in general.

bin/container-entrypoint.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/sh
2+
# SPDX-License-Identifier: GPL-3.0-or-later
3+
#
4+
# Copyright (C) 2025 Olliver Schinagl <oliver@schinagl.nl>
5+
#
6+
# A beginning user should be able to docker run image bash (or sh) without
7+
# needing to learn about --entrypoint
8+
# https://github.com/docker-library/official-images#consistency
9+
10+
set -eu
11+
12+
bin='meshtastic'
13+
14+
# run command if it is not starting with a "-" and is an executable in PATH
15+
if [ "${#}" -le 0 ] || \
16+
[ "${1#-}" != "${1}" ] || \
17+
[ -d "${1}" ] || \
18+
! command -v "${1}" > '/dev/null' 2>&1; then
19+
entrypoint='true'
20+
fi
21+
22+
exec ${entrypoint:+${bin:?}} "${@}"
23+
24+
exit 0

0 commit comments

Comments
 (0)