run_docker: Allow to run arbitrary command in docker (#1424)

Useful for unattended builds.
This commit is contained in:
Ondřej Staněk 2021-04-04 00:20:42 +02:00 committed by GitHub
parent 52045b7802
commit 2c98abfd73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 14 deletions

View File

@ -149,6 +149,8 @@ substitutions:
[#987](https://github.com/pyodide/pyodide/pull/987).
- {{ Enhancement }} Optionally to disable docker port binding
[#1423](https://github.com/pyodide/pyodide/pull/1423).
- {{ Enhancement }} Run arbitrary command in docker
[#1424](https://github.com/pyodide/pyodide/pull/1424)
### REPL

View File

@ -5,20 +5,21 @@ set -eo pipefail
function usage() {
cat > /dev/stdout <<EOF
Usage:
run_docker [OPTIONS]
Usage: run_docker [OPTIONS] [COMMAND] [ARG...]
Optional flags:
-h, --help Show this information and exit
--pre-built Use the prebuilt pyodide image.
This is ignored if the env var PYODIDE_DOCKER_IMAGE is set
-p, --port <port> System port to which to forward.
This is ignored if the env var PYODIDE_SYSTEM_PORT is set
If set to 'none', docker instance will not bind to any port
(Useful for running the docker in multi-user environment)
Runs COMMAND in a new Pyodide docker container. If no COMMAND is provided, starts a bash
shell in the container.
Prerequisites:
Docker has to be set up on your system
Options:
-h, --help Show this information and exit.
--pre-built Use the prebuilt Pyodide image.
This is ignored if the env var PYODIDE_DOCKER_IMAGE is set.
-p, --port <port> System port to which to forward.
This is ignored if the env var PYODIDE_SYSTEM_PORT is set.
If set to 'none', docker instance will not bind to any port.
Prerequisites:
Docker has to be set up on your system.
EOF
}
@ -32,6 +33,7 @@ PYODIDE_IMAGE_TAG="12"
PYODIDE_PREBUILT_IMAGE_TAG="0.17.0a2"
DEFAULT_PYODIDE_DOCKER_IMAGE="iodide/pyodide-env:${PYODIDE_IMAGE_TAG}"
DEFAULT_PYODIDE_SYSTEM_PORT="8000"
DOCKER_COMMAND="/bin/bash"
while [[ $# -gt 0 ]]
do
@ -60,10 +62,14 @@ do
DEFAULT_PYODIDE_SYSTEM_PORT=$2
shift 2
;;
*)
-*)
>&2 echo "Unknown option $1"
error
;;
*)
DOCKER_COMMAND="$@"
break
;;
esac
done
@ -92,4 +98,4 @@ exec docker run \
--user root -e NB_UID=$UID -e NB_GID=$GID \
--shm-size 2g \
"${PYODIDE_DOCKER_IMAGE}" \
/bin/bash
$DOCKER_COMMAND