-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-entrypoint.sh
More file actions
82 lines (71 loc) · 3.17 KB
/
docker-entrypoint.sh
File metadata and controls
82 lines (71 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/bash
# Don't use set -e here, as we want to continue even if CUDA setup fails
# (CUDA might not be installed yet)
# Check and warn about /app/data permissions
# Volume mounts may have incorrect ownership/permissions
if [ -d "/app/data" ]; then
# Check if we can write to the data directory
if [ ! -w "/app/data" ]; then
echo "WARNING: /app/data directory is not writable by current user ($(id -u))"
echo "This will cause configuration and model write errors."
echo "To fix, run on the host: sudo chown -R $(id -u):$(id -g) <volume-path>"
fi
fi
# Source the CUDA environment setup script if it exists
# This allows the same logic to be used at startup and runtime
if [ -f "/app/setup-cuda-env.sh" ]; then
source /app/setup-cuda-env.sh
if [ -n "$CUDA_HOME" ]; then
echo "CUDA environment configured:"
echo " CUDA_HOME=$CUDA_HOME"
echo " CUDA_VERSION=$(basename "$CUDA_HOME" | sed 's/cuda-//')"
echo " PATH includes: ${CUDA_HOME}/bin"
echo " LD_LIBRARY_PATH includes: ${CUDA_HOME}/lib64"
fi
else
# Fallback: use inline function if helper script not available
setup_cuda_env() {
local data_root="/app/data"
local cuda_install_dir="${data_root}/cuda"
if [ ! -d "$cuda_install_dir" ]; then
return 0
fi
# First, check for the current symlink (preferred method)
local latest_cuda_path=""
local current_symlink="${cuda_install_dir}/current"
if [ -e "$current_symlink" ]; then
# Resolve the symlink to get the actual path
local resolved_path=$(readlink -f "$current_symlink" 2>/dev/null || realpath "$current_symlink" 2>/dev/null)
if [ -n "$resolved_path" ] && [ -d "$resolved_path" ] && [ -f "${resolved_path}/bin/nvcc" ]; then
latest_cuda_path="$resolved_path"
fi
fi
# Fallback: Find the latest CUDA installation by scanning directories
if [ -z "$latest_cuda_path" ]; then
while IFS= read -r cuda_dir; do
if [ -d "$cuda_dir" ] && [ -f "${cuda_dir}/bin/nvcc" ]; then
latest_cuda_path="$cuda_dir"
break
fi
done < <(find "$cuda_install_dir" -maxdepth 1 -type d -name "cuda-*" ! -name current 2>/dev/null | sort -V -r)
fi
if [ -z "$latest_cuda_path" ]; then
return 0
fi
export CUDA_HOME="$latest_cuda_path"
export CUDA_PATH="$latest_cuda_path"
if [ -d "${latest_cuda_path}/bin" ]; then
if [[ ":$PATH:" != *":${latest_cuda_path}/bin:"* ]]; then
export PATH="${latest_cuda_path}/bin:$PATH"
fi
fi
if [ -d "${latest_cuda_path}/lib64" ]; then
if [[ ":$LD_LIBRARY_PATH:" != *":${latest_cuda_path}/lib64:"* ]]; then
export LD_LIBRARY_PATH="${latest_cuda_path}/lib64${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
fi
fi
}
setup_cuda_env
fi
# Execute the main command
exec "$@"