diff --git a/.taskfiles/engine.yml b/.taskfiles/engine.yml index 244b48353..6393fa64d 100644 --- a/.taskfiles/engine.yml +++ b/.taskfiles/engine.yml @@ -37,9 +37,23 @@ tasks: dir: src vars: # When PORT is provided (e.g. from dev:all), use it directly. - # When running standalone, probe for a free port starting at 5001. + # With ENGINE_PORT_PROBE=false (Docker), use the fixed STIRLING_ENGINE_PORT + # (default 5001) without probing. Otherwise probe for a free port from 5001. PORT: - sh: '{{if .PORT}}echo {{.PORT}}{{else if eq OS "windows"}}{{.ENGINE_FIND_FREE_PORT_PS}} 5001{{else}}{{.ENGINE_FIND_FREE_PORT_SH}} 5001{{end}}' + sh: | + if [ -n "{{.PORT}}" ]; then + echo "{{.PORT}}" + elif [ -f /.dockerenv ] || [ "${ENGINE_PORT_PROBE:-true}" = "false" ]; then + # Never probe in a container: the port is fixed and the probe script + # isn't shipped in the image. /.dockerenv auto-detects Docker; the + # ENGINE_PORT_PROBE=false flag forces fixed-port mode anywhere else. + # The probe is a dev-only convenience for avoiding local port clashes. + echo "${STIRLING_ENGINE_PORT:-5001}" + elif [ "{{OS}}" = "windows" ]; then + {{.ENGINE_FIND_FREE_PORT_PS}} 5001 + else + {{.ENGINE_FIND_FREE_PORT_SH}} 5001 + fi env: PYTHONUNBUFFERED: "1" cmds: @@ -52,9 +66,23 @@ tasks: dir: src vars: # When PORT is provided (e.g. from dev:all), use it directly. - # When running standalone, probe for a free port starting at 5001. + # With ENGINE_PORT_PROBE=false (Docker), use the fixed STIRLING_ENGINE_PORT + # (default 5001) without probing. Otherwise probe for a free port from 5001. PORT: - sh: '{{if .PORT}}echo {{.PORT}}{{else if eq OS "windows"}}{{.ENGINE_FIND_FREE_PORT_PS}} 5001{{else}}{{.ENGINE_FIND_FREE_PORT_SH}} 5001{{end}}' + sh: | + if [ -n "{{.PORT}}" ]; then + echo "{{.PORT}}" + elif [ -f /.dockerenv ] || [ "${ENGINE_PORT_PROBE:-true}" = "false" ]; then + # Never probe in a container: the port is fixed and the probe script + # isn't shipped in the image. /.dockerenv auto-detects Docker; the + # ENGINE_PORT_PROBE=false flag forces fixed-port mode anywhere else. + # The probe is a dev-only convenience for avoiding local port clashes. + echo "${STIRLING_ENGINE_PORT:-5001}" + elif [ "{{OS}}" = "windows" ]; then + {{.ENGINE_FIND_FREE_PORT_PS}} 5001 + else + {{.ENGINE_FIND_FREE_PORT_SH}} 5001 + fi env: PYTHONUNBUFFERED: "1" cmds: diff --git a/engine/Dockerfile b/engine/Dockerfile index e3f548e8d..375983142 100644 --- a/engine/Dockerfile +++ b/engine/Dockerfile @@ -27,6 +27,10 @@ COPY .taskfiles/ ./.taskfiles/ ENV PATH="/app/engine/.venv/bin:$PATH" ENV PYTHONUNBUFFERED=1 ENV STIRLING_ENGINE_WORKERS=4 +# Container runs on a fixed port; skip the host-only free-port probe (its script +# is not shipped in the image). engine:run honours these. +ENV ENGINE_PORT_PROBE=false +ENV STIRLING_ENGINE_PORT=5001 EXPOSE 5001