Skip to content

Commit

Permalink
[Docker] Added --repo-mount-point for docker/bash.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
Lunderberg committed Aug 6, 2021
1 parent cbb6e2a commit 98cc6a3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 14 deletions.
9 changes: 5 additions & 4 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,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
- Mount current directory to the same location in the docker container, and set it as home
- Switch user to be the same user that calls the bash.sh
- Use the host-side network

Expand Down Expand Up @@ -102,9 +102,10 @@ 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.
The build command will map the tvm root to the corresponding location
inside the container with the same user as the user invoking the
docker command. Here are some common use examples to perform CI
tasks.

- lint the python codes

Expand Down
39 changes: 29 additions & 10 deletions docker/bash.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# under the License.

#
# Start a bash, mount /workspace to be current directory.
# Start a bash, mount REPO_MOUNT_POINT to be current directory.
#
# Usage: bash.sh <CONTAINER_TYPE> [-i] [--net=host] [--mount path] <CONTAINER_NAME> <COMMAND>
#
Expand All @@ -35,7 +35,8 @@ set -euo pipefail
function show_usage() {
cat <<EOF
Usage: docker/bash.sh [-i|--interactive] [--net=host]
[--mount MOUNT_DIR] [--dry-run]
[--mount MOUNT_DIR] [--repo-mount-point REPO_MOUNT_POINT]
[--dry-run]
<DOCKER_IMAGE_NAME> [--] [COMMAND]
-h, --help
Expand All @@ -60,6 +61,14 @@ Usage: docker/bash.sh [-i|--interactive] [--net=host]
the folder location outside the container. This option can be
specified multiple times.
--repo-mount-point REPO_MOUNT_POINT
The directory inside the docker container at which the TVM
repository should be mounted, and is used as the workspace inside
the docker container. If unspecified, the TVM repository will be
mounted at the same location inside the docker container as
outside.
--dry-run
Print the docker command to be run, but do not execute it.
Expand Down Expand Up @@ -87,18 +96,23 @@ EOF
### Start of argument parsing ###
#################################

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
WORKSPACE="$(dirname "${SCRIPT_DIR}")"

DRY_RUN=false
INTERACTIVE=false
USE_NET_HOST=false
DOCKER_IMAGE_NAME=
COMMAND=bash
REPO_MOUNT_POINT="${WORKSPACE}"
MOUNT_DIRS=( )

trap "show_usage >&2" ERR
args=$(getopt \
--name bash.sh \
--options "ih" \
--longoptions "interactive,net=host,mount:,dry-run" \
--longoptions "repo-mount-point:" \
--longoptions "help" \
--unquoted \
-- "$@")
Expand All @@ -123,7 +137,7 @@ while (( $# )); do
;;

--mount)
MOUNT_DIRS+=($2)
MOUNT_DIRS+=("$2")
shift
shift
;;
Expand All @@ -133,6 +147,12 @@ while (( $# )); do
shift
;;

--repo-mount-point)
REPO_MOUNT_POINT="$2"
shift
shift
;;

--)
shift
break
Expand Down Expand Up @@ -191,15 +211,14 @@ if [ -n "${EXPANDED_SHORTCUT}" ]; then
fi

# Set up working directories
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
WORKSPACE="$(dirname "${SCRIPT_DIR}")"
DOCKER_FLAGS+=( --workdir /workspace )
DOCKER_MOUNT+=( --volume "${WORKSPACE}":/workspace

DOCKER_FLAGS+=( --workdir "${REPO_MOUNT_POINT}" )
DOCKER_MOUNT+=( --volume "${WORKSPACE}":"${REPO_MOUNT_POINT}"
--volume "${SCRIPT_DIR}":/docker
)

# Set up CI-specific environment variables
DOCKER_ENV+=( --env CI_BUILD_HOME=/workspace
DOCKER_ENV+=( --env CI_BUILD_HOME="${REPO_MOUNT_POINT}"
--env CI_BUILD_USER="$(id -u -n)"
--env CI_BUILD_UID="$(id -u)"
--env CI_BUILD_GROUP="$(id -g -n)"
Expand All @@ -212,7 +231,7 @@ DOCKER_ENV+=( --env CI_BUILD_HOME=/workspace
# Pass tvm test data folder through to the docker container, to avoid
# repeated downloads.
TEST_DATA_PATH="${TVM_DATA_ROOT_PATH:-${HOME}/.tvm_test_data}"
DOCKER_MOUNT+=( --volume "${TEST_DATA_PATH}":/workspace/.tvm_test_data )
DOCKER_MOUNT+=( --volume "${TEST_DATA_PATH}":"${REPO_MOUNT_POINT}"/.tvm_test_data )


# Remove the container once it finishes running (--rm) and share the
Expand Down Expand Up @@ -266,7 +285,7 @@ fi

# Set TVM import path inside the docker image
if [[ "${DOCKER_IMAGE_NAME}" == *"ci"* ]]; then
DOCKER_ENV+=( --env PYTHONPATH=/workspace/python )
DOCKER_ENV+=( --env PYTHONPATH="${REPO_MOUNT_POINT}"/python )
fi


Expand Down

0 comments on commit 98cc6a3

Please sign in to comment.