From 2c98abfd73ea65ac8b3c4750462c6e09a2ace0e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Stan=C4=9Bk?= Date: Sun, 4 Apr 2021 00:20:42 +0200 Subject: [PATCH] run_docker: Allow to run arbitrary command in docker (#1424) Useful for unattended builds. --- docs/project/changelog.md | 2 ++ run_docker | 34 ++++++++++++++++++++-------------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/docs/project/changelog.md b/docs/project/changelog.md index 63ba198b0..54379bdc0 100644 --- a/docs/project/changelog.md +++ b/docs/project/changelog.md @@ -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 diff --git a/run_docker b/run_docker index a54530fe9..28262091b 100755 --- a/run_docker +++ b/run_docker @@ -5,20 +5,21 @@ set -eo pipefail function usage() { cat > /dev/stdout < 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 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