From 19008a43a722327f9a0e45b249880641eea0580c Mon Sep 17 00:00:00 2001 From: Alex Polvi Date: Mon, 14 Oct 2013 14:03:36 -0700 Subject: [PATCH 1/3] feat(all-amis): add uploading off all ami regions --- oem/ami/upload_ami_txt.sh | 55 +++++++++++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 14 deletions(-) diff --git a/oem/ami/upload_ami_txt.sh b/oem/ami/upload_ami_txt.sh index 05e1d8b63d..acb8054c7f 100755 --- a/oem/ami/upload_ami_txt.sh +++ b/oem/ami/upload_ami_txt.sh @@ -3,6 +3,19 @@ # Set pipefail along with -e in hopes that we catch more errors set -e -o pipefail +# we just use this for the list of regions +# should a copy/paste from build_ebs_on_ec2.sh +declare -A AKI +AKI["us-east-1"]=aki-b4aa75dd +AKI["us-west-1"]=aki-eb7e26ae +AKI["us-west-2"]=aki-f837bac8 +AKI["eu-west-1"]=aki-8b655dff +AKI["ap-southeast-1"]=aki-fa1354a8 +AKI["ap-southeast-2"]=aki-3d990e07 +AKI["ap-northeast-1"]=aki-40992841 +AKI["sa-east-1"]=aki-c88f51d5 +# AKI["gov-west-1"]=aki-75a4c056 + USAGE="Usage: $0 -a ami-id -V VERSION Find AMI by CoreOS version. (required) -K KEY Path to Amazon API private key. @@ -35,26 +48,40 @@ if [[ $(id -u) -eq 0 ]]; then exit 1 fi -if [[ -n "$VER" ]]; then - AMI=$(ec2-describe-images -F name="CoreOS-$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 - exit 1 - fi -else +if [[ ! -n "$VER" ]]; then echo "$0: AMI version required via -V" >&2 echo "$USAGE" >&2 exit 1 fi -zoneurl=http://instance-data/latest/meta-data/placement/availability-zone -zone=$(curl --fail -s $zoneurl) -region=$(echo $zone | sed 's/.$//') -url=$(printf "$URL_FMT" "$VER" "$region") +declare -A AMIS +for r in "${!AKI[@]}"; do + AMI=$(ec2-describe-images --region=${r} -F name="CoreOS-$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 + continue + fi + AMIS[${r}]=$AMI +done +OUT= +for r in "${!AMIS[@]}"; do + url=$(printf "$URL_FMT" "$VER" "$r") + tmp=$(mktemp --suffix=.txt) + trap "rm -f '$tmp'" EXIT + echo "${AMIS[$r]}" > "$tmp" + gsutil cp "$tmp" "$url" + echo "OK, $r ${AMIS[$r]}, $url" + if [[ -z "$OUT" ]]; then + OUT="${r}=${AMIS[$r]}" + else + OUT="${OUT}|${r}=${AMIS[$r]}" + fi +done +url=$(printf "$URL_FMT" "$VER" "all") tmp=$(mktemp --suffix=.txt) trap "rm -f '$tmp'" EXIT -echo "$AMI" > "$tmp" +echo "$OUT" > "$tmp" gsutil cp "$tmp" "$url" -echo "OK" +echo "OK, all, $url" From 21b757571479252fce0ab92618b8dc6b658cb961 Mon Sep 17 00:00:00 2001 From: Alex Polvi Date: Mon, 14 Oct 2013 14:05:28 -0700 Subject: [PATCH 2/3] fix whitespace --- oem/ami/upload_ami_txt.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/oem/ami/upload_ami_txt.sh b/oem/ami/upload_ami_txt.sh index acb8054c7f..7b9ecd2cde 100755 --- a/oem/ami/upload_ami_txt.sh +++ b/oem/ami/upload_ami_txt.sh @@ -60,7 +60,7 @@ for r in "${!AKI[@]}"; do | 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 - continue + continue fi AMIS[${r}]=$AMI done From e124560678366d37bd9261823b6a7b04d9c5ae39 Mon Sep 17 00:00:00 2001 From: Alex Polvi Date: Mon, 14 Oct 2013 15:17:25 -0700 Subject: [PATCH 3/3] sneak in some permission stuff --- oem/ami/build_ebs_on_ec2.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/oem/ami/build_ebs_on_ec2.sh b/oem/ami/build_ebs_on_ec2.sh index d92e7dbaf0..2955ce65ab 100755 --- a/oem/ami/build_ebs_on_ec2.sh +++ b/oem/ami/build_ebs_on_ec2.sh @@ -158,6 +158,9 @@ snapshotid=$(ec2-create-snapshot --description "$name" "$volumeid" | cut -f2) while ec2-describe-snapshots "$snapshotid" | grep -q pending do sleep 30; done +echo "Sharing snapshot with Amazon" +ec2-modify-snapshot-attribute "$snapshotid" -c --add 679593333241 + echo "Created snapshot $snapshotid, registering as a new AMI" amiid=$(ec2-register \ --name "$name" \ @@ -168,6 +171,9 @@ amiid=$(ec2-register \ --block-device-mapping $ephemeraldev=ephemeral0 | cut -f2) +echo "Making $amiid public" +ec2-modify-image-attribute "$amiid" --launch-permission -a all + ec2-delete-volume "$volumeid" # hack job to copy AMIs @@ -182,6 +188,7 @@ do --name "$description" \ --region "$r" | cut -f2) + ec2-modify-image-attribute --region "$r" "$amiid" --launch-permission -a all echo "$r $r_amiid" done