-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdocker-entrypoint.sh
More file actions
106 lines (91 loc) · 4.43 KB
/
docker-entrypoint.sh
File metadata and controls
106 lines (91 loc) · 4.43 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env bash
set -e
# ==============================================================================
# HotPlex Docker Entrypoint
# Handles permission fixes, config seeding, Git identity, and privilege drop
# ==============================================================================
HOTPLEX_HOME="/home/hotplex"
CONFIG_DIR="$HOTPLEX_HOME/.hotplex"
# ------------------------------------------------------------------------------
# Helper: Run commands as the hotplex user if currently root
# ------------------------------------------------------------------------------
run_as_hotplex() {
if [ "$(id -u)" = "0" ]; then
runuser -u hotplex -m -- "$@"
else
"$@"
fi
}
# ------------------------------------------------------------------------------
# 1. Fix Permissions & Create Directories (if running as root)
# Solves EACCES issues with host-mounted volumes and ensures paths exist
# ------------------------------------------------------------------------------
if [ "$(id -u)" = "0" ]; then
echo "--> Ensuring directories exist and fixing permissions..."
mkdir -p "$CONFIG_DIR" "$HOTPLEX_HOME/.claude" "$HOTPLEX_HOME/projects"
chown -R hotplex:hotplex "$CONFIG_DIR" 2>/dev/null || true
chown -R hotplex:hotplex "$HOTPLEX_HOME/.claude" 2>/dev/null || true
chown -R hotplex:hotplex "$HOTPLEX_HOME/projects" 2>/dev/null || true
fi
# ------------------------------------------------------------------------------
# 2. HotPlex Bot Identity & Logging
# ------------------------------------------------------------------------------
echo "==> HotPlex Bot Instance: ${HOTPLEX_BOT_ID:-unknown}"
# ------------------------------------------------------------------------------
# 3. Claude Code Configuration - Seeding & Isolation
# ------------------------------------------------------------------------------
CLAUDE_DIR="$HOTPLEX_HOME/.claude"
CLAUDE_SEED="/home/hotplex/.claude_seed"
# Ensure container-private .claude directory exists
run_as_hotplex mkdir -p "$CLAUDE_DIR"
if [ -d "$CLAUDE_SEED" ]; then
echo "--> Seeding Claude configurations from host..."
# 1. Sync critical capabilities (skills, teams) - Copy only if not exists to avoid overwriting instance-specific changes
for item in "skills" "teams"; do
if [ -d "$CLAUDE_SEED/$item" ]; then
echo " - Syncing $item..."
run_as_hotplex cp -rn "$CLAUDE_SEED/$item" "$CLAUDE_DIR/"
fi
done
# 2. Sync core configuration files
for cfg in "settings.json" "settings.local.json" "config.json"; do
if [ -f "$CLAUDE_SEED/$cfg" ] && [ ! -f "$CLAUDE_DIR/$cfg" ]; then
echo " - Seeding $cfg..."
run_as_hotplex cp "$CLAUDE_SEED/$cfg" "$CLAUDE_DIR/"
# 3. Dynamic Patching: Only replace 127.0.0.1 with host.docker.internal for Docker network compatibility
if [ "$cfg" = "settings.json" ]; then
echo " - Patching 127.0.0.1 -> host.docker.internal in $cfg"
run_as_hotplex sed -i 's/127.0.0.1/host.docker.internal/g' "$CLAUDE_DIR/$cfg"
fi
fi
done
fi
# ------------------------------------------------------------------------------
# 4. Git Identity Injection (from environment variables)
# Allows configuring Git identity via .env without host .gitconfig dependency
# ------------------------------------------------------------------------------
if [ -n "${GIT_USER_NAME:-}" ]; then
echo "--> Setting Git identity: $GIT_USER_NAME"
run_as_hotplex git config --global user.name "$GIT_USER_NAME"
fi
if [ -n "${GIT_USER_EMAIL:-}" ]; then
run_as_hotplex git config --global user.email "$GIT_USER_EMAIL"
fi
# Auto-configure safe.directory for mounted project volumes
if [ -d "$HOTPLEX_HOME/projects" ]; then
run_as_hotplex git config --global --add safe.directory "$HOTPLEX_HOME/projects" || true
# Also add all first-level subdirectories (cloned repos)
for d in "$HOTPLEX_HOME/projects"/*/; do
[ -d "$d/.git" ] && run_as_hotplex git config --global --add safe.directory "$d" || true
done
fi
# ------------------------------------------------------------------------------
# 5. Execute CMD (drop privileges if root)
# Ensures all files created by the app belong to 'hotplex' user
# ------------------------------------------------------------------------------
echo "==> Starting HotPlex Engine..."
if [ "$(id -u)" = "0" ]; then
exec runuser -u hotplex -- "$@"
else
exec "$@"
fi