run_docker: option to run non-interactively (#1641)

Allows to execute `run_docker` in environments such as Github Actions.
Specifying the `--non-interactive` flag resolves the error "the input device
is not a TTY".

Co-authored-by: Ondrej Stanek <ondrej@ostan.cz>
This commit is contained in:
Ondřej Staněk 2021-06-17 00:04:47 +02:00 committed by GitHub
parent da019813a5
commit f9a68998e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -241,6 +241,8 @@ See the {ref}`0-17-0-release-notes` for more information.
[pyodide/pyodide-env](https://hub.docker.com/repository/docker/pyodide/pyodide-env) [pyodide/pyodide-env](https://hub.docker.com/repository/docker/pyodide/pyodide-env)
and and
[pyodide/pyodide](https://hub.docker.com/repository/docker/pyodide/pyodide). [pyodide/pyodide](https://hub.docker.com/repository/docker/pyodide/pyodide).
- {{ Enhancement }} Option to run docker in non-interactive mode
{pr}`1641`
### REPL ### REPL

View File

@ -6,6 +6,7 @@ PYODIDE_PREBUILT_IMAGE_TAG="0.17.0"
DEFAULT_PYODIDE_DOCKER_IMAGE="${PYODIDE_IMAGE_REPO}/pyodide-env:${PYODIDE_IMAGE_TAG}" DEFAULT_PYODIDE_DOCKER_IMAGE="${PYODIDE_IMAGE_REPO}/pyodide-env:${PYODIDE_IMAGE_TAG}"
DEFAULT_PYODIDE_SYSTEM_PORT="8000" DEFAULT_PYODIDE_SYSTEM_PORT="8000"
DOCKER_COMMAND="/bin/bash" DOCKER_COMMAND="/bin/bash"
DOCKER_INTERACTIVE="--interactive"
set -eo pipefail set -eo pipefail
@ -24,6 +25,8 @@ Options:
-p, --port <port> System port to which to forward. -p, --port <port> System port to which to forward.
This is ignored if the env var PYODIDE_SYSTEM_PORT is set. This is ignored if the env var PYODIDE_SYSTEM_PORT is set.
If set to 'none', docker instance will not bind to any port. If set to 'none', docker instance will not bind to any port.
--non-interactive Run docker without the --interactive flag.
Useful for running in headless mode on CI server.
Prerequisites: Prerequisites:
Docker has to be set up on your system. Docker has to be set up on your system.
@ -62,6 +65,10 @@ do
DEFAULT_PYODIDE_SYSTEM_PORT=$2 DEFAULT_PYODIDE_SYSTEM_PORT=$2
shift 2 shift 2
;; ;;
--non-interactive)
DOCKER_INTERACTIVE="--interactive=false"
shift
;;
-*) -*)
>&2 echo "Unknown option $1" >&2 echo "Unknown option $1"
error error
@ -120,7 +127,7 @@ CONTAINER=$(\
EXIT_STATUS=0 EXIT_STATUS=0
# Execute the provided command as the host user with HOME=/src # Execute the provided command as the host user with HOME=/src
docker exec \ docker exec \
-it \ $DOCKER_INTERACTIVE --tty \
--user $(id --user):$(id --group) \ --user $(id --user):$(id --group) \
$CONTAINER \ $CONTAINER \
/bin/bash -c "${DOCKER_COMMAND}" || EXIT_STATUS=$? /bin/bash -c "${DOCKER_COMMAND}" || EXIT_STATUS=$?