File size: 3,241 Bytes
a261a58
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2cfbcd2
a261a58
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7efdd11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2cfbcd2
 
a261a58
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7efdd11
 
 
 
 
 
2cfbcd2
7efdd11
a261a58
2cfbcd2
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
83
84
85
86
#!/usr/bin/env bash
set -euo pipefail

log() { echo "[start] $*"; }

APP_PORT="${APP_PORT:-7860}"
BOOTSTRAP_DIR="/app/bootstrap"

# OpenCode web basic-auth uses OPENCODE_SERVER_PASSWORD
if [[ -n "${OPENCODE_PASSWORD:-}" ]]; then
  export OPENCODE_SERVER_PASSWORD="${OPENCODE_PASSWORD}"
fi

# Persist ONLY settings/skills here (no sessions)
PERSIST_ROOT="/data/opencode-persist"
if [[ ! -d "/data" || ! -w "/data" ]]; then
  log "WARNING: /data not writable (bucket not mounted or permission issue). Falling back to ephemeral storage."
  PERSIST_ROOT="/root/persist-ephemeral"
fi

CONFIG_FILE="${PERSIST_ROOT}/opencode.jsonc"
CONFIG_DIR="${PERSIST_ROOT}/opencode.d"

# Tell OpenCode where to load config + skills/plugins/etc from
export OPENCODE_CONFIG="${CONFIG_FILE}"
export OPENCODE_CONFIG_DIR="${CONFIG_DIR}"

log "== diagnostics =="
id || true
ls -ld /data || true
df -h /data || true

mkdir -p "${PERSIST_ROOT}" "${CONFIG_DIR}"

# ---- Workspace: create your daily folders on the persistent disk (/data) ----
WORKSPACE_ROOT="/data/workspace"
if [[ ! -d "/data" || ! -w "/data" ]]; then
  WORKSPACE_ROOT="/root/workspace-ephemeral"
fi
mkdir -p "${WORKSPACE_ROOT}/chat" "${WORKSPACE_ROOT}/test" "${WORKSPACE_ROOT}/project"

# --- KEY FIX FOR WEB UI ISSUE #12487: Also create directories at root level ----
# Some web UI implementations (especially in containerized environments) 
# expect to see folders at predictable root-level paths rather than through symlinks
# or nested paths. Creating these at root level improves web UI compatibility.
mkdir -p /chat /project /other
log "Created root-level directories for web UI compatibility: /chat, /project, /other"

# --- ALSO: Ensure symlink is handled robustly ----
rm -f /workspace
ln -sfn "${WORKSPACE_ROOT}" /workspace
log "Created workspace symlink: /workspace -> ${WORKSPACE_ROOT}"

# --- ADDITIONAL ROOT-LEVEL SYMLINKS FOR WEB UI COMPATIBILITY ----
# Create direct symlinks to common directories that web UI might expect
ln -sfn "${WORKSPACE_ROOT}/chat" /chat || true
ln -sfn "${WORKSPACE_ROOT}/project" /project || true
ln -sfn "${WORKSPACE_ROOT}/other" /other || true
log "Created direct symlinks for web UI compatibility"

# Seed/overwrite persisted config from repo bootstrap (simple + reproducible)
log "Sync bootstrap => ${PERSIST_ROOT}"
cp -f "${BOOTSTRAP_DIR}/opencode.jsonc" "${CONFIG_FILE}"
rm -rf "${CONFIG_DIR}"
mkdir -p "${CONFIG_DIR}"
cp -r "${BOOTSTRAP_DIR}/opencode.d/"* "${CONFIG_DIR}/" || true

# Prove persistence: append a timestamp
date -u +"%Y-%m-%dT%H:%M:%SZ started" >> "${PERSIST_ROOT}/startup.log"

log "opencode path: $(command -v opencode || true)"
opencode --version || true

log "Workspace root: ${WORKSPACE_ROOT}"
log "Starting OpenCode Web on 0.0.0.0:${APP_PORT}"

# --- IMPROVED STARTUP SEQUENCE FOR WEB UI RELIABILITY ----
# Add a small delay to ensure all filesystem operations are complete
# before the web UI starts initializing and attempting to read directory structures
sleep 2
log "Filesystem synchronization complete, starting web UI..."

# IMPORTANT: do NOT use "--cwd" (this opencode doesn't support it)
# Start from the workspace root as originally intended
cd "${WORKSPACE_ROOT}"
exec opencode web --hostname 0.0.0.0 --port "${APP_PORT}"