forked from ufora/ufora
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake.sh
More file actions
executable file
·173 lines (148 loc) · 5.54 KB
/
make.sh
File metadata and controls
executable file
·173 lines (148 loc) · 5.54 KB
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/bin/bash
# Copyright 2015 Ufora Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Builds and packages Ufora
###########################
#
# Parameters:
# clean - clean all prior build artifacts
# build - configure and build ufora binaries
# package - build a ufora distribution package
#
# If no parameter is specified, the script runs all commands.
#
# Environment Variables:
# BUILD_COMMIT - The full git commitish of the commit being built.
# Used to name the distribution packagee.
# Only required with the 'package' command.
# OUTPUT_DIR - Directory in which the built distribution package is created.
# Only required with the 'package' command.
# CCACHE_DIR - [optional] Location of ccache directory
##########################################################
docker="docker"
nvidia-smi
if [ $? -eq 0 ]; then
docker="nvidia-docker"
fi
dockerfile_hash=`md5sum docker/build/Dockerfile`
if [ $? -ne 0 ]; then
echo "Unable to hash Dockerfile. Aborting."
exit 1
fi
dockerfile_hash=`echo $dockerfile_hash | awk '{print $1}'`
docker_image="ufora/build:$dockerfile_hash"
$docker pull $docker_image
if [ $? -ne 0 ]; then
echo "Failed to pull docker image $docker_image. Building new image."
$docker build -t $docker_image docker/build
if [ $? -ne 0 ]; then
echo "ERROR: Failed to build docker image. Exiting."
exit 1
fi
$docker push $docker_image
fi
clean_command="rm -rf .waf-*-* ; ./waf clean > /dev/null ; rm -rf .build > /dev/null"
reset_axioms_command="PYTHONPATH=/volumes/src ufora/scripts/resetAxiomSearchFunction.py"
rebuild_axioms_command="PYTHONPATH=/volumes/src ufora/scripts/rebuildAxiomSearchFunction.py"
configure_command="CC=clang-3.5 CXX=clang++-3.5 ./waf configure"
build_once_command="CC=clang-3.5 CXX=clang++-3.5 ./waf install"
build_command="$reset_axioms_command; $configure_command; $build_once_command; $rebuild_axioms_command; $build_once_command"
package_command="PYTHONPATH=/volumes/src ufora/scripts/package/create-package.sh -d /volumes/output -v $BUILD_COMMIT"
command_to_run=""
while (( "$#" )); do
if [[ "$1" == "clean" ]]; then
if [[ -z "$command_to_run" ]]; then
command_to_run=$clean_command
else
command_to_run="$command_to_run ; $clean_command"
fi
elif [[ "$1" == "build" ]]; then
if [[ -z "$command_to_run" ]]; then
command_to_run=$build_command
else
command_to_run="$command_to_run ; $build_command"
fi
elif [[ "$1" == "package" ]]; then
if [[ -z "$command_to_run" ]]; then
command_to_run=$package_command
else
command_to_run="$command_to_run ; $package_command"
fi
elif [[ "$1" == "test" ]]; then
shift
if [[ -z "$command_to_run" ]]; then
command_to_run=$*
else
command_to_run="$command_to_run ; $*"
fi
break
else
echo "ERROR: Invalid command '$1'."
exit 1
fi
shift
done
if [[ -z "$command_to_run" ]]; then
echo "Running default command - clean, build and package"
command_to_run="$clean_command ; $build_command && $package_command"
fi
echo "Running command: $command_to_run"
repo_dir=$(cd $(dirname "$0"); pwd) # make.sh is at the root of the repo
echo "OUTPUT_DIR: $OUTPUT_DIR"
src_volume="--volume $repo_dir:/volumes/src"
if [ ! -z $OUTPUT_DIR ]; then
container_output_path="/volumes/output/"
output_volume="--volume $OUTPUT_DIR:$container_output_path"
fi
if [ ! -z $CCACHE_DIR ]; then
ccache_volume="--volume $CCACHE_DIR:/volumes/ccache"
fi
container_env="--env UFORA_PERFORMANCE_TEST_RESULTS_FILE=$container_output_path$UFORA_PERFORMANCE_TEST_RESULTS_FILE \
--env AWS_AVAILABILITY_ZONE=$AWS_AVAILABILITY_ZONE \
--env TEST_LOOPER_TEST_ID=$TEST_LOOPER_TEST_ID \
--env TEST_LOOPER_MULTIBOX_IP_LIST=${TEST_LOOPER_MULTIBOX_IP_LIST// /,} \
--env TEST_LOOPER_MULTIBOX_OWN_IP=$TEST_LOOPER_MULTIBOX_OWN_IP \
--env TEST_OUTPUT_DIR=/volumes/output \
--env CORE_DUMP_DIR=$CORE_DUMP_DIR \
--env REVISION=$REVISION"
container_name=`uuidgen`
container_options='--ulimit="core=-1"'
if [ ! -z "$TEST_LOOPER_MULTIBOX_IP_LIST" ]; then
network_settings="--net=host"
fi
function cleanup {
$docker stop $container_name &> /dev/null
$docker rm $container_name &> /dev/null
}
# Ensure the container is not left running
trap cleanup EXIT
echo "Current docker containters:"
$docker ps -a
echo
echo $docker run --rm --name=$container_name --privileged=true \
$container_env \
$container_options \
$network_settings \
$src_volume \
$output_volume \
$ccache_volume \
$docker_image bash -c "cd /volumes/src; $command_to_run"
$docker run --rm --name=$container_name --privileged=true \
$container_env \
$container_options \
$network_settings \
$src_volume \
$output_volume \
$ccache_volume \
$docker_image bash -c "cd /volumes/src; $command_to_run"