Skip to content

Latest commit

 

History

History
51 lines (36 loc) · 2.5 KB

BaseAMI.md

File metadata and controls

51 lines (36 loc) · 2.5 KB

Step 11 - Build and Bake AMI

In continuing with the layers that we'll use for our instances, we build a "Base AMI" that is used by every instance. With this, we can install packages and configuration we believe all instances will need. Ideally this leaves the baking of the actual application to just the application, keeping the bake quick and small.

Install aminator

Aminator is a Python-based open sourced tool from Netflix to "Bake" Amazon images. It can use system packages, like RPMs or DEBs, or via a system of plugins common configuration management tools, like Chef, Puppet or Ansible, to build a machine image. It also supports various base environments. We'll be using Ubuntu but other RPM based OS's like CentOS are supported.

sudo pip install git+https://github.com/Netflix/[email protected]#egg=aminator

Build a Debian

To minimize complexity and to mimic how Netflix bakes, we're going to be building DEBs for baking. Once again we're using Gradle during this tutorial, but you can create your packages however you like. As stated above, you could use Chef or Puppet to instead.

cd ~/zerotocloud
./gradlew :baseami:buildDeb

In Gradle, we're using the ospackage plugin to build our packages. It lets us build RPM and DEB files with a single syntax declarative syntax, in Java. E.g. this is what we're using to build the Base AMI:

ospackage {
    requires('default-jdk')
    requires('tomcat7')

    from(file('root')) {
        into('/')
    }

    postInstall('rm -fr /var/lib/tomcat7/webapps/ROOT')
    postInstall("perl -p -i -e 's/port=\"8080\"/port=\"7001\"/gi' /var/lib/tomcat7/conf/server.xml")
}

Bake

We can now "bake".

sudo aminate -e ec2_aptitude_linux -b ubuntu-foundation -n ubuntu-base-ami baseami/build/distributions/baseami_1.0.0_all.deb

It is run as root, via sudo, so that it can add and remove mount points. The -e argument tells Aminator what environment it is in. In this case we tell it to use Aptitude. The -b argument is the name of the AMI to start with. This is the one we created in Step 8. The -n argument says to use a "named" image, which is easier to keep track of. There will still be a ami-1234567 like name associated with the resulting AMI. One note: Aminate will append a ‘-ebs’ suffix to the name. The baking process takes a few minutes. You can add --debug to the command line to get more details of what it is doing.