Skip to content

Commit 3d8212c

Browse files
utils/docker-run: allow running without a tty
Currently, utils/docker-run spawns a container with a tty, so that he user can interact properly in the container. However, that requires a tty when calling docker-run, which is not always guaranteed, e.g. if called from a git hook. Since the script is a bash script already, we can use an array to store options passed to docker, and only add the -t option when there is actually a tty available. Signed-off-by: Yann E. MORIN <[email protected]> Cc: Ricardo Martincoski <[email protected]>
1 parent 6104b62 commit 3d8212c

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

utils/docker-run

+12-5
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,15 @@ MAIN_DIR=$(readlink -f "${DIR}/..")
66
IMAGE=$(grep ^image: "${MAIN_DIR}/.gitlab-ci.yml" | \
77
sed -e 's,^image: ,,g' | sed -e 's,\$CI_REGISTRY,registry.gitlab.com,g')
88

9-
exec docker run -it --rm \
10-
--user "$(id -u):$(id -g)" \
11-
--mount "type=bind,src=${MAIN_DIR},dst=${MAIN_DIR}" \
12-
--workdir "${MAIN_DIR}" \
13-
"${IMAGE}" "${@}"
9+
declare -a docker_opts=(
10+
-i
11+
--rm
12+
--user "$(id -u):$(id -g)"
13+
--mount "type=bind,src=${MAIN_DIR},dst=${MAIN_DIR}"
14+
--workdir "${MAIN_DIR}"
15+
)
16+
if tty -s; then
17+
docker_opts+=( -t )
18+
fi
19+
20+
exec docker run "${docker_opts[@]}" "${IMAGE}" "${@}"

0 commit comments

Comments
 (0)