mirror of
https://github.com/flatcar/scripts.git
synced 2025-11-28 14:01:43 +01:00
Merge pull request #120 from polvi/ami-all
feat(all-amis): add uploading off all ami regions
This commit is contained in:
commit
af9c881f72
@ -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
|
||||
|
||||
|
||||
@ -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"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user