diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..c1a2d10 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,29 @@ +**/.DS_Store +**/__pycache__ +**/.venv +**/.classpath +**/.dockerignore +**/.env +**/.envrc +**/.git +**/.gitignore +**/.project +**/.settings +**/.toolstarget +**/.vs +**/.vscode +**/*.*proj.user +**/*.dbmdl +**/*.jfm +**/bin +**/charts +**/docker-compose* +**/compose.y*ml +**/Dockerfile* +**/node_modules +**/npm-debug.log +**/obj +**/secrets.dev.yaml +**/values.dev.yaml +LICENSE +README.md \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b2aaa1a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,26 @@ +ARG PYTHON_VERSION=3.12.5 +FROM python:${PYTHON_VERSION}-slim AS base + +ENV PYTHONDONTWRITEBYTECODE=1 +ENV PYTHONUNBUFFERED=1 + +WORKDIR /app + +ARG UID=10001 +RUN adduser \ + --disabled-password \ + --gecos "" \ + --home "/nonexistent" \ + --shell "/sbin/nologin" \ + --no-create-home \ + --uid "${UID}" \ + appuser + +RUN --mount=type=cache,target=/root/.cache/pip \ + --mount=type=bind,source=requirements.txt,target=requirements.txt \ + python -m pip install -r requirements.txt + +USER appuser +COPY . . + +ENTRYPOINT python3 -m check-mate diff --git a/README.md b/README.md index adc3aaf..06f2858 100644 --- a/README.md +++ b/README.md @@ -27,12 +27,12 @@ Run check-mate: ### Arguments -| Arg | Description | -| ------------- | ------------------------------------------------------------------ | -| -h | Show help | -| --host | The IP or hostname of the meshtastic node, e.g. `192.168.5.10` | -| --location | Text description of where your node is, e.g. `SF Mission District` | -| --healthcheck | URL to send healthcheck pings to when receiving messages | +| Arg | Env | Description | +| ------------- | -------------- | ------------------------------------------------------------------ | +| -h | N/A | Show help | +| --host | HOST | The IP or hostname of the meshtastic node, e.g. `192.168.5.10` | +| --location | LOCATION | Text description of where your node is, e.g. `SF Mission District` | +| --healthcheck | HEALTHCHECKURL | URL to send healthcheck pings to when receiving messages | ## Example radio check diff --git a/check-mate.py b/check-mate.py index 41f3788..bb2645a 100644 --- a/check-mate.py +++ b/check-mate.py @@ -1,5 +1,6 @@ import argparse import logging +import os import random import re import requests @@ -135,15 +136,16 @@ def getMessage(self, snr, rssi, name): """generate a random message to respond to a radio check""" if self.location: loc = self.location + quality = f"({rssi} RSSI, {snr} SNR)" messages = [ - f"{name}, read you 5 by 5 from {loc} ({rssi} RSSI, {snr} SNR)", - f"👋 {name}, got you from {loc}", + f"{name}, read you 5 by 5 from {loc} {quality}", + f"👋 {name}, got you from {loc} {quality}", f"Copy {name}, {snr} SNR & {rssi} RSSI from {loc}", - f"Hey {name}, message received from {loc} ({rssi} RSSI, {snr} SNR)", - f"{name}, loud and clear from {loc} ({rssi} RSSI, {snr} SNR)", - f"{name}, copy your radio check from {loc}", - f"{name}, copy from {loc} ({rssi} RSSI, {snr} SNR)", - f"{name}, copy {snr} SNR from {loc}", + f"Hey {name}, message received from {loc} {quality}", + f"{name}, loud and clear from {loc} {quality}", + f"{name}, copy your radio check from {loc} {quality}", + f"{name}, copy from {loc} {quality}", + f"{name}, copy {snr} SNR & {rssi} RSSI from {loc}", ] else: messages = [ @@ -221,8 +223,9 @@ def idToHex(self, nodeId): parser.add_argument( "--host", dest="host", - required=True, + required=False, help="IP or hostname for Meshtastic device", + default=os.environ.get("HOST"), ) parser.add_argument( "-l", @@ -230,14 +233,21 @@ def idToHex(self, nodeId): dest="location", required=False, help="Location to report in radio checks", + default=os.environ.get("LOCATION"), ) parser.add_argument( "--healthcheck", dest="healthCheckURL", required=False, help="URL to report healthchecks to (empty HEAD request)", + default=os.environ.get("HEALTHCHECKURL"), ) args = parser.parse_args() + if not args.host: + parser.error( + "Please provide a host via --host or the $HOST environment variable" + ) + checkmate = CheckMate(args.host, args.location, args.healthCheckURL) sys.exit(checkmate.start()) diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 0000000..7d335d0 --- /dev/null +++ b/compose.yaml @@ -0,0 +1,5 @@ +services: + server: + build: + context: . + dockerfile: Dockerfile