forked from crops/yocto-dockerfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildall.sh
executable file
·89 lines (72 loc) · 2.18 KB
/
buildall.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
#!/bin/bash
# Copyright (C) 2016 Intel Corporation
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
PIDS=()
trap cleanup SIGINT SIGTERM ERR
function cleanup () {
# Since we're calling kill again on the entire process group make sure
# to not recurse into cleanup() by disabling the trap on SIGTERM.
trap - SIGTERM
kill -- -$$
exit 1
}
function build_images {
PIDS=()
localrepo=$2
tmpdir=$(mktemp --tmpdir -d tmp-buildall.XXX)
echo "Building in $tmpdir"
for i in $1; do
IMAGETAG=$(basename $i)
CONTEXTDIR=$tmpdir/$IMAGETAG
mkdir $CONTEXTDIR
cd $CONTEXTDIR
# Replace the rewitt/yocto repo with the newly one meant for testing
cp $i/Dockerfile .
sed -i -e "s#rewitt/yocto#$2#" Dockerfile
echo "Building $localrepo:$IMAGETAG"
bash -c "docker build --force-rm -t $localrepo:$IMAGETAG . > \
build.log || \
echo \"$IMAGETAG build failed\" \
tail -f build.log \
echo -e \"\n\n\"" &
PIDS=( ${PIDS[@]} $! )
cd -
done
}
function waitforimages {
numpids=${#PIDS[@]}
while [ $numpids -gt 0 ]; do
echo "waiting for $numpids images to be built"
wait -n
if [ $? -ne 0 ]; then
cleanup
fi
numpids=$((numpids-1))
done
}
set -e
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd $SCRIPTDIR
if [ "x" = "x$REPO" ]; then
# Create a uid for the repo so we don't overwrite any user images
REPO=$(uuidgen)-yocto-docker-test
fi
# Build the "base" images first
DIRS=$(readlink -f $(dirname $(find -path '*base/Dockerfile')))
build_images "$DIRS" $REPO
waitforimages
DIRS=$(readlink -f $(dirname $(find -path '*builder/Dockerfile')))
build_images "$DIRS" $REPO
waitforimages