2015-10-22 11:13:39 +02:00
|
|
|
#!/bin/bash
|
|
|
|
set -e
|
2017-04-27 22:58:43 +02:00
|
|
|
set -o pipefail
|
2015-10-22 11:13:39 +02:00
|
|
|
|
|
|
|
# this is kind of an expensive check, so let's not do this twice if we
|
|
|
|
# are running more than one validate bundlescript
|
2016-09-30 19:47:34 +02:00
|
|
|
VALIDATE_REPO='https://github.com/jessfraz/dockerfiles.git'
|
2015-10-22 11:13:39 +02:00
|
|
|
VALIDATE_BRANCH='master'
|
|
|
|
|
|
|
|
VALIDATE_HEAD="$(git rev-parse --verify HEAD)"
|
|
|
|
|
|
|
|
git fetch -q "$VALIDATE_REPO" "refs/heads/$VALIDATE_BRANCH"
|
|
|
|
VALIDATE_UPSTREAM="$(git rev-parse --verify FETCH_HEAD)"
|
|
|
|
|
|
|
|
VALIDATE_COMMIT_DIFF="$VALIDATE_UPSTREAM...$VALIDATE_HEAD"
|
|
|
|
|
|
|
|
validate_diff() {
|
|
|
|
if [ "$VALIDATE_UPSTREAM" != "$VALIDATE_HEAD" ]; then
|
|
|
|
git diff "$VALIDATE_COMMIT_DIFF" "$@"
|
|
|
|
else
|
|
|
|
git diff HEAD~ "$@"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# get the dockerfiles changed
|
|
|
|
IFS=$'\n'
|
2018-09-25 00:46:13 +02:00
|
|
|
# shellcheck disable=SC2207
|
2015-10-22 11:13:39 +02:00
|
|
|
files=( $(validate_diff --name-only -- '*Dockerfile') )
|
|
|
|
unset IFS
|
|
|
|
|
|
|
|
# build the changed dockerfiles
|
2018-09-25 01:54:24 +02:00
|
|
|
# shellcheck disable=SC2068
|
|
|
|
for f in ${files[@]}; do
|
2016-06-29 01:18:05 +02:00
|
|
|
if ! [[ -e "$f" ]]; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
2018-05-25 18:00:54 +02:00
|
|
|
build_dir=$(dirname "$f")
|
|
|
|
base="${build_dir%%\/*}"
|
|
|
|
suite="${build_dir##$base}"
|
|
|
|
suite="${suite##\/}"
|
2015-10-22 11:13:39 +02:00
|
|
|
|
|
|
|
if [[ -z "$suite" ]]; then
|
|
|
|
suite=latest
|
|
|
|
fi
|
|
|
|
|
|
|
|
(
|
|
|
|
set -x
|
2018-09-25 00:46:13 +02:00
|
|
|
docker build -t "${base}:${suite}" "${build_dir}"
|
2015-10-22 11:13:39 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
echo " --- "
|
|
|
|
echo "Successfully built ${base}:${suite} with context ${build_dir}"
|
|
|
|
echo " --- "
|
|
|
|
done
|