diff --git a/oem/ami/build_ebs_on_ec2.sh b/oem/ami/build_ebs_on_ec2.sh index e8af97b577..d86e459e5c 100755 --- a/oem/ami/build_ebs_on_ec2.sh +++ b/oem/ami/build_ebs_on_ec2.sh @@ -25,14 +25,18 @@ AKI["sa-east-1"]=aki-c88f51d5 readonly COREOS_EPOCH=1372636800 VERSION="master" +BOARD="amd64-generic" +GROUP="" 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_PATH="" USAGE="Usage: $0 [-V 1.2.3] [-p path/image.bz2 | -u http://foo/image.bz2] Options: -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 -u URL URL to compressed disk image, derived from -V if unset. -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. " -while getopts "V:p:u:K:C:hv" OPTION +while getopts "V:b:g:p:u:K:C:hv" OPTION do case $OPTION in V) VERSION="$OPTARG";; + b) BOARD="$OPTARG";; + g) GROUP="$OPTARG";; p) IMG_PATH="$OPTARG";; u) IMG_URL="$OPTARG";; K) export EC2_PRIVATE_KEY="$OPTARG";; @@ -71,7 +77,7 @@ if [[ -n "$IMG_PATH" ]]; then IMG_URL=$(basename "$IMG_PATH") else if [[ -z "$IMG_URL" ]]; then - IMG_URL=$(printf "$URL_FMT" "$VERSION") + IMG_URL=$(printf "$URL_FMT" "$BOARD" "$VERSION") fi if ! curl --fail -s --head "$IMG_URL" >/dev/null; then echo "$0: Image URL unavailable: $IMG_URL" >&2 @@ -82,9 +88,19 @@ fi if [[ "$VERSION" == "master" ]]; then # Come up with something more descriptive and timestamped TODAYS_VERSION=$(( (`date +%s` - ${COREOS_EPOCH}) / 86400 )) - VERSION="master-${TODAYS_VERSION}-$(date +%H-%M)" + VERSION="${TODAYS_VERSION}-$(date +%H-%M)" + GROUP="master" 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 # TODO: Perhaps define size and arch in a metadata file image_to_vm creates? @@ -93,8 +109,8 @@ arch=x86_64 arch2=amd64 ephemeraldev=/dev/sdb # The name has a limited set of allowed characterrs -name=$(sed -e "s%[^A-Za-z0-9()\\./_-]%_%g" <<< "CoreOS-$VERSION") -description="CoreOS $VERSION" +name=$(sed -e "s%[^A-Za-z0-9()\\./_-]%_%g" <<< "CoreOS-$GROUP-$VERSION") +description="CoreOS $GROUP $VERSION" zoneurl=http://instance-data/latest/meta-data/placement/availability-zone zone=$(curl --fail -s $zoneurl) @@ -179,7 +195,7 @@ ec2-delete-volume "$volumeid" cat <&2 + echo "$0: Cannot find an AMI for CoreOS $GROUP $VER" >&2 exit 1 fi else @@ -76,8 +92,8 @@ else fi # The name has a limited set of allowed characterrs -name=$(sed -e "s%[^A-Za-z0-9()\\./_-]%_%g" <<< "CoreOS-$VER") -description="CoreOS $VER" +name=$(sed -e "s%[^A-Za-z0-9()\\./_-]%_%g" <<< "CoreOS-$GROUP-$VER") +description="CoreOS $GROUP $VER" zoneurl=http://instance-data/latest/meta-data/placement/availability-zone zone=$(curl --fail -s $zoneurl) diff --git a/oem/ami/run.sh b/oem/ami/run.sh index 761758b60a..24c153c8cd 100755 --- a/oem/ami/run.sh +++ b/oem/ami/run.sh @@ -1,15 +1,17 @@ #!/bin/bash -VER="$1" +BOARD="$1" +VER="$2" DIR=/home/ubuntu/official -if [ -z "$VER" ]; then - echo "Usage: $0 1.2.3" >&2 +if [ -z "$BOARD" -o -z "$VER" ]; then + echo "Usage: $0 amd64-usr 1.2.3" >&2 exit 1 fi set -e -sudo $DIR/build_ebs_on_ec2.sh -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 -$DIR/copy_ami.sh -V $VER -K $DIR/aws-pk.pem -C $DIR/aws-cert.pem -$DIR/upload_ami_txt.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 ) +sudo $DIR/build_ebs_on_ec2.sh "${args[@]}" +$DIR/test_ami.sh -v "${args[@]}" +$DIR/copy_ami.sh "${args[@]}" +$DIR/upload_ami_txt.sh "${args[@]}" diff --git a/oem/ami/test_ami.sh b/oem/ami/test_ami.sh index de2c8005ce..db80a3abe1 100755 --- a/oem/ami/test_ami.sh +++ b/oem/ami/test_ami.sh @@ -14,6 +14,8 @@ set -e -o pipefail USAGE="Usage: $0 -a ami-id -a ami-id ID of the AMI to be tests -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. -C CERT Path to Amazon API key certificate. -h this ;-) @@ -25,12 +27,16 @@ This script must be run from an ec2 host with the ec2 tools installed. AMI= VER= +BOARD="amd64-generic" +GROUP="" -while getopts "a:V:K:C:hv" OPTION +while getopts "a:V:b:g:K:C:hv" OPTION do case $OPTION in a) AMI="$OPTARG";; V) VER="$OPTARG";; + b) BOARD="$OPTARG";; + g) GROUP="$OPTARG";; K) export EC2_PRIVATE_KEY="$OPTARG";; C) export EC2_CERT="$OPTARG";; h) echo "$USAGE"; exit;; @@ -44,11 +50,21 @@ if [[ $(id -u) -eq 0 ]]; then exit 1 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 - 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 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 fi elif [[ -n "$AMI" ]]; then @@ -82,10 +98,23 @@ zone=$(curl --fail -s $zoneurl) region=$(echo $zone | sed 's/.$//') 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... " instances=$(ec2-run-instances \ - --user-data "$token" \ + --user-data "$userdata" \ --instance-type "t1.micro" \ --instance-count 3 \ --group "$sg_name" \ @@ -140,6 +169,7 @@ ec2-terminate-instances $instances > /dev/null while ! $ec2_cmd | grep INSTANCE | grep -q terminated do sleep 10; done +sleep 10 ec2-delete-group $sg_name > /dev/null ec2-delete-keypair $key_name > /dev/null rm $key_file diff --git a/oem/ami/upload_ami_txt.sh b/oem/ami/upload_ami_txt.sh index 0ad1f15030..0d5b2d55f9 100755 --- a/oem/ami/upload_ami_txt.sh +++ b/oem/ami/upload_ami_txt.sh @@ -18,6 +18,8 @@ AKI["sa-east-1"]=aki-c88f51d5 USAGE="Usage: $0 -V 100.0.0 -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. -C CERT Path to Amazon API key certificate. -h this ;-) @@ -27,14 +29,18 @@ This script must be run from an ec2 host with the ec2 tools installed. " 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= VER= +BOARD="amd64-generic" +GROUP="" -while getopts "a:V:K:C:hv" OPTION +while getopts "V:b:g:K:C:hv" OPTION do case $OPTION in V) VER="$OPTARG";; + b) BOARD="$OPTARG";; + g) GROUP="$OPTARG";; K) export EC2_PRIVATE_KEY="$OPTARG";; C) export EC2_CERT="$OPTARG";; h) echo "$USAGE"; exit;; @@ -56,10 +62,11 @@ fi declare -A AMIS 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 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 fi AMIS[${r}]=$AMI @@ -67,7 +74,7 @@ done OUT= for r in "${!AMIS[@]}"; do - url=$(printf "$URL_FMT" "$VER" "$r") + url=$(printf "$URL_FMT" "$BOARD" "$VER" "$r") tmp=$(mktemp --suffix=.txt) trap "rm -f '$tmp'" EXIT echo "${AMIS[$r]}" > "$tmp" @@ -79,7 +86,7 @@ for r in "${!AMIS[@]}"; do OUT="${OUT}|${r}=${AMIS[$r]}" fi done -url=$(printf "$URL_FMT" "$VER" "all") +url=$(printf "$URL_FMT" "$BOARD" "$VER" "all") tmp=$(mktemp --suffix=.txt) trap "rm -f '$tmp'" EXIT echo "$OUT" > "$tmp"