2019-04-06 06:09:21 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
DOCKER="${DOCKER:-%DOCKER%}"
|
|
|
|
IMAGE="${IMAGE:-%IMAGE%}"
|
|
|
|
NETWORK="${NETWORK:-host}"
|
2019-04-17 15:25:56 +00:00
|
|
|
PROJECTDIR="${PROJECTDIR:-%PROJECTDIR%}"
|
|
|
|
SCRIPTDIR="${SCRIPTDIR:-%SCRIPTDIR%/bin}"
|
2019-04-06 06:09:21 +00:00
|
|
|
ENTRYPOINT="${ENTRYPOINT:-%RUNCMD%}"
|
2019-04-17 15:25:56 +00:00
|
|
|
PATH="${SCRIPTDIR}:$PATH"
|
2019-04-06 06:09:21 +00:00
|
|
|
|
|
|
|
set -- --entrypoint "$ENTRYPOINT" "$IMAGE" "$@"
|
|
|
|
set -- --network "$NETWORK" --workdir "$PWD" "$@"
|
|
|
|
|
|
|
|
if [ -n "$USERID" ]; then
|
|
|
|
set -- --user "$USERID:$USERID" "$@"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$PID" ]; then
|
|
|
|
set -- --pid "$PID" "$@"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$CONTAINER_CGROUP_PARENT" ]; then
|
|
|
|
set -- --cgroup-parent "$CONTAINER_CGROUP_PARENT" "$@"
|
|
|
|
fi
|
|
|
|
|
2019-04-17 15:25:56 +00:00
|
|
|
HOST_CONTAINER="${HOST_CONTAINER:-"$(get_container_id.sh)"}" || true
|
2019-04-06 06:09:21 +00:00
|
|
|
if [ -n "$HOST_CONTAINER" ]; then
|
2019-04-17 15:25:56 +00:00
|
|
|
set -- --volumes-from "$HOST_CONTAINER" "$@"
|
|
|
|
else
|
|
|
|
set -- --volume "$PROJECTDIR:$PROJECTDIR:cached" "$@"
|
2019-04-06 06:09:21 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
set -- %RUNFLAGS% "$@"
|
|
|
|
|
2019-04-17 15:25:56 +00:00
|
|
|
if [ -t 0 ] && ! is_running_in_bg.sh $$; then
|
2019-04-06 06:09:21 +00:00
|
|
|
set -- --interactive "$@"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# if STDIN piped or redirected
|
|
|
|
if [ -p /dev/stdin ] || { [ ! -t 0 ] && [ ! -p /dev/stdin ]; }; then
|
|
|
|
set -- --interactive "$@"
|
|
|
|
elif [ -t 1 ]; then
|
|
|
|
set -- --tty "$@"
|
|
|
|
fi
|
|
|
|
|
|
|
|
set -- --rm "$@"
|
|
|
|
|
|
|
|
exec "$DOCKER" run "$@"
|