Skip to content

Instantly share code, notes, and snippets.

@boltronics
Last active December 18, 2015 15:19
Show Gist options
  • Save boltronics/5803691 to your computer and use it in GitHub Desktop.
Save boltronics/5803691 to your computer and use it in GitHub Desktop.
Create Debian GNU/Linux instance-store-backed AMIs with minimum pain. Built Wheezy images well tested. Actual building (execution of this script) also tested on a Wheezy instance.
#!/bin/bash
###### Description
#
# This script creates an instance-backed instance.
#
# Please excuse the lack of error checking for now.
###### Variables
#
# Useful to declare up front for use in other variables:
declare -r build_date="$(date --utc +%Y%m%d%H%M)"
# Change these as required:
declare -r ami_description="Debian 7 (Wheezy) built ${build_date}"
declare -r ami_codename="wheezy"
declare -r ami_suffix="${build_date}"
declare -r ami_arch="amd64"
declare -ri ami_size_in_gb=8
declare -r build_charmap="UTF-8"
declare -r build_locale="en_AU"
declare -r build_timezone="Australia/Melbourne"
declare -r build_filesystem="ext4"
###### Code
# Nothing beyond this point should require touching.
#
declare var
declare repo
declare repo_dirname
declare -r build_deps="ca-certificates euca2ools git"
if [ ${UID} -ne 0 ]
then
echo "Error: You must be root." 1>&2
exit 1
fi
for var in EC2_ACCESS_KEY \
EC2_SECRET_KEY \
EC2_PRIVATE_KEY \
EC2_CERT \
EC2_USER_ID \
EUCALYPTUS_CERT \
S3_BUCKET
do
if [ -z "${!var}" ]
then
echo "Error: Environment variable \$${var} not set." 1>&2
exit 1
fi
done
apt-get update
apt-get -y install ${build_deps}
for repo in \
https://github.com/andsens/build-debian-cloud.git \
https://github.com/sitepoint/build-debian-cloud.git
do
repo_dirname="$(echo ${repo} | \
sed -e 's/https\?:\/\/github\.com\/\(.*\)\/\(.*\)\.git$/\1-\2/')"
# Don't do anything if these cloned repos already exist,
# in case the user has been hacking away on them.
if [ ! -d "${repo_dirname}" ]
then
if [ "${repo_dirname}" = "sitepoint-build-debian-cloud" ]
then
git clone -b instance-store-ami-plugin "${repo}" "${repo_dirname}"
else
git clone "${repo}" "${repo_dirname}"
fi
fi
done
cd ./andsens-build-debian-cloud
./build-debian-cloud ec2 \
--arch "${ami_arch}" \
--codename "${ami_codename}" \
--filesystem "${build_filesystem}" \
--volume-size "${ami_size_in_gb}" \
--plugin plugins/standard-packages \
--plugin ../sitepoint-build-debian-cloud/plugins/instance-store-ami \
--timezone "${build_timezone}" \
--locale "${build_locale}"\
--charmap "${build_charmap}" \
--name "${ami_suffix}" \
--description "${ami_description}"
@boltronics
Copy link
Author

Looking at the git history, it seems that I can't decide if euca2ools is a build dependency or not. The answer is that it certainly is a dependency, however I vaguely recall that the version in Squeeze is too old. I'm happy to only support Wheezy now though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment