Files
meshcore-hub/docker/Dockerfile
Claude caa67059a3 Add Docker setup with Compose profiles for Phase 6
- Add multi-stage Dockerfile with python:3.11-slim base
- Add docker-compose.yml with profile support for selective service deployment:
  - mqtt: Eclipse Mosquitto MQTT broker
  - interface-receiver: MeshCore device receiver mode
  - interface-sender: MeshCore device sender mode
  - collector: MQTT subscriber and database storage
  - api: REST API server
  - web: Web dashboard
  - mock: Testing profile with mock devices
  - migrate: Database migration service
- Add mosquitto.conf with listener and persistence configuration
- Add .dockerignore for faster builds
- Add .env.example for Docker environment configuration
- Add sample members.json for web dashboard
2025-12-03 15:26:05 +00:00

95 lines
2.8 KiB
Docker

# MeshCore Hub - Multi-stage Dockerfile
# Build and run MeshCore Hub components
# =============================================================================
# Stage 1: Builder - Install dependencies and build package
# =============================================================================
FROM python:3.11-slim AS builder
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1
# Install build dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
&& rm -rf /var/lib/apt/lists/*
# Create and use virtual environment
RUN python -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
# Copy project files
WORKDIR /app
COPY pyproject.toml README.md ./
COPY src/ ./src/
COPY alembic/ ./alembic/
COPY alembic.ini ./
# Install the package
RUN pip install --upgrade pip && \
pip install .
# =============================================================================
# Stage 2: Runtime - Final production image
# =============================================================================
FROM python:3.11-slim AS runtime
# Labels
LABEL org.opencontainers.image.title="MeshCore Hub" \
org.opencontainers.image.description="Python monorepo for managing MeshCore mesh networks" \
org.opencontainers.image.source="https://github.com/meshcore-dev/meshcore-hub"
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
# Default configuration
LOG_LEVEL=INFO \
MQTT_HOST=mqtt \
MQTT_PORT=1883 \
MQTT_PREFIX=meshcore \
DATABASE_URL=sqlite:////data/meshcore.db \
API_HOST=0.0.0.0 \
API_PORT=8000 \
WEB_HOST=0.0.0.0 \
WEB_PORT=8080 \
API_BASE_URL=http://api:8000
# Install runtime dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
# For serial port access
udev \
&& rm -rf /var/lib/apt/lists/* \
&& mkdir -p /data
# Copy virtual environment from builder
COPY --from=builder /opt/venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
# Copy alembic configuration for migrations
WORKDIR /app
COPY --from=builder /app/alembic.ini ./
COPY --from=builder /app/alembic/ ./alembic/
# Create non-root user
RUN useradd --create-home --shell /bin/bash meshcore && \
chown -R meshcore:meshcore /data /app
# Default to non-root user (can be overridden for device access)
USER meshcore
# Expose common ports
EXPOSE 8000 8080
# Health check - uses the API health endpoint by default
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/health')" || exit 1
# Set entrypoint to the CLI
ENTRYPOINT ["meshcore-hub"]
# Default command shows help
CMD ["--help"]