meshcore-exporter 1.0.0
Prometheus exporter for MeshCore repeaters, read over the mesh: a companion (USB, BLE, or a companion identity in openHop over TCP) logs in to each repeater, asks for status and telemetry with direct packets and serves battery, temperature/humidity, noise floor, RSSI/SNR, packet counters, airtime and uptime on :9200/metrics. - meshcore_exporter.py: command line, MC_* environment or a TOML file with a password per repeater; --check reads every repeater once and exits; interval 1 h (min 15 min); a failed repeater is retried once after 3 min; contacts fetched once per round. - dashboards/: the Grafana dashboard, generated from generate.py (datasource, job and the rate window are variables; TX drawn above zero, RX below). - stack/: Docker Compose with Prometheus and Grafana provisioned, for a USB companion, or on the host network for openHop on the same machine. - systemd/: running without Docker. - README.md (Czech) and AGENTS.md for setting it up with an AI agent. - CI: lint and tests, gitleaks; PR check builds the image; single-platform images per architecture behind a Trivy gate (latest-<arch>, and X.Y.Z-<arch> with a release on tag vX.Y.Z); dependencies by Renovate. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
2a9126e258
30 files changed
+3181
No files matched your search
@@ -0,0 +1,50 @@
|
||||
# Lint + tests on every push and PR; the image is built by image.yml.
|
||||
name: ci
|
||||
|
||||
"on":
|
||||
push:
|
||||
pull_request:
|
||||
workflow_dispatch:
|
||||
|
||||
env:
|
||||
RUFF_VERSION: "0.15.7"
|
||||
MYPY_VERSION: "1.19.1"
|
||||
YAMLLINT_VERSION: "1.38.0"
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
|
||||
- name: gitleaks
|
||||
uses: https://git.rfa.cz/tth-pub/ci-actions/gitleaks@v11
|
||||
with:
|
||||
mode: block
|
||||
|
||||
- uses: actions/setup-python@v7
|
||||
with:
|
||||
python-version: "3.15"
|
||||
|
||||
- name: Install
|
||||
run: |
|
||||
set -euo pipefail
|
||||
python -m pip install --quiet -r requirements.txt pytest \
|
||||
"ruff==$RUFF_VERSION" "mypy==$MYPY_VERSION" "yamllint==$YAMLLINT_VERSION"
|
||||
|
||||
- name: Lint
|
||||
run: |
|
||||
set -euo pipefail
|
||||
ruff check .
|
||||
ruff format --check .
|
||||
mypy meshcore_exporter.py
|
||||
yamllint stack .gitea .yamllint
|
||||
|
||||
- name: Dashboard is generated from generate.py
|
||||
run: |
|
||||
set -euo pipefail
|
||||
python dashboards/generate.py
|
||||
git diff --exit-code dashboards/
|
||||
|
||||
- name: Tests
|
||||
run: python -m pytest -q
|
||||
@@ -0,0 +1,147 @@
|
||||
# Container image git.rfa.cz/tth-pub/meshcore-exporter, one single-platform
|
||||
# tag per architecture (latest-amd64, latest-arm64): `docker pull` from this
|
||||
# registry is unreliable on combined multi-arch manifests. Only the commit tag
|
||||
# is pushed first; latest-<arch> moves after the Trivy gate.
|
||||
#
|
||||
# A tag vX.Y.Z (must equal __version__) also gets X.Y.Z-<arch> images and a
|
||||
# release with the pull commands and the Grafana dashboard attached.
|
||||
#
|
||||
# Secret REGISTRY_TOKEN: a Gitea token with packages:write.
|
||||
name: image
|
||||
|
||||
"on":
|
||||
push:
|
||||
branches: [main]
|
||||
tags: ["v*"]
|
||||
schedule:
|
||||
- cron: "40 4 * * 1" # weekly: base image security updates
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
skip_trivy:
|
||||
description: "skip the Trivy gate (EMERGENCY, logged)"
|
||||
type: boolean
|
||||
default: false
|
||||
|
||||
env:
|
||||
IMAGE: git.rfa.cz/tth-pub/meshcore-exporter
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
arch: [amd64, arm64]
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
|
||||
- name: Trivy config
|
||||
uses: https://git.rfa.cz/tth-pub/ci-actions/trivy-gate@v11
|
||||
with:
|
||||
scan-type: fs
|
||||
scanners: misconfig
|
||||
mode: warn
|
||||
|
||||
- name: Tag matches __version__
|
||||
if: startsWith(github.ref, 'refs/tags/v')
|
||||
run: |
|
||||
set -euo pipefail
|
||||
v=$(sed -n 's/^__version__ = "\(.*\)"$/\1/p' meshcore_exporter.py)
|
||||
[ "v$v" = "${GITHUB_REF_NAME}" ] ||
|
||||
{ echo "::error::tag ${GITHUB_REF_NAME} but __version__ = $v"; exit 1; }
|
||||
|
||||
- uses: docker/setup-qemu-action@v4
|
||||
- uses: docker/setup-buildx-action@v4
|
||||
|
||||
- uses: docker/login-action@v4
|
||||
with:
|
||||
registry: git.rfa.cz
|
||||
username: ${{ gitea.actor }}
|
||||
password: ${{ secrets.REGISTRY_TOKEN }}
|
||||
|
||||
- name: Build date
|
||||
id: date
|
||||
run: echo "day=$(date -u +%F)" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Build and push the commit tag
|
||||
uses: docker/build-push-action@v7
|
||||
with:
|
||||
context: .
|
||||
push: true
|
||||
pull: true
|
||||
provenance: false
|
||||
platforms: linux/${{ matrix.arch }}
|
||||
build-args: OS_UPDATES=${{ steps.date.outputs.day }}
|
||||
tags: ${{ env.IMAGE }}:${{ github.sha }}-${{ matrix.arch }}
|
||||
cache-from: type=registry,ref=${{ env.IMAGE }}:buildcache-${{ matrix.arch }}
|
||||
cache-to: type=registry,ref=${{ env.IMAGE }}:buildcache-${{ matrix.arch }},mode=max
|
||||
|
||||
# The runner cannot execute foreign binaries (no binfmt): exec format
|
||||
# error on arm64. The code is pure Python, so amd64 covers it.
|
||||
- name: Smoke test (--help, --version)
|
||||
if: matrix.arch == 'amd64'
|
||||
run: |
|
||||
set -euo pipefail
|
||||
img="$IMAGE:${{ github.sha }}-${{ matrix.arch }}"
|
||||
docker run --rm --platform "linux/${{ matrix.arch }}" "$img" --version
|
||||
docker run --rm --platform "linux/${{ matrix.arch }}" "$img" --help | grep -q -- --repeaters
|
||||
|
||||
- name: Trivy gate
|
||||
uses: https://git.rfa.cz/tth-pub/ci-actions/trivy-gate@v11
|
||||
with:
|
||||
image: ${{ env.IMAGE }}:${{ github.sha }}-${{ matrix.arch }}
|
||||
username: ${{ gitea.actor }}
|
||||
password: ${{ secrets.REGISTRY_TOKEN }}
|
||||
platform: linux/${{ matrix.arch }}
|
||||
mode: block
|
||||
skip: ${{ inputs.skip_trivy && 'true' || 'false' }}
|
||||
|
||||
# Pull, tag, push: latest-<arch> stays a plain single-platform manifest
|
||||
# like the commit tag. `imagetools create` would wrap it in an OCI
|
||||
# index, the kind of manifest `docker pull` from this registry is
|
||||
# unreliable on.
|
||||
- name: Move latest-${{ matrix.arch }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
src="$IMAGE:${{ github.sha }}-${{ matrix.arch }}"
|
||||
docker pull -q --platform "linux/${{ matrix.arch }}" "$src"
|
||||
docker tag "$src" "$IMAGE:latest-${{ matrix.arch }}"
|
||||
docker push -q "$IMAGE:latest-${{ matrix.arch }}"
|
||||
if [[ "$GITHUB_REF" == refs/tags/v* ]]; then
|
||||
ver="${GITHUB_REF_NAME#v}-${{ matrix.arch }}"
|
||||
docker tag "$src" "$IMAGE:$ver"
|
||||
docker push -q "$IMAGE:$ver"
|
||||
fi
|
||||
|
||||
release:
|
||||
needs: build
|
||||
if: startsWith(github.ref, 'refs/tags/v')
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
- name: Release with the dashboard attached
|
||||
env:
|
||||
TOKEN: ${{ github.token }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
api="${GITHUB_SERVER_URL}/api/v1/repos/${GITHUB_REPOSITORY}"
|
||||
auth="header = \"Authorization: token $TOKEN\""
|
||||
ver="${GITHUB_REF_NAME#v}"
|
||||
body=$(cat <<EOF2
|
||||
Images (one per architecture):
|
||||
|
||||
docker pull $IMAGE:$ver-amd64
|
||||
docker pull $IMAGE:$ver-arm64
|
||||
|
||||
Docker stack: \`MC_VERSION=$ver\` in \`stack/.env\` pins this version.
|
||||
Grafana: import the attached \`meshcore-repeater.json\`.
|
||||
Setup and configuration: README.md.
|
||||
EOF2
|
||||
)
|
||||
jq -n --arg t "$GITHUB_REF_NAME" --arg n "meshcore-exporter $ver" --arg b "$body" \
|
||||
'{tag_name: $t, name: $n, body: $b}' >"$RUNNER_TEMP/rel.json"
|
||||
id=$(curl -sSf --config - -X POST -H 'Content-Type: application/json' \
|
||||
--data-binary "@$RUNNER_TEMP/rel.json" "$api/releases" <<<"$auth" | jq -r .id)
|
||||
curl -sSf --config - -X POST -F "attachment=@dashboards/meshcore-repeater.json" \
|
||||
"$api/releases/$id/assets?name=meshcore-repeater.json" <<<"$auth" >/dev/null
|
||||
echo "release $GITHUB_REF_NAME (id $id)"
|
||||
@@ -0,0 +1,61 @@
|
||||
# PR check (Renovate and any other PR): the image must build like in
|
||||
# image.yml, just without a push, and the tree's dependencies are scanned
|
||||
# (report only). Renovate automerges only after this and ci.yml are green;
|
||||
# the image after the merge is still guarded by the Trivy gate.
|
||||
name: pr-check
|
||||
|
||||
"on":
|
||||
pull_request:
|
||||
|
||||
# A newer push to the PR branch (Renovate rebases often) cancels the older run.
|
||||
concurrency:
|
||||
group: pr-check-${{ github.head_ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
- uses: docker/setup-buildx-action@v4
|
||||
|
||||
# Read-only use of image.yml's layer cache: a PR never writes it.
|
||||
- name: Registry login (cache import)
|
||||
env:
|
||||
REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }}
|
||||
run: |
|
||||
[ -z "$REGISTRY_TOKEN" ] ||
|
||||
echo "$REGISTRY_TOKEN" | docker login git.rfa.cz -u "${{ gitea.actor }}" --password-stdin
|
||||
|
||||
- name: Build date
|
||||
id: date
|
||||
run: echo "day=$(date -u +%F)" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Build (no push)
|
||||
uses: docker/build-push-action@v7
|
||||
with:
|
||||
context: .
|
||||
push: false
|
||||
load: true
|
||||
pull: true
|
||||
provenance: false
|
||||
platforms: linux/amd64
|
||||
build-args: OS_UPDATES=${{ steps.date.outputs.day }}
|
||||
tags: meshcore-exporter:pr
|
||||
cache-from: type=registry,ref=git.rfa.cz/tth-pub/meshcore-exporter:buildcache-amd64
|
||||
|
||||
- name: Smoke test (--help, --version)
|
||||
run: |
|
||||
set -euo pipefail
|
||||
docker run --rm meshcore-exporter:pr --version
|
||||
docker run --rm meshcore-exporter:pr --help | grep -q -- --repeaters
|
||||
|
||||
dependencies:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
- name: Dependencies in the tree
|
||||
uses: https://git.rfa.cz/tth-pub/ci-actions/trivy-gate@v11
|
||||
with:
|
||||
scan-type: fs
|
||||
mode: warn
|
||||
Reference in new issue
Block a user