I’ve used CoreOS a good deal for the last few months, automating it on Amazon Web Services to run Docker instances like a boss, but when a new version comes out, figuring out the new AMI ID to target is cumbersome. What happens is that a new CoreOS version will be built with AWS, resulting in a new AMI ID, but going to the CoreOS cloud provider’s page to manually grok the ID is no fun. I knew there had to be a automated way to do this, but earlier attempts failed. That changed today as I got a clue from the #coreos channel on [irc.freenode.net] (h/t guys!). Here’s the gist:
#!/bin/bash
build=alpha # define build ["stable", "beta", "alpha"]disk=hvm # define disk backing ["pv", "hvm"]
if [ "x$1" = "x" ]; then echo "Usage: $0 REGION"; exit 1fi
#### deprecated#ami_id=$(curl --silent http://$build.release.core-os.net/amd64-usr/current/coreos_production_ami_all.json | grep -A 2 $1 | grep $disk | cut -d"\"" -f4)
#### Source from coreos.com now (h/t cswong)ami_id=$(curl --silent https://coreos.com/dist/aws/aws-$build.json | grep -A 2 "$1" | grep $disk | cut -d"\"" -f4)
[ -z "$ami_id" ] && echo "FAIL: region $1 not found or doesn't include a CoreOS $build, $disk backed AMI" && exit 1
echo -n "$1,$build,$disk,$ami_id,"echo "https://console.aws.amazon.com/ec2/home?region=$1#launchAmi=$ami_id"
exit 0
If you pull that, and run it, calling out the region you want the AMI in, you’ll get the details. For example:
# coreid.sh us-east-1us-east-1,alpha,hvm,ami-ff35fc94,https://console.aws.amazon.com/ec2/home?region=us-east-1#launchAmi=ami-ff35fc94
Now we have all the details, and for me, most importanly the AMI ID and the URL to launch the AMI. Cool, so that’s it, I’m calling this day a success. Is there an easier way of doing this? Am I missing something obvious? Let me know, always happy to learn more.