Signed-off-by: Jess Frazelle <acidburn@google.com>
This commit is contained in:
Jess Frazelle 2017-01-11 20:02:41 -08:00
parent 70dd5abcd8
commit 6b5e3e4b8a
No known key found for this signature in database
GPG Key ID: 18F3685C0022BFF3

View File

@ -3,6 +3,8 @@ set -e
set -o pipefail set -o pipefail
REPO_URL="${REPO_URL:-r.j3ss.co}" REPO_URL="${REPO_URL:-r.j3ss.co}"
JOBS=${JOBS:-2}
export REPO_URL
build_and_push(){ build_and_push(){
base=$1 base=$1
@ -33,6 +35,29 @@ build_and_push(){
docker push --disable-content-trust=false ${REPO_URL}/${base}:latest docker push --disable-content-trust=false ${REPO_URL}/${base}:latest
fi fi
} }
export -f build_and_push
dofile() {
f=$1
image=${f%Dockerfile}
base=${image%%\/*}
build_dir=$(dirname $f)
suite=${build_dir##*\/}
if [[ -z "$suite" ]] || [[ "$suite" == "$base" ]]; then
suite=latest
fi
{
build_and_push "${base}" "${suite}" "${build_dir}"
} || {
# add to errors
export ERRORS="${ERRORS} ${base}:${suite} "
}
echo
echo
}
export -f dofile
main(){ main(){
# get the dockerfiles # get the dockerfiles
@ -40,35 +65,18 @@ main(){
files=( $(find . -iname '*Dockerfile' | sed 's|./||' | sort) ) files=( $(find . -iname '*Dockerfile' | sed 's|./||' | sort) )
unset IFS unset IFS
ERRORS=() export ERRORS=""
# build all dockerfiles # build all dockerfiles
for f in "${files[@]}"; do echo "Running in parallel with ${JOBS} jobs."
image=${f%Dockerfile} parallel -j"${JOBS}" dofile "{1}" ::: "${files[@]}"
base=${image%%\/*}
build_dir=$(dirname $f)
suite=${build_dir##*\/}
if [[ -z "$suite" ]] || [[ "$suite" == "$base" ]]; then if [[ "$ERRORS" == "" ]]; then
suite=latest echo "No errors, hooray!"
fi else
echo "[ERROR] Some images did not build correctly, see below." >&2
{ echo "These images failed: ${ERRORS[@]}" >&2
build_and_push "${base}" "${suite}" "${build_dir}" exit 1
} || { fi
# add to errors
ERRORS+=("${base}:${suite}")
}
echo
echo
done
if [ ${#ERRORS[@]} -eq 0 ]; then
echo "No errors, hooray!"
else
echo "[ERROR] Some images did not build correctly, see below." >&2
echo "These images failed: ${ERRORS[@]}" >&2
exit 1
fi
} }
main $@ main $@