60 lines
1.7 KiB
Bash
Executable File
60 lines
1.7 KiB
Bash
Executable File
#!/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
|
|
printf "\n*** %s ***\n\n" "$BUILD"
|
|
|
|
BUILD_DIR="profile/$PROFILE/$BUILD"
|
|
|
|
# get version, release, and arch
|
|
eval "$(
|
|
grep -E '"(version|release|arch)"' "$BUILD_DIR/vars.json" | \
|
|
sed -e 's/[ ",]//g' -e 's/:/=/g'
|
|
)"
|
|
|
|
if [ "$version" != 'edge' ]; then
|
|
# get current Alpine release for this version
|
|
alpine_release=$(
|
|
curl -s "http://dl-cdn.alpinelinux.org/alpine/v$version/main/$arch/" | \
|
|
grep '"alpine-base-' | cut -d'"' -f2 | cut -d- -f3
|
|
)
|
|
# update core version profile's release if necessary
|
|
if [ "$alpine_release" != "$release" ]; then
|
|
printf "=== New release (%s) detected! ===\n\n" "$alpine_release"
|
|
sed -i '' -e "s/$release/$alpine_release/" "../profiles/version/$version"
|
|
./resolve-profile.py "$PROFILE"
|
|
# NOTE: this does NOT update 'revision', it's at target profile/build level
|
|
fi
|
|
fi
|
|
|
|
# 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")
|
|
|
|
if [ "$EXIT" -eq 0 ]; then
|
|
./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
|