You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by ar...@apache.org on 2021/04/06 00:50:05 UTC
[tvm] branch main updated: [CI] docker images build script cmd line
args optional (#7776)
This is an automated email from the ASF dual-hosted git repository.
areusch pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm.git
The following commit(s) were added to refs/heads/main by this push:
new f0fddc8 [CI] docker images build script cmd line args optional (#7776)
f0fddc8 is described below
commit f0fddc828492829944130f97ddb0604f2d600357
Author: Mher Kazandjian <mh...@gmail.com>
AuthorDate: Tue Apr 6 02:49:53 2021 +0200
[CI] docker images build script cmd line args optional (#7776)
* allow COMMAND to be empty when building a container
* clarfiy the difference between build.sh and bash.sh
* fix typo and highlight command as option in usage snippet
---
docker/README.md | 36 ++++++++++++++++++++++++++++++-----
docker/build.sh | 58 ++++++++++++++++++++++++++++++--------------------------
2 files changed, 62 insertions(+), 32 deletions(-)
diff --git a/docker/README.md b/docker/README.md
index ae972f9..5e47035 100644
--- a/docker/README.md
+++ b/docker/README.md
@@ -32,6 +32,7 @@ interactive bash session with a given image_name.
```
The script does the following things:
+
- Mount current directory to /workspace and set it as home
- Switch user to be the same user that calls the bash.sh
- Use the host-side network
@@ -59,12 +60,12 @@ Note that these are convenience images and are not part of the ASF release.
## Use Local Build Script
We also provide script to build docker images locally.
-We use (`build.sh`)[./build.sh] to build and run the commands.
-To build and run docker images, we can run the following command
-at the root of the project.
+We use (`build.sh`)[./build.sh] to build and (optionally) run commands
+in the container. To build and run docker images, we can run the following
+command at the root of the project.
```bash
-./docker/build.sh image_name [command]
+./docker/build.sh image_name [command(optional)]
```
Here image_name corresponds to the docker defined in the
@@ -76,6 +77,31 @@ You can also start an interactive session by typing
./docker/build.sh image_name -it bash
```
+The built docker images are prefixed by ``tvm.``, for example the command
+
+````bash
+./docker/build.sh image_name
+````
+
+produces the image ``tvm.ci_cpu`` that is displayed in the list of docker images
+using the command ``docker images``. To run an interactive terminal, execute:
+
+````bash
+./docker/bash.sh tvm.ci_cpu
+````
+
+or
+
+````bash
+./docker/bash.sh tvm.ci_cpu echo hello tvm world
+````
+
+the same applies to the other images (``./docker/Dockerfile.*```).
+
+The command ``./docker/build.sh image_name COMMANDS`` is almost equivelant to
+``./docker/bash.sh image_name COMMANDS`` but in the case of ``bash.sh``
+a build attempt is not done.
+
The build command will map the tvm root to /workspace/ inside the container
with the same user as the user invoking the docker command.
Here are some common use examples to perform CI tasks.
@@ -83,7 +109,7 @@ Here are some common use examples to perform CI tasks.
- lint the python codes
```bash
- ./docker/build.sh ci_lint make pylint
+ ./docker/build.sh tvm.ci_lint make pylint
```
- build codes with CUDA support
diff --git a/docker/build.sh b/docker/build.sh
index f966e22..d574e20 100755
--- a/docker/build.sh
+++ b/docker/build.sh
@@ -18,11 +18,11 @@
# under the License.
#
-# Execute command within a docker container
+# Build a docker container and optionally execute command within a it
#
# Usage: build.sh <CONTAINER_TYPE> [--tag <DOCKER_IMAGE_TAG>]
# [--dockerfile <DOCKERFILE_PATH>] [-it]
-# [--net=host] [--cache-from <IMAGE_NAME>] <COMMAND>
+# [--net=host] [--cache-from <IMAGE_NAME>] [<COMMAND>]
#
# CONTAINER_TYPE: Type of the docker container used the run the build,
# e.g. "ci_cpu", "ci_gpu"
@@ -37,7 +37,7 @@
# IMAGE_NAME: An image to be as a source for cached layers when building the
# Docker image requested.
#
-# COMMAND: Command to be executed in the docker container
+# COMMAND (optional): Command to be executed in the docker container
#
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
@@ -90,12 +90,12 @@ fi
COMMAND=("$@")
# Validate command line arguments.
-if [ "$#" -lt 1 ] || [ ! -e "${SCRIPT_DIR}/Dockerfile.${CONTAINER_TYPE}" ]; then
+if [ ! -e "${SCRIPT_DIR}/Dockerfile.${CONTAINER_TYPE}" ]; then
supported_container_types=$( ls -1 ${SCRIPT_DIR}/Dockerfile.* | \
sed -n 's/.*Dockerfile\.\([^\/]*\)/\1/p' | tr '\n' ' ' )
echo "Usage: $(basename $0) CONTAINER_TYPE COMMAND"
echo " CONTAINER_TYPE can be one of [${supported_container_types}]"
- echo " COMMAND is a command (with arguments) to run inside"
+ echo " COMMAND (optional) is a command (with arguments) to run inside"
echo " the container."
exit 1
fi
@@ -164,25 +164,29 @@ if [[ $? != "0" ]]; then
exit 1
fi
-# Run the command inside the container.
-echo "Running '${COMMAND[@]}' inside ${DOCKER_IMG_SPEC}..."
-
-# By default we cleanup - remove the container once it finish running (--rm)
-# and share the PID namespace (--pid=host) so the process inside does not have
-# pid 1 and SIGKILL is propagated to the process inside (jenkins can kill it).
-echo ${DOCKER_BINARY}
-${DOCKER_BINARY} run --rm --pid=host \
- -v ${WORKSPACE}:/workspace \
- -w /workspace \
- -e "CI_BUILD_HOME=/workspace" \
- -e "CI_BUILD_USER=$(id -u -n)" \
- -e "CI_BUILD_UID=$(id -u)" \
- -e "CI_BUILD_GROUP=$(id -g -n)" \
- -e "CI_BUILD_GID=$(id -g)" \
- -e "CI_PYTEST_ADD_OPTIONS=$CI_PYTEST_ADD_OPTIONS" \
- -e "CI_IMAGE_NAME=${DOCKER_IMAGE_NAME}" \
- ${CUDA_ENV}\
- ${CI_DOCKER_EXTRA_PARAMS[@]} \
- ${DOCKER_IMG_SPEC} \
- bash --login docker/with_the_same_user \
- ${COMMAND[@]}
+if [[ -n ${COMMAND} ]]; then
+
+ # Run the command inside the container.
+ echo "Running '${COMMAND[@]}' inside ${DOCKER_IMG_SPEC}..."
+
+ # By default we cleanup - remove the container once it finish running (--rm)
+ # and share the PID namespace (--pid=host) so the process inside does not have
+ # pid 1 and SIGKILL is propagated to the process inside (jenkins can kill it).
+ echo ${DOCKER_BINARY}
+ ${DOCKER_BINARY} run --rm --pid=host \
+ -v ${WORKSPACE}:/workspace \
+ -w /workspace \
+ -e "CI_BUILD_HOME=/workspace" \
+ -e "CI_BUILD_USER=$(id -u -n)" \
+ -e "CI_BUILD_UID=$(id -u)" \
+ -e "CI_BUILD_GROUP=$(id -g -n)" \
+ -e "CI_BUILD_GID=$(id -g)" \
+ -e "CI_PYTEST_ADD_OPTIONS=$CI_PYTEST_ADD_OPTIONS" \
+ -e "CI_IMAGE_NAME=${DOCKER_IMAGE_NAME}" \
+ ${CUDA_ENV}\
+ ${CI_DOCKER_EXTRA_PARAMS[@]} \
+ ${DOCKER_IMG_SPEC} \
+ bash --login docker/with_the_same_user \
+ ${COMMAND[@]}
+
+fi