-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.sh
executable file
·317 lines (272 loc) · 8.32 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
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
#!/usr/bin/env bash
# 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.
# Some defaults
# source directory
SOURCEDIR="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
# top-level build directory
BUILD_DIR=$(pwd)/build
# install directory
INSTALL_PREFIX=$(pwd)/output
# Dockerfiles directory
DOCKERFILES_DIR=$(pwd)/dockerfiles
# Build type
BUILD_TYPE=debug
# Use container to build
CTR_BUILD=no
# name for logging
LOG_NAME="vaccel build"
source $SOURCEDIR/scripts/utils.sh
print_build_options() {
info ""
info "Build options:"
info " BUILD_DIR: $BUILD_DIR"
info " INSTALL_PREFIX: $INSTALL_PREFIX"
info " BUILD_TYPE: $BUILD_TYPE"
info ""
}
prepare_build_env() {
mkdir -p $INSTALL_PREFIX/$BUILD_TYPE/{lib,include,share,bin}
mkdir -p $BUILD_DIR/$BUILD_TYPE
}
runctr() {
docker run --rm \
-v $SOURCEDIR:$SOURCEDIR \
-v $BUILD_DIR:$BUILD_DIR \
-v $INSTALL_PREFIX:$INSTALL_PREFIX \
"$@"
}
runctr_vaccel_deps() {
runctr nubificus/vaccel-deps:latest "$@"
}
# Build vAccelRT inside a container
_build_vaccelrt_ctr() {
info "Calling VaccelRT script inside container"
runctr_vaccel_deps $SOURCEDIR/scripts/build_vaccelrt.sh \
--$BUILD_TYPE \
--src_dir $SOURCEDIR/vaccelrt \
--build_dir $BUILD_DIR/$BUILD_TYPE \
--install_prefix $INSTALL_PREFIX/$BUILD_TYPE
ok_or_die "Could not build vaccelrt inside container"
# Fix permissions
runctr_vaccel_deps chown -R "$(id -u):$(id -g)" \
$BUILD_DIR/$BUILD_TYPE/vaccelrt \
$INSTALL_PREFIX/$BUILD_TYPE
ok_or_die "Could not fix permissions for vaccelrt"
}
# Build vAccelRT on host
_build_vaccelrt_host() {
info "Calling VaccelRT script on host"
./scripts/build_vaccelrt.sh \
--build_dir $BUILD_DIR/$BUILD_TYPE \
--install_prefix $INSTALL_PREFIX/$BUILD_TYPE
}
build_vaccelrt() {
[ "$CTR_BUILD" == yes ] && _build_vaccelrt_ctr || _build_vaccelrt_host
}
#Build Firecracker
build_firecracker() {
info "Calling firecracker script"
./scripts/build_firecracker.sh --$BUILD_TYPE --install_prefix $INSTALL_PREFIX/$BUILD_TYPE
ok_or_die "Could not build firecracker"
}
_build_virtio_host() {
info "Calling the virtio-accel build script on host"
./scripts/build_virtio.sh \
--build_dir $BUILD_DIR/$BUILD_TYPE \
--install_prefix $INSTALL_PREFIX/$BUILD_TYPE
ok_or_die "Could not build virtio module"
}
_build_virtio_ctr() {
info "Calling the virtio-accel build script inside container"
runctr kernel-build-container:gcc-7 \
$SOURCEDIR/scripts/build_virtio.sh \
--build_dir $BUILD_DIR/$BUILD_TYPE \
--src_dir $SOURCEDIR/virtio-accel \
--install_prefix $INSTALL_PREFIX/$BUILD_TYPE
ok_or_die "Could not build virtio module and Linux kernel"
runctr kernel-build-container:gcc-7 \
chown -R "$(id -u):$(id -g)" \
$BUILD_DIR/$BUILD_TYPE/virtio-accel \
$INSTALL_PREFIX/$BUILD_TYPE
ok_or_die "Could not fix permissions for virtio module and Linux kernel"
}
build_virtio() {
[ "$CTR_BUILD" == yes ] && _build_virtio_ctr || _build_virtio_host
}
build_tf_plugin() {
info "Calling TensorFlow plugin build script inside container"
runctr nubificus/tensorflow \
$SOURCEDIR/scripts/build_tf_plugin.sh \
--$BUILD_TYPE \
--src_dir $SOURCEDIR/plugins/vaccelrt-plugin-tensorflow \
--build_dir $BUILD_DIR/$BUILD_TYPE \
--install_prefix $INSTALL_PREFIX/$BUILD_TYPE
ok_or_die "Could not build TensorFlow plugin inside container"
# Fix permissions
runctr nubificus/tensorflow \
chown -R "$(id -u):$(id -g)" \
$BUILD_DIR/$BUILD_TYPE/tf-plugin \
$INSTALL_PREFIX/$BUILD_TYPE
ok_or_die "Could not fix permissions for TensorFlow plugin"
}
build_virtio_plugin() {
info "Calling VirtIO plugin build script"
runctr nubificus/vaccel-deps \
$SOURCEDIR/scripts/build_virtio_plugin.sh \
--$BUILD_TYPE \
--src_dir $SOURCEDIR/plugins/vaccelrt-plugin-virtio \
--build_dir $BUILD_DIR/$BUILD_TYPE \
--install_prefix $INSTALL_PREFIX/$BUILD_TYPE
ok_or_die "Could not build VirtIO plugin"
# Fix permissions
runctr nubificus/vaccel-deps \
chown -R "$(id -u):$(id -g)" \
$BUILD_DIR/$BUILD_TYPE/virtio-plugin \
$INSTALL_PREFIX/$BUILD_TYPE
ok_or_die "Could not fix permissions for VirtIO plugin"
}
build_vsock_plugin() {
info "Calling vsock plugin build script"
runctr nubificus/vaccel-deps \
$SOURCEDIR/scripts/build_vsock_plugin.sh \
--$BUILD_TYPE \
--src_dir $SOURCEDIR/plugins/vaccelrt-plugin-vsock \
--build_dir $BUILD_DIR/$BUILD_TYPE \
--install_prefix $INSTALL_PREFIX/$BUILD_TYPE
ok_or_die "Could not build vsock plugin"
# Fix permissions
runctr nubificus/vaccel-deps \
chown -R "$(id -u):$(id -g)" \
$BUILD_DIR/$BUILD_TYPE/vsock-plugin \
$INSTALL_PREFIX/$BUILD_TYPE
ok_or_die "Could not fix permissions for vsock plugin"
}
build_fc_rootfs() {
info "Calling the rootfs build script"
./scripts/build_rootfs.sh \
--install_prefix $INSTALL_PREFIX/$BUILD_TYPE \
--build_dir $BUILD_DIR/$BUILD_TYPE \
--base_image "ubuntu:latest" \
--dockerfiles_path $DOCKERFILES_DIR \
"$@"
ok_or_die "Could not build rootfs"
}
download_models() {
info "Downloading imagenet models"
mkdir -p $INSTALL_PREFIX/$BUILD_TYPE/share/networks
./scripts/download-models.sh NO $INSTALL_PREFIX/$BUILD_TYPE/share/networks
}
build_plugins() {
build_vsock_plugin
build_virtio_plugin
build_tf_plugin
}
build_vaccel_agent() {
info "Building vAccel agent"
./scripts/build_agent.sh \
--$BUILD_TYPE \
--build_dir $BUILD_DIR/$BUILD_TYPE \
--install_prefix $INSTALL_PREFIX/$BUILD_TYPE
}
build_all() {
build_vaccelrt
build_firecracker
build_virtio
build_fc_rootfs all
build_plugins
build_vaccel_agent
download_models
}
build_help() {
echo ""
echo "Vaccel build script"
echo "Usage: $(basename $0) [<args>] <component>"
echo ""
echo "Arguments"
echo " --release|--debug Build release or debug versions. (default:--debug)"
echo " --build_dir The top-level build directory. (default: $(pwd)/build)"
echo " --install_dir The directory to install output binaries. (default: $(pwd)/output)"
echo " -c|--ctr_build Use container to build components, atm vAccelRT"
echo " -h|--help Print this message and exit"
echo ""
echo "Available components to build:"
echo ""
echo " all"
echo " build all Vaccel components"
echo ""
echo " vaccelrt"
echo " build the VaccelRT runtime"
echo ""
echo " firecracker"
echo " build Firecracker"
echo ""
echo " virtio"
echo " build the vaccel-virtio module & corresponding kernel"
echo ""
echo " tf_plugin"
echo " build the TensorFlow plugin"
echo ""
echo " virtio_plugin"
echo " build the VirtIO plugin"
echo ""
echo " vsock_plugin"
echo " build the vsock plugin"
echo ""
echo " plugins"
echo " Build all plugins"
echo ""
echo " fc_rootfs"
echo " build a rootfs image for firecracker"
echo ""
echo " vaccel_agent"
echo " build vAccel agent"
echo ""
echo " imagenet-models"
echo " Download imagenet network models"
echo ""
}
main() {
if [ $# == 0 ]; then
die "Insufficient script arguments. Use \`$0 --help\` for help."
fi
while [ $# -gt 0 ]; do
case "$1" in
-h|--help) { build_help; exit 1; };;
--release) { BUILD_TYPE=release; };;
--debug) { BUILD_TYPE=debug; };;
--build_dir) { BUILD_DIR=$2; shift; };;
--install_dir) { INSTALL_PREFIX=$2; shift; };;
-c|--ctr_build) { CTR_BUILD=yes; };;
-*)
die "Unkown argument: $1. Please use \`$0 help\`."
;;
*)
break;
;;
esac
shift
done
print_build_options
# Make sure that $1 is a valid command
declare -f "build_$1" > /dev/null
ok_or_die "Unkown command: $1. Please use \`$0 help\`."
cmd=build_$1
shift
# Create all the necessary directories
prepare_build_env
# Call the command and pass it the remaining arguments.
# At the moment no arguments are passed in the commands, but keep
# it like this for the future
$cmd "$@"
}
main "$@"