-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathentrypoint_build.sh
More file actions
55 lines (45 loc) · 1.68 KB
/
entrypoint_build.sh
File metadata and controls
55 lines (45 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
49
50
51
52
53
54
55
#!/usr/bin/env bash
set -x
set -euo pipefail
# Graceful shutdown for dockerd if needed
term() {
killall dockerd || true
wait
}
# Optionally run Docker in the container if you need nested Docker
#sudo dockerd -s vfs &
trap term INT TERM
# If your build or environment requires this sysctl tweak
sudo sysctl -w vm.max_map_count=262144 || true
if [[ -n "${USER_NAME:-}" && -n "${USER_UID:-}" && -n "${USER_GID:-}" ]]; then
echo "Creating user ${USER_NAME} with UID=${USER_UID}, GID=${USER_GID}..."
if ! getent group "$USER_GID" >/dev/null; then
groupadd -g "$USER_GID" "$USER_NAME"
fi
if ! id -u "$USER_NAME" >/dev/null 2>&1; then
useradd -m -u "$USER_UID" -g "$USER_GID" -s /bin/bash "$USER_NAME"
echo "$USER_NAME ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/$USER_NAME
chmod 0440 /etc/sudoers.d/$USER_NAME
fi
# Use DOCKER_GID from environment if set, otherwise default to 999
DOCKER_GROUP_ID="${DOCKER_GID:-999}"
if ! getent group docker >/dev/null; then
groupadd -g "$DOCKER_GROUP_ID" docker
else
# If docker group exists but with wrong GID, modify it
EXISTING_GID=$(getent group docker | cut -d: -f3)
if [ "$EXISTING_GID" != "$DOCKER_GROUP_ID" ]; then
groupmod -g "$DOCKER_GROUP_ID" docker
fi
fi
usermod -aG docker "$USER_NAME"
chown -R "$USER_UID":"$USER_GID" /gpu-operator
chown -R "$USER_UID":"$USER_GID" /home/$USER_NAME
su - "$USER_NAME" -c "echo 'export GOPATH=/home/$USER_NAME/go' >> ~/.bashrc"
su - "$USER_NAME" -c "echo 'export PATH=\$GOPATH/bin:/usr/local/go/bin:\$PATH' >> ~/.bashrc"
su - "$USER_NAME" -c "echo 'export PATH=/usr/local/go/bin:\$PATH' >> ~/.bashrc"
exec gosu "$USER_NAME" bash -c "$@"
else
echo "Running as default user (root)..."
exec "$@"
fi