-
Notifications
You must be signed in to change notification settings - Fork 31
/
entrypoint.sh
executable file
·44 lines (36 loc) · 1.47 KB
/
entrypoint.sh
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
#!/usr/bin/env bash
set -e
# Check for algorithm main file
if [[ -z "$ALGORITHM_MAIN" ]]; then
echo 'No algorithm main file specified. Environment variable $ALGORITHM_MAIN is empty!' >&2
echo "Add the following to your Dockerfile: 'ENV ALGORITHM_MAIN=/app/<your algorithm main file>'" >&2
exit 1
fi
# Create user with the supplied user ID and group ID to use the correct privileges on the mounted volumes
# -- more information at the end of the file.
Z_UID=0
Z_GID=0
if [[ ! -z "$LOCAL_UID" ]] && [[ ! -z "$LOCAL_GID" ]]; then
addgroup --quiet --gid "${LOCAL_GID}" group
adduser --quiet --gid "${LOCAL_GID}" --uid "${LOCAL_UID}" --no-create-home --disabled-password --disabled-login --gecos "" user
Z_UID=$LOCAL_UID
Z_GID=$LOCAL_GID
# Reset owner:group of working directory
chown -R "$Z_UID:$Z_GID" .
fi
# check and execute command
if [[ "$1" == "manifest" ]]; then
# output the algorithm manifest
cat /app/manifest.json
elif [[ "$1" == "execute-algorithm" ]]; then
# run algorithm
shift
exec setpriv --reuid=$Z_UID --regid=$Z_GID --init-groups -- java -jar "$ALGORITHM_MAIN" "$@"
else
# just run supplied command inside container
exec setpriv --reuid=$Z_UID --regid=$Z_GID --init-groups -- "$@"
fi
# To forward the GID of the group "akita" and the UID of the current user to the docker container run:
# LOCAL_GID=$(getent group akita | cut -d ':' -f 3)
# LOCAL_UID=$(id -u)
# docker run -e LOCAL_GID -e LOCAL_UID this-image:latest id