Update containers/app/entrypoint.sh
Browse files- containers/app/entrypoint.sh +69 -0
containers/app/entrypoint.sh
CHANGED
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/bin/bash
|
2 |
+
set -eo pipefail
|
3 |
+
|
4 |
+
echo "Starting OpenHands..."
|
5 |
+
if [[ $NO_SETUP == "true" ]]; then
|
6 |
+
echo "Skipping setup, running as $(whoami)"
|
7 |
+
"$@"
|
8 |
+
exit 0
|
9 |
+
fi
|
10 |
+
|
11 |
+
if [ "$(id -u)" -ne 0 ]; then
|
12 |
+
echo "The OpenHands entrypoint.sh must run as root"
|
13 |
+
exit 1
|
14 |
+
fi
|
15 |
+
|
16 |
+
if [ -z "$SANDBOX_USER_ID" ]; then
|
17 |
+
echo "SANDBOX_USER_ID is not set"
|
18 |
+
exit 1
|
19 |
+
fi
|
20 |
+
|
21 |
+
if [ -z "$WORKSPACE_MOUNT_PATH" ]; then
|
22 |
+
# This is set to /opt/workspace in the Dockerfile. But if the user isn't mounting, we want to unset it so that OpenHands doesn't mount at all
|
23 |
+
unset WORKSPACE_BASE
|
24 |
+
fi
|
25 |
+
|
26 |
+
if [[ "$SANDBOX_USER_ID" -eq 0 ]]; then
|
27 |
+
echo "Running OpenHands as root"
|
28 |
+
export RUN_AS_OPENHANDS=false
|
29 |
+
mkdir -p /root/.cache/ms-playwright/
|
30 |
+
if [ -d "/home/openhands/.cache/ms-playwright/" ]; then
|
31 |
+
mv /home/openhands/.cache/ms-playwright/ /root/.cache/
|
32 |
+
fi
|
33 |
+
"$@"
|
34 |
+
else
|
35 |
+
echo "Setting up enduser with id $SANDBOX_USER_ID"
|
36 |
+
if id "enduser" &>/dev/null; then
|
37 |
+
echo "User enduser already exists. Skipping creation."
|
38 |
+
else
|
39 |
+
if ! useradd -l -m -u $SANDBOX_USER_ID -s /bin/bash enduser; then
|
40 |
+
echo "Failed to create user enduser with id $SANDBOX_USER_ID. Moving openhands user."
|
41 |
+
incremented_id=$(($SANDBOX_USER_ID + 1))
|
42 |
+
usermod -u $incremented_id openhands
|
43 |
+
if ! useradd -l -m -u $SANDBOX_USER_ID -s /bin/bash enduser; then
|
44 |
+
echo "Failed to create user enduser with id $SANDBOX_USER_ID for a second time. Exiting."
|
45 |
+
exit 1
|
46 |
+
fi
|
47 |
+
fi
|
48 |
+
fi
|
49 |
+
usermod -aG app enduser
|
50 |
+
# get the user group of /var/run/docker.sock and set openhands to that group
|
51 |
+
DOCKER_SOCKET_GID=$(stat -c '%g' /var/run/docker.sock)
|
52 |
+
echo "Docker socket group id: $DOCKER_SOCKET_GID"
|
53 |
+
if getent group $DOCKER_SOCKET_GID; then
|
54 |
+
echo "Group with id $DOCKER_SOCKET_GID already exists"
|
55 |
+
else
|
56 |
+
echo "Creating group with id $DOCKER_SOCKET_GID"
|
57 |
+
groupadd -g $DOCKER_SOCKET_GID docker
|
58 |
+
fi
|
59 |
+
|
60 |
+
mkdir -p /home/enduser/.cache/huggingface/hub/
|
61 |
+
mkdir -p /home/enduser/.cache/ms-playwright/
|
62 |
+
if [ -d "/home/openhands/.cache/ms-playwright/" ]; then
|
63 |
+
mv /home/openhands/.cache/ms-playwright/ /home/enduser/.cache/
|
64 |
+
fi
|
65 |
+
|
66 |
+
usermod -aG $DOCKER_SOCKET_GID enduser
|
67 |
+
echo "Running as enduser"
|
68 |
+
su enduser /bin/bash -c "${*@Q}" # This magically runs any arguments passed to the script as a command
|
69 |
+
fi
|