#!/bin/sh # docker-entrypoint.sh # # Spark 3.1.2 + JDK 11 container entrypoint. # # Three responsibilities, in order: # 1. Resolve JAVA_HOME and SPARK_HOME from env (with sensible defaults # matching the Dockerfile). # 2. Validate the resolved paths exist and contain the expected # binaries. Fail fast at container start with a clear error # message, instead of letting a job submission die later with an # opaque "no such file" or "command not found". # 3. Update PATH so the (possibly overridden) JAVA_HOME/bin and # SPARK_HOME/bin are prepended — overrides via docker-compose / .env # take effect on the very next container start, without rebuilding # the image. # # Compared to the previous version this drops the awk-based PATH # stripping (too brittle — would also strip the new JAVA_HOME/bin if # it happened to be under /usr/lib/jvm/) and instead just prepends. # Whatever was in the old PATH is preserved; the new paths win # because they come first. set -e # Defaults match the Dockerfile's build-time ENV : "${JAVA_HOME:=/usr/lib/jvm/java-11-openjdk-amd64}" : "${SPARK_HOME:=/opt/spark}" # --- Validation (fail fast with a clear error) --- if [ ! -x "${JAVA_HOME}/bin/java" ]; then echo "[entrypoint] FATAL: JAVA_HOME=${JAVA_HOME} but ${JAVA_HOME}/bin/java is missing or not executable" >&2 echo "[entrypoint] Hint: set JAVA_HOME to a directory containing bin/java (e.g. /usr/lib/jvm/java-11-openjdk-amd64)" >&2 exit 1 fi if [ ! -x "${SPARK_HOME}/bin/spark-submit" ]; then echo "[entrypoint] FATAL: SPARK_HOME=${SPARK_HOME} but ${SPARK_HOME}/bin/spark-submit is missing or not executable" >&2 echo "[entrypoint] Hint: set SPARK_HOME to the Spark install root (e.g. /opt/spark)" >&2 exit 1 fi # Export the resolved values (so subprocesses see them) export JAVA_HOME export SPARK_HOME # --- Update PATH --- # Prepend the project venv and the (possibly overridden) JDK + Spark # bin dirs. Order matters: /app/.venv/bin first (project tools win), # then JAVA_HOME/bin (overrides any system java), then SPARK_HOME/bin, # then whatever was already on PATH. export PATH="/app/.venv/bin:${JAVA_HOME}/bin:${SPARK_HOME}/bin:${PATH}" # --- Log the effective resolution so docker logs show what was picked --- echo "[entrypoint] JAVA_HOME=${JAVA_HOME}" >&2 echo "[entrypoint] SPARK_HOME=${SPARK_HOME}" >&2 echo "[entrypoint] java: $(command -v java)" >&2 echo "[entrypoint] spark-submit: $(command -v spark-submit)" >&2 echo "[entrypoint] java version: $(java -version 2>&1 | head -1)" >&2 # Run whatever CMD was passed (gunicorn main:app, or python main.py, etc.) exec "$@"