fix(oem/ami): Add support for building release AMIs for amd64-usr

This commit is contained in:
Michael Marineau 2014-03-20 17:28:09 -07:00
parent 26b5865b73
commit a55f566b40
5 changed files with 100 additions and 29 deletions

View File

@ -25,14 +25,18 @@ AKI["sa-east-1"]=aki-c88f51d5
readonly COREOS_EPOCH=1372636800 readonly COREOS_EPOCH=1372636800
VERSION="master" VERSION="master"
BOARD="amd64-generic"
GROUP=""
IMAGE="coreos_production_ami_image.bin.bz2" IMAGE="coreos_production_ami_image.bin.bz2"
URL_FMT="http://storage.core-os.net/coreos/amd64-generic/%s/$IMAGE" URL_FMT="http://storage.core-os.net/coreos/%s/%s/$IMAGE"
IMG_URL="" IMG_URL=""
IMG_PATH="" IMG_PATH=""
USAGE="Usage: $0 [-V 1.2.3] [-p path/image.bz2 | -u http://foo/image.bz2] USAGE="Usage: $0 [-V 1.2.3] [-p path/image.bz2 | -u http://foo/image.bz2]
Options: Options:
-V VERSION Set the version of this AMI, default is 'master' -V VERSION Set the version of this AMI, default is 'master'
-b BOARD Set to the board name, amd64-usr or amd64-generic
-g GROUP Set the update group, default is based on BOARD
-p PATH Path to compressed disk image, overrides -u -p PATH Path to compressed disk image, overrides -u
-u URL URL to compressed disk image, derived from -V if unset. -u URL URL to compressed disk image, derived from -V if unset.
-K KEY Path to Amazon API private key. -K KEY Path to Amazon API private key.
@ -43,10 +47,12 @@ Options:
This script must be run from an ec2 host with the ec2 tools installed. This script must be run from an ec2 host with the ec2 tools installed.
" "
while getopts "V:p:u:K:C:hv" OPTION while getopts "V:b:g:p:u:K:C:hv" OPTION
do do
case $OPTION in case $OPTION in
V) VERSION="$OPTARG";; V) VERSION="$OPTARG";;
b) BOARD="$OPTARG";;
g) GROUP="$OPTARG";;
p) IMG_PATH="$OPTARG";; p) IMG_PATH="$OPTARG";;
u) IMG_URL="$OPTARG";; u) IMG_URL="$OPTARG";;
K) export EC2_PRIVATE_KEY="$OPTARG";; K) export EC2_PRIVATE_KEY="$OPTARG";;
@ -71,7 +77,7 @@ if [[ -n "$IMG_PATH" ]]; then
IMG_URL=$(basename "$IMG_PATH") IMG_URL=$(basename "$IMG_PATH")
else else
if [[ -z "$IMG_URL" ]]; then if [[ -z "$IMG_URL" ]]; then
IMG_URL=$(printf "$URL_FMT" "$VERSION") IMG_URL=$(printf "$URL_FMT" "$BOARD" "$VERSION")
fi fi
if ! curl --fail -s --head "$IMG_URL" >/dev/null; then if ! curl --fail -s --head "$IMG_URL" >/dev/null; then
echo "$0: Image URL unavailable: $IMG_URL" >&2 echo "$0: Image URL unavailable: $IMG_URL" >&2
@ -82,9 +88,19 @@ fi
if [[ "$VERSION" == "master" ]]; then if [[ "$VERSION" == "master" ]]; then
# Come up with something more descriptive and timestamped # Come up with something more descriptive and timestamped
TODAYS_VERSION=$(( (`date +%s` - ${COREOS_EPOCH}) / 86400 )) TODAYS_VERSION=$(( (`date +%s` - ${COREOS_EPOCH}) / 86400 ))
VERSION="master-${TODAYS_VERSION}-$(date +%H-%M)" VERSION="${TODAYS_VERSION}-$(date +%H-%M)"
GROUP="master"
fi fi
if [[ -z "$GROUP" ]]; then
if [[ "$BOARD" == "amd64-generic" ]]; then
GROUP="dev-channel"
elif [[ "$BOARD" == "amd64-usr" ]]; then
GROUP="alpha"
else
GROUP="$BOARD"
fi
fi
# Size of AMI file system # Size of AMI file system
# TODO: Perhaps define size and arch in a metadata file image_to_vm creates? # TODO: Perhaps define size and arch in a metadata file image_to_vm creates?
@ -93,8 +109,8 @@ arch=x86_64
arch2=amd64 arch2=amd64
ephemeraldev=/dev/sdb ephemeraldev=/dev/sdb
# The name has a limited set of allowed characterrs # The name has a limited set of allowed characterrs
name=$(sed -e "s%[^A-Za-z0-9()\\./_-]%_%g" <<< "CoreOS-$VERSION") name=$(sed -e "s%[^A-Za-z0-9()\\./_-]%_%g" <<< "CoreOS-$GROUP-$VERSION")
description="CoreOS $VERSION" description="CoreOS $GROUP $VERSION"
zoneurl=http://instance-data/latest/meta-data/placement/availability-zone zoneurl=http://instance-data/latest/meta-data/placement/availability-zone
zone=$(curl --fail -s $zoneurl) zone=$(curl --fail -s $zoneurl)
@ -179,7 +195,7 @@ ec2-delete-volume "$volumeid"
cat <<EOF cat <<EOF
AMI: $amiid $region $arch2 AMI: $amiid $region $arch2
CoreOS $VERSION $description
architecture: $arch ($arch2) architecture: $arch ($arch2)
region: $region ($zone) region: $region ($zone)
aki id: $akiid aki id: $akiid

