Packer is a great tool, but unfortunately it has a couple of minor issues in the getting started guide which snags you. This is a quick write-up to get yourself through those first hurdles quickly.
Setting up an Amazon EC2 Debian image with Oracle Java 8
Problems I encountered
- Using the shell provisioner, you cannot source sub scripts easily
- The usual Oracle Java 8 non-interactive shell script example doesn’t work
- The AMI image in the getting started guide on packer.io doesn’t exist anymore
I won’t go into detail on what I tried and not, but instead I will just focus on the final working scripts.
If you are really impatient, you can skip everything below and just checkout the file from the link above, plug in your credentials in the build script and take it from there.
If you have some more time before you dig into the below, head over and read through the Getting Started Guide at packer.io.
Configuring a basic working image
The first hurdle was that the copy-paste example from packer.io didn’t work. It turned out that the image they used as a starting point doesn’t exist anymore and you will have to plug in your own image ID.
This page lists Debian Amazon images.
Pick an image id which matches your region. Pick it from the column “hvm x86_64 ebs” to be able to run it on the free tier in Amazon EC2. Edit builders section in the JSON file to reflect the image id.
Example
1 2 |
|
Understanding the Java 8 workaround
For me, getting the non-interactive Oracle Java 8 installation simply didn’t work at all. In the end, I had to make a script that downloads the actual installation script and runs the downloaded script as root using sudo.
It is a weird workaround and there is probably a better way, but this one works just as well, so I won’t bother any more at this point.
This is my installer downloader. It downloads and runs this Java 8 installation script.
Packing it
It couldn’t be simpler, just tell packer about your amazon details and point it to the description file. Hint: Set the details as environment variables in your shell login script to avoid accidental sharing.
1 2 |
|
The line is quite long, so I bundled it up in a shell script and
called it build.sh
in the repo.
Launching the image
Once packer is done, just head over to the Amazon Management Console and you will find the freshly created image under Images > AMIs. That is also where you launch it from.
Good luck!