/
build.sh
139 lines (120 loc) · 4.67 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/bin/bash
GIT_DESCRIBE_TAG=`git describe --tags`
MINOR_VERSION=`echo $GIT_DESCRIBE_TAG | grep -o -E '([0-9]+\.[0-9]+)'`
DOCKER_IMAGE="gpuci/rapidsai:${MINOR_VERSION}-cuda10.1-devel-ubuntu16.04-py3.7"
REPO_PATH=${PWD}
RAPIDS_DIR_IN_CONTAINER="/rapids"
CPP_BUILD_DIR="cuML/build"
PYTHON_BUILD_DIR="python/build"
CONTAINER_SHELL_ONLY=0
SHORTHELP="$(basename "$0") [-h] [-H] [-s] [-r <repo_dir>] [-i <image_name>]"
LONGHELP="${SHORTHELP}
Build and test your local repository using a base gpuCI Docker image
where:
-H Show this help text
-r Path to repository (defaults to working directory)
-i Use Docker image (default is ${DOCKER_IMAGE})
-s Skip building and testing and start an interactive shell in a container of the Docker image
"
# Limit GPUs available to container based on CUDA_VISIBLE_DEVICES
if [[ -z "${CUDA_VISIBLE_DEVICES}" ]]; then
NVIDIA_VISIBLE_DEVICES="all"
else
NVIDIA_VISIBLE_DEVICES=${CUDA_VISIBLE_DEVICES}
fi
while getopts ":hHr:i:s" option; do
case ${option} in
r)
REPO_PATH=${OPTARG}
;;
i)
DOCKER_IMAGE=${OPTARG}
;;
s)
CONTAINER_SHELL_ONLY=1
;;
h)
echo "${SHORTHELP}"
exit 0
;;
H)
echo "${LONGHELP}"
exit 0
;;
*)
echo "ERROR: Invalid flag"
echo "${SHORTHELP}"
exit 1
;;
esac
done
REPO_PATH_IN_CONTAINER="${RAPIDS_DIR_IN_CONTAINER}/$(basename "${REPO_PATH}")"
CPP_BUILD_DIR_IN_CONTAINER="${RAPIDS_DIR_IN_CONTAINER}/$(basename "${REPO_PATH}")/${CPP_BUILD_DIR}"
PYTHON_BUILD_DIR_IN_CONTAINER="${RAPIDS_DIR_IN_CONTAINER}/$(basename "${REPO_PATH}")/${PYTHON_BUILD_DIR}"
# BASE_CONTAINER_BUILD_DIR is named after the image name, allowing for
# multiple image builds to coexist on the local filesystem. This will
# be mapped to the typical BUILD_DIR inside of the container. Builds
# running in the container generate build artifacts just as they would
# in a bare-metal environment, and the host filesystem is able to
# maintain the host build in BUILD_DIR as well.
# shellcheck disable=SC2001,SC2005,SC2046
BASE_CONTAINER_BUILD_DIR=${REPO_PATH}/build_$(echo $(basename "${DOCKER_IMAGE}")|sed -e 's/:/_/g')
CPP_CONTAINER_BUILD_DIR=${BASE_CONTAINER_BUILD_DIR}/cpp
PYTHON_CONTAINER_BUILD_DIR=${BASE_CONTAINER_BUILD_DIR}/python
BUILD_SCRIPT="#!/bin/bash
set -e
WORKSPACE=${REPO_PATH_IN_CONTAINER}
PREBUILD_SCRIPT=${REPO_PATH_IN_CONTAINER}/ci/gpu/prebuild.sh
BUILD_SCRIPT=${REPO_PATH_IN_CONTAINER}/ci/gpu/build.sh
cd \${WORKSPACE}
if [ -f \${PREBUILD_SCRIPT} ]; then
source \${PREBUILD_SCRIPT}
fi
yes | source \${BUILD_SCRIPT}
"
if (( CONTAINER_SHELL_ONLY == 0 )); then
COMMAND="${CPP_BUILD_DIR_IN_CONTAINER}/build.sh || bash"
else
COMMAND="bash"
fi
# Create the build dir for the container to mount, generate the build script inside of it
mkdir -p "${BASE_CONTAINER_BUILD_DIR}"
mkdir -p "${CPP_CONTAINER_BUILD_DIR}"
mkdir -p "${PYTHON_CONTAINER_BUILD_DIR}"
# Create build directories. This is to ensure correct owner for directories. If
# directories don't exist there is side effect from docker volume mounting creating build
# directories owned by root(volume mount point(s))
mkdir -p "${REPO_PATH}/${CPP_BUILD_DIR}"
mkdir -p "${REPO_PATH}/${PYTHON_BUILD_DIR}"
echo "${BUILD_SCRIPT}" > "${CPP_CONTAINER_BUILD_DIR}/build.sh"
chmod ugo+x "${CPP_CONTAINER_BUILD_DIR}/build.sh"
PASSWD_FILE="/etc/passwd"
GROUP_FILE="/etc/group"
USER_FOUND=$(grep -wc "$(whoami)" < "$PASSWD_FILE")
if [ "$USER_FOUND" == 0 ]; then
echo "Local User not found, LDAP WAR for docker mounts activated. Creating dummy passwd and group"
echo "files to allow docker resolve username and group"
cp "$PASSWD_FILE" /tmp/passwd
PASSWD_FILE="/tmp/passwd"
cp "$GROUP_FILE" /tmp/group
GROUP_FILE="/tmp/group"
echo "$(whoami):x:$(id -u):$(id -g):$(whoami),,,:$HOME:$SHELL" >> "$PASSWD_FILE"
echo "$(whoami):x:$(id -g):" >> "$GROUP_FILE"
fi
# Run the generated build script in a container
docker pull "${DOCKER_IMAGE}"
DOCKER_MAJOR=$(docker -v|sed 's/[^[0-9]*\([0-9]*\).*/\1/')
GPU_OPTS="--gpus device=${NVIDIA_VISIBLE_DEVICES}"
if [ "$DOCKER_MAJOR" -lt 19 ]
then
GPU_OPTS="--runtime=nvidia -e NVIDIA_VISIBLE_DEVICES='${NVIDIA_VISIBLE_DEVICES}'"
fi
docker run --rm -it ${GPU_OPTS} \
--user "$(id -u)":"$(id -g)" \
-v "${REPO_PATH}:${REPO_PATH_IN_CONTAINER}" \
-v "${CPP_CONTAINER_BUILD_DIR}:${CPP_BUILD_DIR_IN_CONTAINER}" \
-v "${PYTHON_CONTAINER_BUILD_DIR}:${PYTHON_BUILD_DIR_IN_CONTAINER}" \
-v "$PASSWD_FILE":/etc/passwd:ro \
-v "$GROUP_FILE":/etc/group:ro \
--cap-add=SYS_PTRACE \
"${DOCKER_IMAGE}" bash -c "${COMMAND}"