# pymodbus simulator container for the Modbus integration suite.
#
# Pinned base + package version so the fixture surface is reproducible —
# matches the version referenced in docs/drivers/Modbus-Test-Fixture.md.
FROM python:3.12-slim-bookworm

LABEL org.opencontainers.image.source="https://github.com/dohertj2/lmxopcua" \
      org.opencontainers.image.description="pymodbus simulator for OtOpcUa Modbus driver integration tests"

RUN pip install --no-cache-dir "pymodbus[simulator]==3.13.0"

# Ship every profile in the image so one container can serve whichever
# family a test run needs; the compose file picks which JSON is active via
# the command override.
WORKDIR /fixtures
COPY profiles/ /fixtures/

# Standalone exception-injection server (pure Python stdlib — no pymodbus
# dependency). Speaks raw Modbus/TCP and emits arbitrary exception codes
# per rules in exception_injection.json. Drives the `exception_injection`
# compose profile. See Docker/README.md §exception injection.
COPY exception_injector.py /fixtures/

# #909: launcher that runs the simulator with asyncio debug mode OFF (pymodbus 3.13
# hard-codes debug=True, which made it >10x slower and let it be swamped by one test run),
# plus the FC03 liveness probe it uses as an in-container watchdog and compose uses as
# the healthcheck. See run_simulator.py.
COPY run_simulator.py fc3_probe.py /fixtures/

# 5020 = the shared port for the standard/dl205/mitsubishi/s7_1500/exception_injection
# profiles (only one binds it at a time); 5021 = the rtu_over_tcp profile, which co-runs
# with standard. Image-metadata honesty only — compose's ports: mapping doesn't need EXPOSE.
EXPOSE 5020 5021

# Default to the standard profile; docker-compose.yml overrides per service.
# Never launch the stock `pymodbus.simulator` console script: it runs asyncio in debug mode (#909).
# --http_port intentionally omitted; pymodbus 3.13's web UI binds on a
# container-local default we don't publish, so it's not reachable from the
# host and costs nothing.
CMD ["python", "/fixtures/run_simulator.py", \
     "--modbus_server", "srv", \
     "--modbus_device",  "dev", \
     "--json_file",      "/fixtures/standard.json"]
