Skip to content

Commit b164413

Browse files
committed
Harden a bit, update some sections, add a README section
1 parent 77db301 commit b164413

4 files changed

Lines changed: 47 additions & 18 deletions

File tree

.github/workflows/container-build.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ env:
1717
jobs:
1818
build-and-push-image:
1919
runs-on: ubuntu-latest
20-
continue-on-error: true
2120
permissions:
2221
contents: read
2322
packages: write
@@ -32,26 +31,27 @@ jobs:
3231

3332
steps:
3433
- name: Checkout repository
35-
uses: actions/checkout@v3
34+
uses: actions/checkout@v4
3635
with:
3736
fetch-depth: 0
3837

3938
- name: Set up QEMU
40-
uses: docker/setup-qemu-action@v2
39+
uses: docker/setup-qemu-action@v3
4140

4241
- name: Set up Docker Buildx
43-
uses: docker/setup-buildx-action@v2
42+
uses: docker/setup-buildx-action@v3
4443

4544
- name: Login to Container registry
46-
uses: docker/login-action@v2
45+
if: github.event_name != 'pull_request'
46+
uses: docker/login-action@v3
4747
with:
4848
registry: ${{ env.REGISTRY }}
4949
username: ${{ github.actor }}
5050
password: ${{ secrets.GITHUB_TOKEN }}
5151

5252
- name: Docker meta
5353
id: meta
54-
uses: docker/metadata-action@v4
54+
uses: docker/metadata-action@v5
5555
with:
5656
images: |
5757
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
@@ -67,9 +67,9 @@ jobs:
6767
suffix=${{ matrix.suffix }}
6868
6969
- name: Build and push
70-
uses: docker/build-push-action@v4
70+
uses: docker/build-push-action@v6
7171
with:
72-
platforms: linux/amd64,linux/386,linux/arm64,linux/arm/v7,linux/arm/v6
72+
platforms: linux/amd64,linux/arm64,linux/arm/v7
7373
context: .
7474
file: ${{ matrix.container }}
7575
push: ${{ github.event_name != 'pull_request' }}

Containerfile.alpine

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,24 @@ ARG TARGET_ARCH="library"
77

88
FROM docker.io/${TARGET_ARCH}/python:${TARGET_VERSION}
99

10-
WORKDIR /usr/local/app
10+
WORKDIR /tmp/build
1111

12-
COPY . /usr/local/app
12+
COPY . /tmp/build
1313

1414
RUN _poetry_venv_dir="$(mktemp -d -p "${TMPDIR:-/tmp}" 'poetry_venv.XXXXXX')" && \
1515
python -m 'venv' "${_poetry_venv_dir}" && \
16-
"${_poetry_venv_dir}/bin/pip" install 'poetry' && \
16+
"${_poetry_venv_dir}/bin/pip" install --no-cache-dir 'poetry' && \
1717
"${_poetry_venv_dir}/bin/poetry" config --local virtualenvs.create false && \
18-
"${_poetry_venv_dir}/bin/poetry" install && \
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 && \
1921
rm -f -r "${_poetry_venv_dir}" && \
20-
rm -f -r "/usr/local/app"
22+
rm -f -r "/tmp/build"
2123

2224
COPY "./bin/container-entrypoint.sh" "/init"
25+
RUN chmod 0755 /init
26+
27+
WORKDIR /home/meshtastic
28+
USER meshtastic
2329

2430
ENTRYPOINT [ "/init" ]

Containerfile.debian

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,23 @@ ARG TARGET_ARCH="library"
77

88
FROM docker.io/${TARGET_ARCH}/python:${TARGET_VERSION}
99

10-
WORKDIR /usr/local/app
10+
WORKDIR /tmp/build
1111

12-
COPY . /usr/local/app
12+
COPY . /tmp/build
1313

1414
RUN _poetry_venv_dir="$(mktemp -d -p "${TMPDIR:-/tmp}" 'poetry_venv.XXXXXX')" && \
1515
python -m 'venv' "${_poetry_venv_dir}" && \
16-
"${_poetry_venv_dir}/bin/pip" install 'poetry' && \
16+
"${_poetry_venv_dir}/bin/pip" install --no-cache-dir 'poetry' && \
1717
"${_poetry_venv_dir}/bin/poetry" config --local virtualenvs.create false && \
18-
"${_poetry_venv_dir}/bin/poetry" install --no-directory && \
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 && \
1920
rm -f -r "${_poetry_venv_dir}" && \
20-
rm -f -r "/usr/local/app"
21+
rm -f -r "/tmp/build"
2122

2223
COPY "./bin/container-entrypoint.sh" "/init"
24+
RUN chmod 0755 /init
25+
26+
WORKDIR /home/meshtastic
27+
USER meshtastic
2328

2429
ENTRYPOINT [ "/init" ]

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.

0 commit comments

Comments
 (0)