2021-05-25 17:47:39 +00:00
|
|
|
#!/usr/bin/env bash
|
2021-01-12 18:32:49 +00:00
|
|
|
|
2021-01-26 14:11:37 +00:00
|
|
|
set -u
|
2021-01-12 18:32:49 +00:00
|
|
|
set -e
|
|
|
|
|
|
|
|
usage() {
|
|
|
|
cat <<EOF
|
|
|
|
Usage: build <target>
|
|
|
|
|
|
|
|
Build an AMI for the target configuration
|
|
|
|
|
|
|
|
Examples
|
2022-11-16 16:37:18 +00:00
|
|
|
build ubuntu-jammy-amd64
|
2021-01-12 18:32:49 +00:00
|
|
|
|
|
|
|
EOF
|
|
|
|
|
|
|
|
exit 2
|
|
|
|
}
|
|
|
|
|
|
|
|
if [[ $# -ne 1 ]]; then
|
|
|
|
usage
|
|
|
|
fi
|
|
|
|
|
2021-01-26 14:11:37 +00:00
|
|
|
target="${1/%.pkr.hcl/}"
|
2021-01-12 18:32:49 +00:00
|
|
|
|
2021-01-26 14:11:37 +00:00
|
|
|
directory="$(dirname "$0")"
|
|
|
|
cd "${directory}"
|
2021-01-12 18:32:49 +00:00
|
|
|
|
|
|
|
if ! test -f "${target}.pkr.hcl"; then
|
|
|
|
echo "${target}.pkr.hcl is not present" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-01-26 14:11:37 +00:00
|
|
|
sha=$(git log -n 1 --pretty=format:%H "${directory}")
|
|
|
|
echo packer build --var "build_sha=${sha}" "${target}.pkr.hcl"
|
|
|
|
packer build --var "build_sha=${sha}" "${target}.pkr.hcl"
|