View File

@ -26,6 +26,8 @@ AKI["sa-east-1"]=aki-c88f51d5
USAGE="Usage: $0 -a ami-id USAGE="Usage: $0 -a ami-id
-a ami-id ID of the AMI to be coppied. -a ami-id ID of the AMI to be coppied.
-V VERSION Find AMI by CoreOS version. -V VERSION Find AMI by CoreOS version.
-b BOARD Set to the board name, amd64-usr or amd64-generic
-g GROUP Set the update group, default is based on BOARD
-K KEY Path to Amazon API private key. -K KEY Path to Amazon API private key.
-C CERT Path to Amazon API key certificate. -C CERT Path to Amazon API key certificate.
-h this ;-) -h this ;-)
@ -36,12 +38,16 @@ This script must be run from an ec2 host with the ec2 tools installed.
AMI= AMI=
VER= VER=
BOARD="amd64-generic"
GROUP=""
while getopts "a:V:K:C:hv" OPTION while getopts "a:V:b:g:K:C:hv" OPTION
do do
case $OPTION in case $OPTION in
a) AMI="$OPTARG";; a) AMI="$OPTARG";;
V) VER="$OPTARG";; V) VER="$OPTARG";;
b) BOARD="$OPTARG";;
g) GROUP="$OPTARG";;
K) export EC2_PRIVATE_KEY="$OPTARG";; K) export EC2_PRIVATE_KEY="$OPTARG";;
C) export EC2_CERT="$OPTARG";; C) export EC2_CERT="$OPTARG";;
h) echo "$USAGE"; exit;; h) echo "$USAGE"; exit;;
@ -60,11 +66,21 @@ if [[ -z "$VER" ]]; then
exit 1 exit 1
fi fi
if [[ -z "$GROUP" ]]; then
if [[ "$BOARD" == "amd64-generic" ]]; then
GROUP="dev-channel"
elif [[ "$BOARD" == "amd64-usr" ]]; then
GROUP="alpha"
else
GROUP="$BOARD"
fi
fi
if [[ -z "$AMI" ]]; then if [[ -z "$AMI" ]]; then
AMI=$(ec2-describe-images -F name="CoreOS-$VER" | grep -m1 ^IMAGE \ AMI=$(ec2-describe-images -F name="CoreOS-$GROUP-$VER" | grep -m1 ^IMAGE \
| cut -f2) || true # Don't die silently, error messages are good | cut -f2) || true # Don't die silently, error messages are good
if [[ -z "$AMI" ]]; then if [[ -z "$AMI" ]]; then
echo "$0: Cannot find an AMI for CoreOS $VER" >&2 echo "$0: Cannot find an AMI for CoreOS $GROUP $VER" >&2
exit 1 exit 1
fi fi
else else
@ -76,8 +92,8 @@ else
fi fi
# The name has a limited set of allowed characterrs # The name has a limited set of allowed characterrs
name=$(sed -e "s%[^A-Za-z0-9()\\./_-]%_%g" <<< "CoreOS-$VER") name=$(sed -e "s%[^A-Za-z0-9()\\./_-]%_%g" <<< "CoreOS-$GROUP-$VER")
description="CoreOS $VER" description="CoreOS $GROUP $VER"
zoneurl=http://instance-data/latest/meta-data/placement/availability-zone zoneurl=http://instance-data/latest/meta-data/placement/availability-zone
zone=$(curl --fail -s $zoneurl) zone=$(curl --fail -s $zoneurl)

View File

@ -1,15 +1,17 @@
#!/bin/bash #!/bin/bash
VER="$1" BOARD="$1"
VER="$2"
DIR=/home/ubuntu/official DIR=/home/ubuntu/official
if [ -z "$VER" ]; then if [ -z "$BOARD" -o -z "$VER" ]; then
echo "Usage: $0 1.2.3" >&2 echo "Usage: $0 amd64-usr 1.2.3" >&2
exit 1 exit 1
fi fi
set -e set -e
sudo $DIR/build_ebs_on_ec2.sh -V $VER -K $DIR/aws-pk.pem -C $DIR/aws-cert.pem args=( -b $BOARD -V $VER -K $DIR/aws-pk.pem -C $DIR/aws-cert.pem )
$DIR/test_ami.sh -v -V $VER -K $DIR/aws-pk.pem -C $DIR/aws-cert.pem sudo $DIR/build_ebs_on_ec2.sh "${args[@]}"
$DIR/copy_ami.sh -V $VER -K $DIR/aws-pk.pem -C $DIR/aws-cert.pem $DIR/test_ami.sh -v "${args[@]}"
$DIR/upload_ami_txt.sh -V $VER -K $DIR/aws-pk.pem -C $DIR/aws-cert.pem $DIR/copy_ami.sh "${args[@]}"
$DIR/upload_ami_txt.sh "${args[@]}"

View File

@ -14,6 +14,8 @@ set -e -o pipefail
USAGE="Usage: $0 -a ami-id USAGE="Usage: $0 -a ami-id
-a ami-id ID of the AMI to be tests -a ami-id ID of the AMI to be tests
-V VERSION Find AMI by CoreOS version. -V VERSION Find AMI by CoreOS version.
-b BOARD Set to the board name, amd64-usr or amd64-generic
-g GROUP Set the update group, default is based on BOARD
-K KEY Path to Amazon API private key. -K KEY Path to Amazon API private key.
-C CERT Path to Amazon API key certificate. -C CERT Path to Amazon API key certificate.
-h this ;-) -h this ;-)
@ -25,12 +27,16 @@ This script must be run from an ec2 host with the ec2 tools installed.
AMI= AMI=
VER= VER=
BOARD="amd64-generic"
GROUP=""
while getopts "a:V:K:C:hv" OPTION while getopts "a:V:b:g:K:C:hv" OPTION
do do
case $OPTION in case $OPTION in
a) AMI="$OPTARG";; a) AMI="$OPTARG";;
V) VER="$OPTARG";; V) VER="$OPTARG";;
b) BOARD="$OPTARG";;
g) GROUP="$OPTARG";;
K) export EC2_PRIVATE_KEY="$OPTARG";; K) export EC2_PRIVATE_KEY="$OPTARG";;
C) export EC2_CERT="$OPTARG";; C) export EC2_CERT="$OPTARG";;
h) echo "$USAGE"; exit;; h) echo "$USAGE"; exit;;
@ -44,11 +50,21 @@ if [[ $(id -u) -eq 0 ]]; then
exit 1 exit 1
fi fi
if [[ -z "$GROUP" ]]; then
if [[ "$BOARD" == "amd64-generic" ]]; then
GROUP="dev-channel"
elif [[ "$BOARD" == "amd64-usr" ]]; then
GROUP="alpha"
else
GROUP="$BOARD"
fi
fi
if [[ -z "$AMI" && -n "$VER" ]]; then if [[ -z "$AMI" && -n "$VER" ]]; then
AMI=$(ec2-describe-images -F name="CoreOS-$VER" | grep -m1 ^IMAGE \ AMI=$(ec2-describe-images -F name="CoreOS-$GROUP-$VER" | grep -m1 ^IMAGE \
| cut -f2) || true # Don't die silently, error messages are good | cut -f2) || true # Don't die silently, error messages are good
if [[ -z "$AMI" ]]; then if [[ -z "$AMI" ]]; then
echo "$0: Cannot find an AMI for CoreOS $VER" >&2 echo "$0: Cannot find an AMI for CoreOS $GROUP $VER" >&2
exit 1 exit 1
fi fi
elif [[ -n "$AMI" ]]; then elif [[ -n "$AMI" ]]; then
@ -82,10 +98,23 @@ zone=$(curl --fail -s $zoneurl)
region=$(echo $zone | sed 's/.$//') region=$(echo $zone | sed 's/.$//')
token=$(uuidgen) token=$(uuidgen)
if [[ "$BOARD" == "amd64-generic" ]]; then
userdata="$token"
else
discovery=$(curl --fail -s https://discovery.etcd.io/new)
userdata="#cloud-config
coreos:
etcd:
discovery: $discovery
addr: \$private_ipv4:4001
peer-addr: \$private_ipv4:7001
"
fi
echo -n "Booting instances... " echo -n "Booting instances... "
instances=$(ec2-run-instances \ instances=$(ec2-run-instances \
--user-data "$token" \ --user-data "$userdata" \
--instance-type "t1.micro" \ --instance-type "t1.micro" \
--instance-count 3 \ --instance-count 3 \
--group "$sg_name" \ --group "$sg_name" \
@ -140,6 +169,7 @@ ec2-terminate-instances $instances > /dev/null
while ! $ec2_cmd | grep INSTANCE | grep -q terminated while ! $ec2_cmd | grep INSTANCE | grep -q terminated
do sleep 10; done do sleep 10; done
sleep 10
ec2-delete-group $sg_name > /dev/null ec2-delete-group $sg_name > /dev/null
ec2-delete-keypair $key_name > /dev/null ec2-delete-keypair $key_name > /dev/null
rm $key_file rm $key_file

View File

@ -18,6 +18,8 @@ AKI["sa-east-1"]=aki-c88f51d5
USAGE="Usage: $0 -V 100.0.0 USAGE="Usage: $0 -V 100.0.0
-V VERSION Find AMI by CoreOS version. (required) -V VERSION Find AMI by CoreOS version. (required)
-b BOARD Set to the board name, amd64-usr or amd64-generic
-g GROUP Set the update group, default is based on BOARD
-K KEY Path to Amazon API private key. -K KEY Path to Amazon API private key.
-C CERT Path to Amazon API key certificate. -C CERT Path to Amazon API key certificate.
-h this ;-) -h this ;-)
@ -27,14 +29,18 @@ This script must be run from an ec2 host with the ec2 tools installed.
" "
IMAGE="coreos_production_ami" IMAGE="coreos_production_ami"
URL_FMT="gs://storage.core-os.net/coreos/amd64-generic/%s/${IMAGE}_%s.txt" URL_FMT="gs://storage.core-os.net/coreos/%s/%s/${IMAGE}_%s.txt"
AMI= AMI=
VER= VER=
BOARD="amd64-generic"
GROUP=""
while getopts "a:V:K:C:hv" OPTION while getopts "V:b:g:K:C:hv" OPTION
do do
case $OPTION in case $OPTION in
V) VER="$OPTARG";; V) VER="$OPTARG";;
b) BOARD="$OPTARG";;
g) GROUP="$OPTARG";;
K) export EC2_PRIVATE_KEY="$OPTARG";; K) export EC2_PRIVATE_KEY="$OPTARG";;
C) export EC2_CERT="$OPTARG";; C) export EC2_CERT="$OPTARG";;
h) echo "$USAGE"; exit;; h) echo "$USAGE"; exit;;
@ -56,10 +62,11 @@ fi
declare -A AMIS declare -A AMIS
for r in "${!AKI[@]}"; do for r in "${!AKI[@]}"; do
AMI=$(ec2-describe-images --region=${r} -F name="CoreOS-$VER" | grep -m1 ^IMAGE \ AMI=$(ec2-describe-images --region=${r} -F name="CoreOS-$GROUP-$VER" \
| grep -m1 ^IMAGE \
| cut -f2) || true # Don't die silently, error messages are good | cut -f2) || true # Don't die silently, error messages are good
if [[ -z "$AMI" ]]; then if [[ -z "$AMI" ]]; then
echo "$0: Cannot find ${r} AMI for CoreOS $VER" >&2 echo "$0: Cannot find ${r} AMI for CoreOS $GROUP $VER" >&2
continue continue
fi fi
AMIS[${r}]=$AMI AMIS[${r}]=$AMI
@ -67,7 +74,7 @@ done
OUT= OUT=
for r in "${!AMIS[@]}"; do for r in "${!AMIS[@]}"; do
url=$(printf "$URL_FMT" "$VER" "$r") url=$(printf "$URL_FMT" "$BOARD" "$VER" "$r")
tmp=$(mktemp --suffix=.txt) tmp=$(mktemp --suffix=.txt)
trap "rm -f '$tmp'" EXIT trap "rm -f '$tmp'" EXIT
echo "${AMIS[$r]}" > "$tmp" echo "${AMIS[$r]}" > "$tmp"
@ -79,7 +86,7 @@ for r in "${!AMIS[@]}"; do
OUT="${OUT}|${r}=${AMIS[$r]}" OUT="${OUT}|${r}=${AMIS[$r]}"
fi fi
done done
url=$(printf "$URL_FMT" "$VER" "all") url=$(printf "$URL_FMT" "$BOARD" "$VER" "all")
tmp=$(mktemp --suffix=.txt) tmp=$(mktemp --suffix=.txt)
trap "rm -f '$tmp'" EXIT trap "rm -f '$tmp'" EXIT
echo "$OUT" > "$tmp" echo "$OUT" > "$tmp"