kumquat-buildroot/utils/docker-run
Yann E. MORIN 3d8212c4b2 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 <yann.morin.1998@free.fr>
Cc: Ricardo Martincoski <ricardo.martincoski@gmail.com>
2023-04-23 19:34:00 +02:00

21 lines
525 B
Bash
Executable File

#!/usr/bin/env bash
set -o errexit -o pipefail
DIR=$(dirname "${0}")
MAIN_DIR=$(readlink -f "${DIR}/..")
# shellcheck disable=SC2016
IMAGE=$(grep ^image: "${MAIN_DIR}/.gitlab-ci.yml" | \
sed -e 's,^image: ,,g' | sed -e 's,\$CI_REGISTRY,registry.gitlab.com,g')
declare -a docker_opts=(
-i
--rm
--user "$(id -u):$(id -g)"
--mount "type=bind,src=${MAIN_DIR},dst=${MAIN_DIR}"
--workdir "${MAIN_DIR}"
)
if tty -s; then
docker_opts+=( -t )
fi
exec docker run "${docker_opts[@]}" "${IMAGE}" "${@}"