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}"]