šŸ“¦ Packer ā¤ DigitalOcean

katopz
Digithun
Published in
2 min readJul 2, 2017

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.

--

--