MacBook pro commited on
Commit
320ec50
·
1 Parent(s): 6f09ee6

fix: handle permission denial on /app/models symlink setup fallback

Browse files
Files changed (1) hide show
  1. entrypoint.sh +29 -10
entrypoint.sh CHANGED
@@ -19,9 +19,7 @@ fi
19
  if [[ $PERSIST_DEFAULT -eq 1 ]]; then
20
  PERSIST_ROOT="/data/mirage_models"
21
  mkdir -p "$PERSIST_ROOT" || true
22
- # If /app/models exists and is not a symlink, migrate its contents (first run)
23
  if [[ -d /app/models && ! -L /app/models ]]; then
24
- # Only migrate if persistent dir is empty (avoid overwriting existing cache)
25
  if [[ -z "$(ls -A "$PERSIST_ROOT" 2>/dev/null)" ]]; then
26
  echo "[entrypoint] Migrating existing /app/models/* -> $PERSIST_ROOT (first persistent run)"
27
  shopt -s dotglob nullglob
@@ -30,19 +28,40 @@ if [[ $PERSIST_DEFAULT -eq 1 ]]; then
30
  done
31
  shopt -u dotglob nullglob
32
  fi
33
- rm -rf /app/models
34
- ln -s "$PERSIST_ROOT" /app/models
35
- echo "[entrypoint] Symlinked /app/models -> $PERSIST_ROOT"
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  elif [[ -L /app/models ]]; then
37
  echo "[entrypoint] /app/models already symlinked"
 
 
38
  else
39
- # Create then symlink if missing
40
  rm -rf /app/models 2>/dev/null || true
41
- ln -s "$PERSIST_ROOT" /app/models
42
- echo "[entrypoint] Initialized persistent symlink /app/models -> $PERSIST_ROOT"
 
 
 
 
 
 
 
 
43
  fi
44
- STORAGE_MODE="persistent"
45
- STORAGE_PATH="$PERSIST_ROOT"
46
  else
47
  mkdir -p /app/models || true
48
  STORAGE_MODE="ephemeral"
 
19
  if [[ $PERSIST_DEFAULT -eq 1 ]]; then
20
  PERSIST_ROOT="/data/mirage_models"
21
  mkdir -p "$PERSIST_ROOT" || true
 
22
  if [[ -d /app/models && ! -L /app/models ]]; then
 
23
  if [[ -z "$(ls -A "$PERSIST_ROOT" 2>/dev/null)" ]]; then
24
  echo "[entrypoint] Migrating existing /app/models/* -> $PERSIST_ROOT (first persistent run)"
25
  shopt -s dotglob nullglob
 
28
  done
29
  shopt -u dotglob nullglob
30
  fi
31
+ if rm -rf /app/models 2>/dev/null; then
32
+ if ln -s "$PERSIST_ROOT" /app/models 2>/dev/null; then
33
+ echo "[entrypoint] Symlinked /app/models -> $PERSIST_ROOT"
34
+ STORAGE_MODE="persistent"
35
+ STORAGE_PATH="$PERSIST_ROOT"
36
+ else
37
+ echo "[entrypoint] WARNING: symlink creation failed (permission?). Falling back to ephemeral mode." >&2
38
+ mkdir -p /app/models || true
39
+ STORAGE_MODE="ephemeral"
40
+ STORAGE_PATH="/app/models"
41
+ fi
42
+ else
43
+ echo "[entrypoint] WARNING: cannot remove /app/models (permission denied). Using existing directory as ephemeral." >&2
44
+ STORAGE_MODE="ephemeral"
45
+ STORAGE_PATH="/app/models"
46
+ fi
47
  elif [[ -L /app/models ]]; then
48
  echo "[entrypoint] /app/models already symlinked"
49
+ STORAGE_MODE="persistent"
50
+ STORAGE_PATH="$PERSIST_ROOT"
51
  else
52
+ # Attempt to create symlink fresh
53
  rm -rf /app/models 2>/dev/null || true
54
+ if ln -s "$PERSIST_ROOT" /app/models 2>/dev/null; then
55
+ echo "[entrypoint] Initialized persistent symlink /app/models -> $PERSIST_ROOT"
56
+ STORAGE_MODE="persistent"
57
+ STORAGE_PATH="$PERSIST_ROOT"
58
+ else
59
+ echo "[entrypoint] WARNING: cannot create symlink; falling back to ephemeral /app/models" >&2
60
+ mkdir -p /app/models || true
61
+ STORAGE_MODE="ephemeral"
62
+ STORAGE_PATH="/app/models"
63
+ fi
64
  fi
 
 
65
  else
66
  mkdir -p /app/models || true
67
  STORAGE_MODE="ephemeral"