-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathbuild.sh
executable file
·62 lines (51 loc) · 1.29 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
#!/bin/bash
LOG_DIR=./logs
LOG_FILE=${LOG_DIR}/docker-build.log
[ -d "$LOG_DIR" ] || mkdir -p $LOG_DIR
usage() {
echo `basename $0`: ERROR: $* 1>&2
cat 2>&1 <<EOF
usage: `basename $0` [--image-list|-f filename]
EOF
exit 1
}
die() {
# display an error message ($1) and exit with a return code ($2)
echo `basename $0`: ERROR: $1 1>&2
exit $2
}
os=$(uname -s)
if [ "$os" = "Darwin" ]; then
OPTS=`getopt nf: $*`
else
OPTS=`getopt -o nf: -l image-list:,no-cache -- "$@"`
fi
if [ $? != 0 ]
then
exit 1
fi
eval set -- "$OPTS"
# default values
imagelist=images.lst cache=
while true ; do
case "$1" in
--image-list|-f) imagelist=$2; shift 2;;
--no-cache|-n) cache=--no-cache; shift 1;;
--) shift; break;;
esac
done
[ -z "$imagelist" ] && die "No image list." 1
[ -r "$imagelist" ] || die "file ${imagelist} not found." 1
touch $LOG_DIR/build-start
touch ${LOG_FILE}
for img in $(cat ${imagelist}); do
if [[ "$img" == "#"* ]]; then
echo "${img#\#} skipped"
else
echo "Building $img..."
[ -w ${LOG_FILE} ] && logger -s "Starting build. Image: $img..." 2>> ${LOG_FILE}
docker build $cache -t $img $img/ 2>&1 | tee ${LOG_DIR}/docker-build-$img.log
[ -w ${LOG_FILE} ] && logger -s "Done. Image: $img..." 2>> ${LOG_FILE}
fi
done
touch $LOG_DIR/build-end