-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathdocker-entrypoint.sh
More file actions
executable file
·48 lines (41 loc) · 1.68 KB
/
Copy pathdocker-entrypoint.sh
File metadata and controls
executable file
·48 lines (41 loc) · 1.68 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
#!/bin/sh
set -e
# If running as root, fix data directory ownership and drop privileges.
if [ "$(id -u)" = '0' ]; then
TARGET_UID="${PUID:-1000}"
TARGET_GID="${PGID:-1000}"
# Reject UID/GID 0 — matches the build-time APP_UID/APP_GID guard.
if [ "$TARGET_UID" -eq 0 ] || [ "$TARGET_GID" -eq 0 ]; then
echo "ERROR: PUID and PGID must be non-zero" >&2
exit 1
fi
# Update appuser UID/GID if they differ from build-time defaults.
cur_uid="$(id -u appuser)"
cur_gid="$(id -g appuser)"
if [ "$cur_gid" != "$TARGET_GID" ]; then
groupmod -o -g "$TARGET_GID" appuser
fi
if [ "$cur_uid" != "$TARGET_UID" ]; then
usermod -o -u "$TARGET_UID" -g "$TARGET_GID" appuser
fi
# Ensure state subdirectories exist inside the volume.
# Dockerfile seeds these on first use, but externally-created or
# pre-existing volumes may be empty.
mkdir -p /data/state/embeddings /data/state/fastembed /data/state/fastmcp
# Always fix ownership of state subdirs — mkdir creates as root,
# but the conditional chown loop below may skip /data/state if it
# was already owned by appuser from a previous run.
chown appuser:appuser /data/state/*
# Fix ownership — named volumes may arrive root-owned.
# Only recurse into directories still owned by root, to avoid
# touching bind-mounted vault files on every restart.
chown appuser:appuser /data
for _dir in /data/*; do
if [ -d "$_dir" ] && [ "$(stat -c '%u' "$_dir")" = '0' ]; then
chown -R appuser:appuser "$_dir"
fi
done
exec gosu appuser "$@"
fi
# Already running as non-root (e.g. user: directive in compose).
exec "$@"