2019-05-28 05:27:55 +00:00
|
|
|
#!/bin/sh
|
|
|
|
# vim: set ts=4 et:
|
|
|
|
|
|
|
|
export PACKER=${PACKER:-packer}
|
|
|
|
|
|
|
|
cd build || exit 1
|
|
|
|
|
|
|
|
# we need a profile, at least
|
|
|
|
if [ $# -eq 0 ]; then
|
|
|
|
echo "Usage: $(basename "$0") <profile> [ <build> ... ]" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
PROFILE=$1; shift
|
|
|
|
|
|
|
|
# no build(s) specified? do all the builds!
|
|
|
|
[ $# -gt 0 ] && BUILDS="$*" || BUILDS=$(ls "profile/$PROFILE")
|
|
|
|
|
|
|
|
for BUILD in $BUILDS
|
|
|
|
do
|
2019-05-31 04:04:11 +00:00
|
|
|
printf "\n*** %s ***\n\n" "$BUILD"
|
2019-05-28 05:27:55 +00:00
|
|
|
BUILD_DIR="profile/$PROFILE/$BUILD"
|
|
|
|
|
|
|
|
# execute packer, capture output and exit code
|
|
|
|
(
|
|
|
|
"$PACKER" build -var-file="$BUILD_DIR/vars.json" packer.json
|
|
|
|
echo $? >"$BUILD_DIR/exit"
|
|
|
|
) | tee "$BUILD_DIR/output"
|
|
|
|
EXIT=$(cat "$BUILD_DIR/exit")
|
|
|
|
|
2019-05-31 04:04:11 +00:00
|
|
|
if [ "$EXIT" -eq 0 ]; then
|
2019-05-28 05:27:55 +00:00
|
|
|
./update-release.py "$PROFILE" "$BUILD"
|
|
|
|
else
|
|
|
|
# unless AMI revision already exists, exit
|
|
|
|
grep -q 'is used by an existing AMI' "$BUILD_DIR/output" || exit "$EXIT"
|
|
|
|
fi
|
|
|
|
done
|