-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-all.sh
More file actions
executable file
·86 lines (70 loc) · 1.63 KB
/
build-all.sh
File metadata and controls
executable file
·86 lines (70 loc) · 1.63 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
#!/bin/bash
set -e
set -o pipefail
BASE_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
SCRIPT="${BASE_DIR}/$(basename "${BASH_SOURCE[0]}")"
REPO_URL="${REPO_URL:-yokogawa}"
JOBS=${JOBS:-2}
ERRORS="${BASE_DIR}/.errors"
IGNORE="${BASE_DIR}/ignore"
cd ${BASE_DIR}
build(){
base=$1
suite=$2
build_dir=$3
echo "Building ${REPO_URL}/${base}:${suite} for context ${build_dir}"
docker build --rm --force-rm -t ${REPO_URL}/${base}:${suite} ${build_dir} || return 1
}
dofile() {
f=$1
image=${f%Dockerfile}
base=${image%%\/*}
build_dir=$(dirname ${f})
suite=${build_dir##*\/}
skip=0
if [[ -f ${IGNORE} ]]; then
if echo ${base} | grep -f ${IGNORE} >/dev/null; then
skip=1
fi
fi
if [[ -z "${suite}" ]] || [[ "${suite}" == "${base}" ]]; then
image_name=${base}
else
image_name=${base}-${suite}
fi
if [[ ${skip} -eq 0 ]]; then
{
$SCRIPT build "${image_name}" latest "${build_dir}"
} || {
echo "${image_name}:latest" >> ${ERRORS}
}
echo
echo
else
echo "${base} is skipped (${IGNORE})"
fi
}
main(){
# get the dockerfiles
readarray -t files < <(find . -iname '*Dockerfile' | sed 's|./||' | sort)
# build all dockerfiles
echo "Running in parallel with ${JOBS} jobs."
parallel --tag --verbose --ungroup -j"${JOBS}" ${SCRIPT} dofile "{1}" ::: "${files[@]}"
if [[ ! -f ${ERRORS} ]]; then
echo "No errors, hooray!"
else
echo "[ERROR] Some images did not build correctly, see below." >&2
echo "These images failed: $(cat ${ERRORS})" >&2
exit 1
fi
}
run(){
args=$@
f=$1
if [[ "$f" == "" ]]; then
main $args
else
$args
fi
}
run $@