2016-01-29 18:41:08 +01:00
|
|
|
#!/bin/bash
|
|
|
|
set -e
|
2016-09-21 03:41:21 +02:00
|
|
|
set -o pipefail
|
|
|
|
|
2017-01-12 06:40:35 +01:00
|
|
|
SCRIPT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/$(basename "${BASH_SOURCE[0]}")"
|
2016-09-21 03:41:21 +02:00
|
|
|
REPO_URL="${REPO_URL:-r.j3ss.co}"
|
2017-01-16 04:30:54 +01:00
|
|
|
JOBS=${JOBS:-2}
|
2016-01-29 18:41:08 +01:00
|
|
|
|
2017-01-12 06:45:25 +01:00
|
|
|
ERRORS="$(pwd)/errors"
|
|
|
|
|
2016-07-04 18:46:27 +02:00
|
|
|
build_and_push(){
|
|
|
|
base=$1
|
|
|
|
suite=$2
|
|
|
|
build_dir=$3
|
2016-05-16 04:18:36 +02:00
|
|
|
|
2016-09-21 03:41:21 +02:00
|
|
|
echo "Building ${REPO_URL}/${base}:${suite} for context ${build_dir}"
|
|
|
|
docker build --rm --force-rm -t ${REPO_URL}/${base}:${suite} ${build_dir} || return 1
|
2016-01-29 18:41:08 +01:00
|
|
|
|
2016-08-12 00:43:41 +02:00
|
|
|
# on successful build, push the image
|
2016-01-29 18:41:08 +01:00
|
|
|
echo " --- "
|
|
|
|
echo "Successfully built ${base}:${suite} with context ${build_dir}"
|
|
|
|
echo " --- "
|
|
|
|
|
2016-06-08 21:46:38 +02:00
|
|
|
# try push a few times because notary server sometimes returns 401 for
|
|
|
|
# absolutely no reason
|
|
|
|
n=0
|
|
|
|
until [ $n -ge 5 ]; do
|
2016-09-21 03:41:21 +02:00
|
|
|
docker push --disable-content-trust=false ${REPO_URL}/${base}:${suite} && break
|
2016-06-08 21:46:38 +02:00
|
|
|
echo "Try #$n failed... sleeping for 15 seconds"
|
|
|
|
n=$[$n+1]
|
|
|
|
sleep 15
|
|
|
|
done
|
2016-01-29 20:47:10 +01:00
|
|
|
|
2018-01-01 16:09:03 +01:00
|
|
|
# also push the tag latest for "stable" (chrome) or "3.5" tags for zookeeper
|
|
|
|
if [[ "$suite" == "stable" ]] || [[ "$suite" == "3.5" ]]; then
|
2016-09-21 03:41:21 +02:00
|
|
|
docker tag ${REPO_URL}/${base}:${suite} ${REPO_URL}/${base}:latest
|
|
|
|
docker push --disable-content-trust=false ${REPO_URL}/${base}:latest
|
2016-01-29 20:47:10 +01:00
|
|
|
fi
|
2016-07-04 18:46:27 +02:00
|
|
|
}
|
2017-01-12 05:02:41 +01:00
|
|
|
|
|
|
|
dofile() {
|
|
|
|
f=$1
|
|
|
|
image=${f%Dockerfile}
|
|
|
|
base=${image%%\/*}
|
|
|
|
build_dir=$(dirname $f)
|
|
|
|
suite=${build_dir##*\/}
|
|
|
|
|
|
|
|
if [[ -z "$suite" ]] || [[ "$suite" == "$base" ]]; then
|
|
|
|
suite=latest
|
|
|
|
fi
|
|
|
|
|
|
|
|
{
|
2017-01-12 06:40:35 +01:00
|
|
|
$SCRIPT build_and_push "${base}" "${suite}" "${build_dir}"
|
2017-01-12 05:02:41 +01:00
|
|
|
} || {
|
|
|
|
# add to errors
|
2017-01-14 23:05:40 +01:00
|
|
|
echo "${base}:${suite}" >> $ERRORS
|
2017-01-12 05:02:41 +01:00
|
|
|
}
|
|
|
|
echo
|
|
|
|
echo
|
|
|
|
}
|
2016-07-04 18:46:27 +02:00
|
|
|
|
|
|
|
main(){
|
|
|
|
# get the dockerfiles
|
|
|
|
IFS=$'\n'
|
2016-09-21 03:41:21 +02:00
|
|
|
files=( $(find . -iname '*Dockerfile' | sed 's|./||' | sort) )
|
2016-07-04 18:46:27 +02:00
|
|
|
unset IFS
|
|
|
|
|
|
|
|
# build all dockerfiles
|
2017-01-12 05:02:41 +01:00
|
|
|
echo "Running in parallel with ${JOBS} jobs."
|
2017-01-12 06:40:35 +01:00
|
|
|
parallel --tag --verbose --ungroup -j"${JOBS}" $SCRIPT dofile "{1}" ::: "${files[@]}"
|
2016-07-04 18:46:27 +02:00
|
|
|
|
2017-01-12 06:40:35 +01:00
|
|
|
if [[ ! -f $ERRORS ]]; then
|
2017-01-12 05:02:41 +01:00
|
|
|
echo "No errors, hooray!"
|
|
|
|
else
|
|
|
|
echo "[ERROR] Some images did not build correctly, see below." >&2
|
2017-01-12 06:40:35 +01:00
|
|
|
echo "These images failed: $(cat $ERRORS)" >&2
|
2017-01-12 05:02:41 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
2016-07-04 18:46:27 +02:00
|
|
|
}
|
|
|
|
|
2017-01-12 06:40:35 +01:00
|
|
|
run(){
|
|
|
|
args=$@
|
|
|
|
f=$1
|
|
|
|
|
|
|
|
if [[ "$f" == "" ]]; then
|
|
|
|
main $args
|
|
|
|
else
|
|
|
|
$args
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
run $@
|