Build and Push Docker Image / build (push) Canceled after 0s
- Split Dockerfile into builder and runtime stages - Put .venv on PATH so pymodbus resolves in the container - Push image to Docker Hub and GHCR with latest and 7-char SHA tags - Use real repo/image names in README
27 lines
536 B
Docker
27 lines
536 B
Docker
# Stage 1: build and install dependencies
|
|
FROM python:3.11-slim AS builder
|
|
|
|
WORKDIR /app
|
|
|
|
COPY pyproject.toml uv.lock ./
|
|
RUN pip install --no-cache-dir uv && uv sync --frozen --no-dev --no-install-project
|
|
|
|
# Stage 2: runtime (slim, no build toolchain)
|
|
FROM python:3.11-slim AS runtime
|
|
|
|
WORKDIR /app
|
|
|
|
COPY --from=builder /app/.venv ./.venv
|
|
ENV PATH="/app/.venv/bin:$PATH"
|
|
|
|
# Copy application
|
|
COPY main.py ./
|
|
|
|
# Create non-root user
|
|
RUN useradd -m modbus && chown -R modbus:modbus /app
|
|
USER modbus
|
|
|
|
EXPOSE 5020
|
|
|
|
CMD ["python", "main.py"]
|