From d24bcb1f43cebab31cec42b45d45bbde84a39bd2 Mon Sep 17 00:00:00 2001 From: Michael Gillett <51103663+migillett@users.noreply.github.com> Date: Sun, 1 Mar 2026 10:46:42 -0500 Subject: [PATCH 1/3] starting work on a docker build --- README.md | 4 ++++ docker-compose.yml | 16 ++++++++++++++ dockerfile | 52 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 docker-compose.yml create mode 100644 dockerfile diff --git a/README.md b/README.md index af59ad9..d4066da 100644 --- a/README.md +++ b/README.md @@ -249,7 +249,11 @@ Pre-commit hooks will automatically: - Lint with flake8 - Fix trailing whitespace and other file issues +## Docker +```bash +docker build -t pymc:latest . --platform linux/arm/v7 +``` ## Support diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..b2d0009 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,16 @@ +services: + pymc-repeater: + build: . + container_name: pymc-repeater + restart: unless-stopped + devices: + - /dev/spidev0.0 + - /dev/spidev0.1 + volumes: + - ./config.yaml:/etc/pymc_repeater/config.yaml:ro + - pymc_data:/var/lib/pymc_repeater + ports: + - "8000:8000" + +volumes: + pymc_data: diff --git a/dockerfile b/dockerfile new file mode 100644 index 0000000..807f7b0 --- /dev/null +++ b/dockerfile @@ -0,0 +1,52 @@ +# --------------------------- +# Builder stage +# --------------------------- +FROM python:3.11-alpine AS builder + +WORKDIR /build + +# Build dependencies +RUN apk add --no-cache \ + build-base \ + linux-headers \ + python3-dev + +COPY pyproject.toml . +COPY repeater ./repeater + +# Build wheels (including spidev) +RUN pip wheel --no-cache-dir --wheel-dir /wheels . + +# --------------------------- +# Runtime stage +# --------------------------- +FROM python:3.11-alpine + +ENV PYTHONUNBUFFERED=1 \ + CONFIG_PATH=/etc/pymc_repeater/config.yaml + +ARG UID=10001 +ARG GID=10001 + +# Create non-root user +RUN addgroup -g ${GID} repeater && \ + adduser -D -u ${UID} -G repeater repeater + +WORKDIR /opt/pymc_repeater + +# Copy wheels from builder +COPY --from=builder /wheels /wheels + +# Install from wheels only +RUN pip install --no-cache-dir /wheels/* && \ + rm -rf /wheels + +# Config directory +RUN mkdir -p /etc/pymc_repeater && \ + chown -R ${UID}:${GID} /etc/pymc_repeater + +USER ${UID}:${GID} + +EXPOSE 8000 + +ENTRYPOINT ["/bin/sh", "-c", "test -f ${CONFIG_PATH} || (echo 'Missing config.yaml' && exit 1); exec python3 -m repeater --config ${CONFIG_PATH}"] From 908b1c39db7c99be7aedbf38f838fc61f2a838b5 Mon Sep 17 00:00:00 2001 From: Michael Gillett <51103663+migillett@users.noreply.github.com> Date: Sun, 1 Mar 2026 16:18:50 -0500 Subject: [PATCH 2/3] instructions for config.yaml rework of docker its ALIVE disable :ro tag for config.yaml leave empty line lets open ports instead of network mode host run as current user run as user nevermind update readme with instructions relocate docker section --- README.md | 17 +++++++---- docker-compose.yml | 15 +++++----- dockerfile | 71 ++++++++++++++++++---------------------------- 3 files changed, 45 insertions(+), 58 deletions(-) diff --git a/README.md b/README.md index d4066da..b343763 100644 --- a/README.md +++ b/README.md @@ -202,6 +202,17 @@ This script will: The script will prompt you for each optional removal step. +## Docker + +You can now run PyMC Repeater from within a [Docker Container](https://www.docker.com/). Checkout the example [Docker Compose](./docker-compose.yml) file for an example. + +```bash +docker compose up -d --force-recreate --build +``` + +Just note that you will have to pass in a `config.yaml` into the container. You can create a new config by following the instructions in the [Configuration section](#configuration). + + ## Roadmap / Planned Features - [ ] **Public Map Integration** - Submit repeater location and details to public map for discovery @@ -249,12 +260,6 @@ Pre-commit hooks will automatically: - Lint with flake8 - Fix trailing whitespace and other file issues -## Docker - -```bash -docker build -t pymc:latest . --platform linux/arm/v7 -``` - ## Support - [Core Lib Documentation](https://rightup.github.io/pyMC_core/) diff --git a/docker-compose.yml b/docker-compose.yml index b2d0009..f65a1de 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,14 +3,13 @@ services: build: . container_name: pymc-repeater restart: unless-stopped + ports: + - 8000:8000 devices: - /dev/spidev0.0 - - /dev/spidev0.1 + - /dev/gpiochip0 + cap_add: + - SYS_RAWIO volumes: - - ./config.yaml:/etc/pymc_repeater/config.yaml:ro - - pymc_data:/var/lib/pymc_repeater - ports: - - "8000:8000" - -volumes: - pymc_data: + - ./config.yaml:/etc/pymc_repeater/config.yaml + - ./data:/var/lib/pymc_repeater diff --git a/dockerfile b/dockerfile index 807f7b0..8d3689f 100644 --- a/dockerfile +++ b/dockerfile @@ -1,52 +1,35 @@ -# --------------------------- -# Builder stage -# --------------------------- -FROM python:3.11-alpine AS builder +FROM python:3.12-slim-bookworm -WORKDIR /build +ENV INSTALL_DIR=/opt/pymc_repeater \ + CONFIG_DIR=/etc/pymc_repeater \ + DATA_DIR=/var/lib/pymc_repeater \ + PYTHONUNBUFFERED=1 \ + SETUPTOOLS_SCM_PRETEND_VERSION_FOR_PYMC_REPEATER=1.0.5 -# Build dependencies -RUN apk add --no-cache \ - build-base \ - linux-headers \ - python3-dev +# Install runtime dependencies only +RUN apt-get update && apt-get install -y \ + libffi-dev \ + python3-rrdtool \ + jq \ + wget \ + swig \ + git \ + build-essential \ + python3-dev \ + && rm -rf /var/lib/apt/lists/* -COPY pyproject.toml . +# Create runtime directories +RUN mkdir -p ${INSTALL_DIR} ${CONFIG_DIR} ${DATA_DIR} + +WORKDIR ${INSTALL_DIR} + +# Copy source COPY repeater ./repeater +COPY pyproject.toml . -# Build wheels (including spidev) -RUN pip wheel --no-cache-dir --wheel-dir /wheels . - -# --------------------------- -# Runtime stage -# --------------------------- -FROM python:3.11-alpine - -ENV PYTHONUNBUFFERED=1 \ - CONFIG_PATH=/etc/pymc_repeater/config.yaml - -ARG UID=10001 -ARG GID=10001 - -# Create non-root user -RUN addgroup -g ${GID} repeater && \ - adduser -D -u ${UID} -G repeater repeater - -WORKDIR /opt/pymc_repeater - -# Copy wheels from builder -COPY --from=builder /wheels /wheels - -# Install from wheels only -RUN pip install --no-cache-dir /wheels/* && \ - rm -rf /wheels - -# Config directory -RUN mkdir -p /etc/pymc_repeater && \ - chown -R ${UID}:${GID} /etc/pymc_repeater - -USER ${UID}:${GID} +# Install package +RUN pip install --no-cache-dir . EXPOSE 8000 -ENTRYPOINT ["/bin/sh", "-c", "test -f ${CONFIG_PATH} || (echo 'Missing config.yaml' && exit 1); exec python3 -m repeater --config ${CONFIG_PATH}"] +ENTRYPOINT ["python3", "-m", "repeater.main", "--config", "/etc/pymc_repeater/config.yaml"] From 9ac6630128551d1bdc91b5fd91785cfe0340d321 Mon Sep 17 00:00:00 2001 From: Michael Gillett <51103663+migillett@users.noreply.github.com> Date: Mon, 2 Mar 2026 11:47:22 -0500 Subject: [PATCH 3/3] Clarify Docker usage instructions in README Updated wording for clarity in Docker section. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b343763..4c65cd9 100644 --- a/README.md +++ b/README.md @@ -204,7 +204,7 @@ The script will prompt you for each optional removal step. ## Docker -You can now run PyMC Repeater from within a [Docker Container](https://www.docker.com/). Checkout the example [Docker Compose](./docker-compose.yml) file for an example. +You can now run PyMC Repeater from within a [Docker Container](https://www.docker.com/). Checkout the example [Docker Compose](./docker-compose.yml) file before you get started. ```bash docker compose up -d --force-recreate --build