* [Buildroot] [PATCH] utils/docker-run: allow running without a tty
@ 2023-04-15 19:43 Yann E. MORIN
2023-04-23 17:37 ` Yann E. MORIN
2023-05-02 6:30 ` Peter Korsgaard
0 siblings, 2 replies; 3+ messages in thread
From: Yann E. MORIN @ 2023-04-15 19:43 UTC (permalink / raw)
To: buildroot; +Cc: Yann E. MORIN, Ricardo Martincoski
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>
---
utils/docker-run | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/utils/docker-run b/utils/docker-run
index 164e11c0e6..135a1451b6 100755
--- a/utils/docker-run
+++ b/utils/docker-run
@@ -6,8 +6,15 @@ MAIN_DIR=$(readlink -f "${DIR}/..")
IMAGE=$(grep ^image: "${MAIN_DIR}/.gitlab-ci.yml" | \
sed -e 's,^image: ,,g' | sed -e 's,\$CI_REGISTRY,registry.gitlab.com,g')
-exec docker run -it --rm \
- --user "$(id -u):$(id -g)" \
- --mount "type=bind,src=${MAIN_DIR},dst=${MAIN_DIR}" \
- --workdir "${MAIN_DIR}" \
- "${IMAGE}" "${@}"
+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}" "${@}"
--
2.25.1
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [Buildroot] [PATCH] utils/docker-run: allow running without a tty
2023-04-15 19:43 [Buildroot] [PATCH] utils/docker-run: allow running without a tty Yann E. MORIN
@ 2023-04-23 17:37 ` Yann E. MORIN
2023-05-02 6:30 ` Peter Korsgaard
1 sibling, 0 replies; 3+ messages in thread
From: Yann E. MORIN @ 2023-04-23 17:37 UTC (permalink / raw)
To: buildroot; +Cc: Ricardo Martincoski
All,
On 2023-04-15 21:43 +0200, Yann E. MORIN spake thusly:
> 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>
Applied to master, thanks.
Regards,
Yann E. MORIN.
> ---
> utils/docker-run | 17 ++++++++++++-----
> 1 file changed, 12 insertions(+), 5 deletions(-)
>
> diff --git a/utils/docker-run b/utils/docker-run
> index 164e11c0e6..135a1451b6 100755
> --- a/utils/docker-run
> +++ b/utils/docker-run
> @@ -6,8 +6,15 @@ MAIN_DIR=$(readlink -f "${DIR}/..")
> IMAGE=$(grep ^image: "${MAIN_DIR}/.gitlab-ci.yml" | \
> sed -e 's,^image: ,,g' | sed -e 's,\$CI_REGISTRY,registry.gitlab.com,g')
>
> -exec docker run -it --rm \
> - --user "$(id -u):$(id -g)" \
> - --mount "type=bind,src=${MAIN_DIR},dst=${MAIN_DIR}" \
> - --workdir "${MAIN_DIR}" \
> - "${IMAGE}" "${@}"
> +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}" "${@}"
> --
> 2.25.1
>
--
.-----------------.--------------------.------------------.--------------------.
| Yann E. MORIN | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software Designer | \ / CAMPAIGN | ___ |
| +33 561 099 427 `------------.-------: X AGAINST | \e/ There is no |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL | v conspiracy. |
'------------------------------^-------^------------------^--------------------'
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [Buildroot] [PATCH] utils/docker-run: allow running without a tty
2023-04-15 19:43 [Buildroot] [PATCH] utils/docker-run: allow running without a tty Yann E. MORIN
2023-04-23 17:37 ` Yann E. MORIN
@ 2023-05-02 6:30 ` Peter Korsgaard
1 sibling, 0 replies; 3+ messages in thread
From: Peter Korsgaard @ 2023-05-02 6:30 UTC (permalink / raw)
To: Yann E. MORIN; +Cc: Ricardo Martincoski, buildroot
>>>>> "Yann" == Yann E MORIN <yann.morin.1998@free.fr> writes:
> 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>
Committed to 2023.02.x, thanks.
--
Bye, Peter Korsgaard
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-05-02 6:30 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-15 19:43 [Buildroot] [PATCH] utils/docker-run: allow running without a tty Yann E. MORIN
2023-04-23 17:37 ` Yann E. MORIN
2023-05-02 6:30 ` Peter Korsgaard
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox