* ADD: initial commit
This commit is contained in:
97
build-all.sh
Executable file
97
build-all.sh
Executable file
@@ -0,0 +1,97 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
set -o pipefail
|
||||
|
||||
SCRIPT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/$(basename "${BASH_SOURCE[0]}")"
|
||||
REPO_URL="${REPO_URL:-uleenucks}"
|
||||
JOBS=${JOBS:-2}
|
||||
DOCKER="$(which docker)"
|
||||
DOCKERFILESPATH="${HOME}/closed/dockerfiles"
|
||||
|
||||
ERRORS="$(pwd)/errors"
|
||||
|
||||
dcleanup(){
|
||||
${DOCKER} rm $(${DOCKER} ps -aq 2>/dev/null) 2>/dev/null
|
||||
${DOCKER} rm -v $(${DOCKER} ps --filter status=exited -q 2>/dev/null) 2>/dev/null
|
||||
${DOCKER} rmi $(${DOCKER} images --filter dangling=true -q 2>/dev/null) 2>/dev/null
|
||||
}
|
||||
|
||||
build_and_push_kaniko(){
|
||||
base=$1
|
||||
suite=$2
|
||||
build_dir=$3
|
||||
|
||||
echo "Building ${REPO_URL}/${base}:${suite} for context ${build_dir}"
|
||||
docker run \
|
||||
-v "${HOME}/config.json:/kaniko/.docker/config.json:ro" \
|
||||
-v "$(pwd)/${build_dir}:/workspace" \
|
||||
gcr.io/kaniko-project/executor:debug \
|
||||
--destination "${REPO_URL}/${base}:${suite}" --force \
|
||||
|| return 1
|
||||
|
||||
# on successful build, push the image
|
||||
echo " --- "
|
||||
echo "Successfully built and pushed ${base}:${suite} with context ${build_dir}"
|
||||
echo " --- "
|
||||
}
|
||||
|
||||
dofile() {
|
||||
f=$1
|
||||
image=${f%Dockerfile}
|
||||
base=${image%%\/*}
|
||||
build_dir=$(dirname "$f")
|
||||
suite=${build_dir##*\/}
|
||||
|
||||
if [[ -z "$suite" ]] || [[ "$suite" == "$base" ]]; then
|
||||
suite=latest
|
||||
fi
|
||||
|
||||
{
|
||||
$SCRIPT build_and_push_kaniko "${base}" "${suite}" "${build_dir}"
|
||||
} || {
|
||||
# add to errors
|
||||
echo "${base}:${suite}" >> "$ERRORS"
|
||||
}
|
||||
echo
|
||||
echo
|
||||
}
|
||||
|
||||
prescript(){
|
||||
cd "${DOCKERFILESPATH}"
|
||||
rm -f errors
|
||||
git pull
|
||||
}
|
||||
|
||||
main(){
|
||||
# get the dockerfiles
|
||||
IFS=$'\n'
|
||||
files=( $(find . -iname '*Dockerfile' | sed 's|./||' | sort) )
|
||||
unset IFS
|
||||
|
||||
# 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
|
||||
}
|
||||
|
||||
prescript
|
||||
run $@
|
||||
dcleanup
|
||||
Reference in New Issue
Block a user