forked from nasa/harmony
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-service-images
executable file
·87 lines (74 loc) · 1.32 KB
/
build-service-images
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
#!/bin/bash
set -e
SELF=$(basename $0)
function usage
{
echo "Usage: $SELF [-p|--parallel -h] [service_name ...]"
echo "Builds the images for all listed service names that have matching sub-directories in the 'services' directory."
echo "Builds all images if none are listed."
echo ""
echo "-p - run builds in parallel"
echo "-h - print this message"
}
function wait_for_pids {
pids=$1
for pid in "${pids[@]}"; do
wait "$pid"
done
}
PARALLEL=0
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-p|--parallel)
PARALLEL=1
shift
;;
-h|--help)
usage
exit 0
;;
*)
break
;;
esac
done
# build all the image in the 'services' directory
function build_all {
parallel=$1
pids=()
for dir in services/*; do
pushd "$dir"
if [[ $parallel -eq 1 ]]; then
./bin/build-image &
pids+=($!)
else
./bin/build-image
fi
popd
done
if [[ $parallel -eq 1 ]]; then
wait_for_pids $pids
fi
}
if [[ "$#" -eq 0 ]]; then
build_all $PARALLEL
else
pids=()
for f in "$@"; do
pushd "services/${f}"
if [[ $PARALLEL -eq 1 ]]; then
echo "BUILDING ${f} IN PARALLEL"
./bin/build-image &
pids+=($!)
else
echo "BUILDING ${f} IN SERIES"
./bin/build-image
fi
popd
done
if [[ $PARALLEL -eq 1 ]]; then
wait_for_pids $pids
fi
fi