feat: env-configurable JAVA_HOME / SPARK_HOME via entrypoint

Three problems with the prior Dockerfile:

  1. JAVA_HOME and SPARK_HOME were hardcoded at build time (ENV ...),
     so docker-compose / .env overrides had no effect.
  2. PATH was constructed at build time using those hardcoded values,
     so even if you could override the env vars, PATH would still
     reference the old literal paths (e.g. /usr/lib/jvm/java-17-openjdk-amd64/bin
     hardcoded into PATH at image build).
  3. There was no .env.example entry for either, so operators had no
     template to follow.

Fix:
  - docker-entrypoint.sh: re-derives PATH from the (possibly overridden)
    JAVA_HOME and SPARK_HOME at every container start. Strips any stale
    JDK/Spark bin dirs from PATH first so a restart with a new override
    actually changes which  /  resolve.
  - Dockerfile: COPY + ENTRYPOINT [entrypoint.sh], CMD [gunicorn main:app].
    The existing ENV JAVA_HOME and ENV SPARK_HOME stay as the defaults
    so the image works out of the box; users override via .env.
  - .env.example: new 'Java + Spark install paths' section, default
    values match the Dockerfile, comments explain the entrypoint
    re-derivation.
  - docker-compose.yml: forwards JAVA_HOME and SPARK_HOME with
    container-side defaults matching the Dockerfile.

Verified:
  - 116/116 tests still pass
  - Direct entrypoint run with JAVA_HOME=/fake/jdk shows PATH rebuilt as
    /app/.venv/bin:/fake/jdk/bin:/fake/spark/bin:... (override took effect)

Note: uses awk instead of 'paste -sd:' for portability across macOS
(BSD paste doesn't support -s) and Linux (GNU does).
This commit is contained in:
Claude
2026-06-25 11:30:30 +08:00
parent 13e39b39f3
commit 5970fadcd2
4 changed files with 68 additions and 0 deletions
+7
View File
@@ -62,6 +62,13 @@ RUN uv sync --index-url=https://pypi.tuna.tsinghua.edu.cn/simple/ --frozen --no-
ENV PATH=/app/.venv/bin:$PATH
ENV PYTHONUNBUFFERED=1
# Entrypoint re-derives PATH from JAVA_HOME and SPARK_HOME at container
# start, so overriding either via docker-compose / .env actually changes
# which `java` and `spark-submit` binaries the gunicorn process picks up.
COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
# gunicorn is the prod entrypoint — multiple ASGI workers, graceful
# shutdown, stdout/stderr logs. Config knobs are env-var driven (see
# gunicorn.conf.py).