Skip to content

Commit 29755a7

Browse files
committed
Container: Add initial container for meshtastic-cli
Just a quick set of files to enable the build of (tagged) containers. Both alpine and debian containers are available (~200MiB/~1.2GiB) allowing us to use meshtastic cli with a quick docker run, instead of having to build/install stuff locally. Signed-off-by: Olliver Schinagl <[email protected]>
1 parent dcd077d commit 29755a7

File tree

6 files changed

+143
-0
lines changed

6 files changed

+143
-0
lines changed
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+
- 'v*'
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+
continue-on-error: true
21+
permissions:
22+
contents: read
23+
packages: write
24+
strategy:
25+
matrix:
26+
include:
27+
- container: Containerfile.debian
28+
autotag: false
29+
suffix: -debian
30+
- container: Containerfile.alpine
31+
autotag: ${{ github.ref == 'refs/heads/master' && 'true' || 'auto' }}
32+
33+
steps:
34+
- name: Checkout repository
35+
uses: actions/checkout@v3
36+
with:
37+
fetch-depth: 0
38+
39+
- name: Set up QEMU
40+
uses: docker/setup-qemu-action@v2
41+
42+
- name: Set up Docker Buildx
43+
uses: docker/setup-buildx-action@v2
44+
45+
- name: Login to Container registry
46+
uses: docker/login-action@v2
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@v4
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@v4
71+
with:
72+
platforms: linux/amd64,linux/386,linux/arm64,linux/arm/v7,linux/arm/v6
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: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
ARG TARGET_VERSION="3.11-alpine"
2+
ARG TARGET_ARCH="library"
3+
4+
FROM docker.io/${TARGET_ARCH}/python:${TARGET_VERSION}
5+
6+
WORKDIR /usr/local/app
7+
8+
COPY . /usr/local/app
9+
10+
RUN _poetry_venv_dir="$(mktemp -d -p "${TMPDIR:-/tmp}" 'poetry_venv.XXXXXX')" && \
11+
python -m 'venv' "${_poetry_venv_dir}" && \
12+
"${_poetry_venv_dir}/bin/pip" install 'poetry' && \
13+
"${_poetry_venv_dir}/bin/poetry" config --local virtualenvs.create false && \
14+
"${_poetry_venv_dir}/bin/poetry" install && \
15+
rm -f -r "${_poetry_venv_dir}" && \
16+
rm -f -r "/src"
17+
18+
COPY "./bin/container-entrypoint.sh" "/init"
19+
20+
ENTRYPOINT [ "/init" ]

Containerfile.debian

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
ARG TARGET_VERSION="3.11"
2+
ARG TARGET_ARCH="library"
3+
4+
FROM docker.io/${TARGET_ARCH}/python:${TARGET_VERSION}
5+
6+
WORKDIR /usr/local/app
7+
8+
COPY . /usr/local/app
9+
10+
RUN _poetry_venv_dir="$(mktemp -d -p "${TMPDIR:-/tmp}" 'poetry_venv.XXXXXX')" && \
11+
python -m 'venv' "${_poetry_venv_dir}" && \
12+
"${_poetry_venv_dir}/bin/pip" install 'poetry' && \
13+
"${_poetry_venv_dir}/bin/poetry" config --local virtualenvs.create false && \
14+
"${_poetry_venv_dir}/bin/poetry" install --no-directory && \
15+
rm -f -r "${_poetry_venv_dir}" && \
16+
rm -f -r "/src"
17+
18+
COPY "./bin/container-entrypoint.sh" "/init"
19+
20+
ENTRYPOINT [ "/init" ]

Dockerfile

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

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 <[email protected]>
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)