#!/bin/sh # docker-entrypoint.sh # # Re-derives PATH from JAVA_HOME and SPARK_HOME at container start, so that # overriding either via docker-compose / .env actually changes which # `java` and `spark-submit` binaries the gunicorn process picks up. # # Without this, the image's built-in PATH (set at build time from the # Dockerfile's ENV) would still reference the old literal paths even # after the env vars are overridden at runtime. # # Usage in Dockerfile: # ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"] # CMD ["gunicorn", "main:app"] set -e # Defaults if not set (matches Dockerfile's build-time defaults) : "${JAVA_HOME:=/usr/lib/jvm/java-17-openjdk-amd64}" : "${SPARK_HOME:=/opt/spark}" # Project venv always takes precedence VENV_BIN="/app/.venv/bin" # Strip any stale JAVA_HOME / SPARK_HOME bin dirs from PATH, then prepend # the current ones so overrides actually take effect on a container restart. # Uses awk instead of `paste -sd:` for portability (macOS paste is BSD and # doesn't support -s). PATH_CLEAN=$(echo "$PATH" | tr ':' '\n' | grep -v "/usr/lib/jvm/" | grep -v "/opt/spark/bin" | awk '{ printf "%s%s", $0, (NR==1?":":"") }' | sed 's/:$//') export PATH="${VENV_BIN}:${JAVA_HOME}/bin:${SPARK_HOME}/bin:${PATH_CLEAN}" export JAVA_HOME export SPARK_HOME echo "[entrypoint] JAVA_HOME=${JAVA_HOME}" >&2 echo "[entrypoint] SPARK_HOME=${SPARK_HOME}" >&2 echo "[entrypoint] PATH=${PATH}" >&2 # Run whatever CMD was passed (gunicorn main:app, or `python main.py`, etc.) exec "$@"