summaryrefslogtreecommitdiffhomepage
path: root/docker
diff options
context:
space:
mode:
Diffstat (limited to 'docker')
-rw-r--r--docker/entrypoint.dev.sh52
1 files changed, 44 insertions, 8 deletions
diff --git a/docker/entrypoint.dev.sh b/docker/entrypoint.dev.sh
index b28b44f..8378585 100644
--- a/docker/entrypoint.dev.sh
+++ b/docker/entrypoint.dev.sh
@@ -1,11 +1,47 @@
#!/bin/bash
set -euo pipefail
-# Install/update dependencies.
-# Source code is bind-mounted from the host; node_modules lives on the host
-# filesystem via the bind mount so it persists across container restarts
-# and is shared between the api and frontend services.
-bun install
-
-# Execute the main command
-exec "$@"
+# ─── Match host user inside container ────────────────────────────
+# Ensures the process runs as the host UID/GID with a matching
+# home directory so volume mounts and config paths are consistent.
+
+HOST_UID="${HOST_UID:-1000}"
+HOST_GID="${HOST_GID:-1000}"
+HOST_USER="${HOST_USER:-dispatch}"
+
+USER_HOME="/home/$HOST_USER"
+
+# Create group if it doesn't exist
+if ! getent group "$HOST_GID" > /dev/null 2>&1; then
+ groupadd -g "$HOST_GID" "$HOST_USER"
+fi
+
+# Ensure user with this UID has the correct home directory
+if id -u "$HOST_UID" > /dev/null 2>&1; then
+ USER_NAME=$(getent passwd "$HOST_UID" | cut -d: -f1)
+ usermod -d "$USER_HOME" "$USER_NAME" 2>/dev/null || true
+else
+ useradd -u "$HOST_UID" -g "$HOST_GID" -d "$USER_HOME" -m -s /bin/bash "$HOST_USER"
+ USER_NAME="$HOST_USER"
+fi
+
+# Ensure home and data directories exist with correct ownership
+mkdir -p "$USER_HOME" "$USER_HOME/.local/share/dispatch"
+chown "$HOST_UID:$HOST_GID" "$USER_HOME"
+chown -R "$HOST_UID:$HOST_GID" "$USER_HOME/.local/share/dispatch"
+
+# Ensure .claude is accessible
+if [ -d "$USER_HOME/.claude" ]; then
+ chown -R "$HOST_UID:$HOST_GID" "$USER_HOME/.claude" 2>/dev/null || true
+fi
+
+# Ensure node_modules is writable (created as root during build)
+if [ -d /app/node_modules ]; then
+ chown -R "$HOST_UID:$HOST_GID" /app/node_modules
+fi
+
+# Install/update dependencies as the target user
+su -s /bin/bash - "$USER_NAME" -c "export HOME=$USER_HOME && cd /app && bun install"
+
+# Execute the main command as the target user
+exec su -s /bin/bash - "$USER_NAME" -c "export HOME=$USER_HOME && cd /app && exec $*"