📦 Packer ❤ DigitalOcean

At this day you have many choices to create new droplets, let see what we got so far via DigitalOcean

  1. DigitalOcean’s dashboard
  2. DigitalOcean’s API
  3. DigitalOcean’s CLI

For CI/CD sake we’ll need to “ship it” without GUI anyhow so we have to choose between API or CLI there. Far as I try, they serve you well with simple purposes like …

  1. Create snapshot (for faster deployment process)
  2. Create droplets from image (including snapshot)

After mess with API and CLI you’ll end up with plenty of builders, templates, variables, provisioners shell scripts and you’ll have to repeat this again for other platforms. And yes this will take our times to maintain it all…

Good news! Packer is do just that!

Prerequisites

1. Homebrew for install Packer

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

2. Packer

brew install packer

To create snapshot with Packer…

1. Create snapshot config name it snap.json

You can leave provisioners part empty, above it’s just an examples.

2. Run it with your DigitalOcean API token.

DO_TOKEN=YOUR_TOKEN_HERE packer build snap.json

It will create temporary droplet for us…

And it will make snapshot then destroy temporary droplets after that…

3. Done!

Now we got ubuntuz-1498983641 snapshot with ID = 26016450, let’s use it!

To create droplet from snapshot.

  1. Create droplets config file named droplets.json

2. Create drop.sh shell script file

3. Run drop.sh with required parameters name, snapshot ID (from previous step)

DO_TOKEN=YOUR_TOKEN_HERE . drop.sh foo 26016450

And it’s done! No more dashboard! Happy packing!

Note (ref)

Don’t miss a chance to get free $10 for DigitalOcean ← 2 months free hosting!
And do claim your cheapest .io name before it’s gone at NameCheap.