Creating Digital Ocean Droplets

Digital Ocean are a Cloud Hosting provider that supports running VMs and Kubernetes clusters. Along with these they host a market place where users can pick pre-built images (known as Droplets) for the VMs and Application stacks for deploying to the Kubernetes clusters.

Over the last week I’ve spent an hour or two on a few days building Digital Ocean Droplet image to stand up an instance of FlowForge.

Luckily Digital Ocean make the recipes to build their standard images available on GitHub here which gives great examples to build on.

Packer

The recipes all use a tool called packer from Hashicorp to assemble the images.

Packer can be used with a number of different environments, but it has native support for building Digital Ocean Droplet snaphots. To use this you need to generate a Digital Ocean API Token, details of how to generate a token can be found here.

Once you have a token you can start to build the template.json file that will be passed to packer.

{
  "variables": {
    "do_api_token": "{{env `DIGITALOCEAN_API_TOKEN`}}",
    "image_name": "flowforge-1-3-0-snapshot-{{timestamp}}",
    "apt_packages": "apt-transport-https ca-certificates curl jq linux-image-extra-virtual software-properties-common ",
    "application_name": "FlowForge",
    "application_version": "v1.3.0",
    "docker_compose_version": "v2.12.0"
  },
  "sensitive-variables": [
    "do_api_token"
  ],
  "builders": [
    {
      "type": "digitalocean",
      "api_token": "{{user `do_api_token`}}",
      "image": "ubuntu-22-04-x64",
      "region": "lon1",
      "size": "s-1vcpu-1gb",
      "ssh_username": "root",
      "snapshot_name": "{{user `image_name`}}"
    }
  ],
...

Here we have a section at the top that declares a bunch of variables we will use later, and then a builder definition which says to use Digital Ocean as the environment and sets the base image and which region to run the build in.

Next we have the bits that do the real work of building the image, the provisioners section.

For this task they fall into 2 categories

  1. Scripts to run
  2. Files to copy

I used the Digital Ocean Docker droplet as a starting point as I’m installing the FlowForge Docker driver. This includes scripts to ensure that the Ubuntu 22.04 images is up to date and then installs both Docker and Docker Compose. This meant the only tasks needed where to install the FlowForge package and include a script to do the initial configuration (setting the domain to host the FlowForge Projects).

The setup script gets added to the end of the root users .bashrc file so it gets run when the user logs into the Droplet with SSH for the first time. The script removes it’s self from this file so it only runs once.

It also pulls all the needed containers and finally calls docker compose up to start the stack.

Once the template.json was complete it was a case of having packer run it

$ DIGITAL_OCEAN_API_TOKEN=######## packer template.json

Once built the snapshot shows up under Snapshots section in the Images section of the Digital Ocean dashboard. From here it can be published to the Digital Ocean Marketplace once you have signed up as a vendor.

Digital Ocean Snapshots

Trying it out

You can find the FlowForge entry in the Digital Ocean Marketplace here. You will need a domain to host the FlowForge app and any projects you end up running.

It will run in the $6 a month Droplet size, but you may want to bump it to to one of the large offerings depending on how many projects you want to end up running.

The full packer project can be found here