feat: enhance Docker setup with entrypoint script and skill management
- Added a new entrypoint script to manage ownership of bind-mounted directories and merge built-in skills into preloaded ones. - Updated the Dockerfile to include the `gosu` package for privilege management and to set the entrypoint to the new script. - Ensured built-in skills are preserved and accessible after bind-mounting user directories, improving the application's flexibility and usability. These changes streamline the container initialization process and enhance the management of skills within the application.
This commit is contained in:
Executable
+43
@@ -0,0 +1,43 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# ─── Fix ownership of bind-mounted directories ───
|
||||
# When users bind-mount host directories (e.g. ./skills/preloaded),
|
||||
# the mount inherits the host UID/GID which may differ from the
|
||||
# container's appuser. This entrypoint runs as root, fixes ownership,
|
||||
# then drops privileges to appuser via gosu — the same pattern used
|
||||
# by official postgres/redis images.
|
||||
|
||||
# Directories that may be bind-mounted and need appuser access
|
||||
MOUNT_DIRS=(
|
||||
/app/skills/preloaded
|
||||
/data/files
|
||||
)
|
||||
|
||||
for dir in "${MOUNT_DIRS[@]}"; do
|
||||
if [ -d "$dir" ]; then
|
||||
chown -R appuser:appuser "$dir" 2>/dev/null || true
|
||||
fi
|
||||
done
|
||||
|
||||
# ─── Merge built-in skills into preloaded ───
|
||||
# Built-in skills are backed up at /app/skills/_builtin during image build.
|
||||
# After a bind-mount replaces /app/skills/preloaded, copy back any
|
||||
# missing built-in skills (without overwriting user-provided ones).
|
||||
BUILTIN_DIR="/app/skills/_builtin"
|
||||
PRELOADED_DIR="/app/skills/preloaded"
|
||||
|
||||
if [ -d "$BUILTIN_DIR" ]; then
|
||||
mkdir -p "$PRELOADED_DIR"
|
||||
for skill_dir in "$BUILTIN_DIR"/*/; do
|
||||
[ -d "$skill_dir" ] || continue
|
||||
skill_name="$(basename "$skill_dir")"
|
||||
if [ ! -d "$PRELOADED_DIR/$skill_name" ]; then
|
||||
cp -r "$skill_dir" "$PRELOADED_DIR/$skill_name"
|
||||
fi
|
||||
done
|
||||
chown -R appuser:appuser "$PRELOADED_DIR"
|
||||
fi
|
||||
|
||||
# ─── Drop privileges and exec the main process ───
|
||||
exec gosu appuser "$@"
|
||||
Reference in New Issue
Block a user