Files
mcp-server/docker-entrypoint.sh
T
Claude 0cb7605afa fix(deploy): align JAVA_HOME default to JDK 17 (match Dockerfile)
The Dockerfile installs openjdk-17-jre-headless and sets
JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64, but the entrypoint
default was still /usr/lib/jvm/java-11-openjdk-amd64. The
validation caught the mismatch at container start:

  [entrypoint] FATAL: JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
  but /usr/lib/jvm/java-11-openjdk-amd64/bin/java is missing or
  not executable

That's exactly the failure mode the validation is designed to catch
- the deployment config got out of sync. Aligning all four files
(Dockerfile, entrypoint, .env.example, docker-compose.yml) to
java-17-openjdk-amd64.

No app code touched. 165/165 still pass.
2026-06-25 17:27:27 +08:00

63 lines
2.6 KiB
Bash
Executable File

#!/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
# (openjdk-17-jre-headless + Spark 3.5.8)
: "${JAVA_HOME:=/usr/lib/jvm/java-17-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 "$@"