DigitalOcean to start snapshots billing. Don’t have the budget for it? Introduce Packer to your workflow
If you’re like me, you probably have different server configurations for different environments (development, testing, QA, staging, production). To automate the process of provisioning new servers, I have base pre-configured images for various environments for some of my workflow. So for example, an image could contain an Ubuntu OS with an administrative non-root user setup, some folder permissions, a configured firewall and LAMP installed. That way whenever I need such an environment, I won’t have to go through the process of setting up all that again. These images can be stored as snapshots on DigitalOcean (DO) for free.
However, from October 2016, DO starts charging $0.05 per gigabyte per month based on the amount of utilized space within the filesystem. Seems like a small amount but if you’re operating on a low budget and have several snapshots, it can pile up fast! So, time for plan B, right?
Packer is a tool for creating machine and container images for multiple platforms from a single source configuration.
In comes packer. As Hashicorp (creators of packer) put it “Packer is a tool for creating machine and container images for multiple platforms from a single source configuration.” Packer does this through a configuration file know as a template that defines the image(s) we want to build and how we’ll go about doing it. The template has a JSON format making it easy for both developer and operations teams to understand and work on.
The template file is made up of the following sections:
- Variables: packer requires you to define user variables. This section helps other people looking at or using your template identify what can be modified in it using variables.
- Builders: packer can create images for any platform. This section is used to define the platform(s) you want to build an image for. Packer ships with support for only a set of platforms (including DigitalOcean) but can be extended with plugins to support any.
- Provisioners: provisioners are used to install and configure software within running machines just before turning them to machine images. A lot can be done here. This section is optional.
- Post-processors: packer uses this section to perform an action (post-processing) on images created from the build section. Post-processing could include things like uploading an image, compressing it etc. This section is optional.
Here’s an example of a packer template that creates and saves an image as a snapshot on DigitalOcean. You can see the shell provisioner being used to update repositories and install Apache before creating the image. So now you get to create snapshots only when you’re ready to provision a new server on DO then delete them right after.
Packer comes built with support for DigitalOcean and connects to it through the DigitalOcean API. So for this example, you need to retrieve an api-token from your DO account and add it on the template file.
If you frequently provision or manage a lot of servers, you might want to install packer on a remote machine meant for running cron processes. To automate these processes, consider introducing continuous integration and deployment practices with the help of tools like ansible, chef or puppet. Be sure to consult with your development and operations teams before making any decisions on tools. Remember, people before tools!
What workflows and tools are you using to automate your IT operations?
Posts you may also find interesting
Originally published at https://www.linkedin.com on August 19, 2016.