Skip to content

digitalocean/droplet-1-clicks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

1-Click Droplet Packer Build templates

These are the Packer build templates for DigitalOcean Marketplace 1-clicks.

Prereqs

Build Automation with Packer

Packer is a tool for creating images from a single source configuration. Using this Packer template reduces the entire process of creating, configuring, validating, and snapshotting a build Droplet to a single command:

make build-{{image-name}}

The Packer build command can also be run manually.

packer build {{image-name}}/template.json

Usage

To run the Packer build that this template uses by default, you'll need to install Packer and create a DigitalOcean personal access token and set it to the DIGITALOCEAN_API_TOKEN environment variable.

⚠️ Starting Packer version 1.7.0, the DigitalOcean Builder needs to be installed as a plugin. To install the DigitalOcean Builder for Packer version 1.7.0 or later, follow these steps:

  1. Create a new Packer configuration file named plugins.pkr.hcl.
  2. Paste the following content into your Packer configuration file:
    packer {
      required_plugins {
        digitalocean = {
          version = ">= 1.0.4"
          source  = "github.com/digitalocean/digitalocean"
        }
      }
    }
  3. Apply this configuration by running:
    packer init <path-to-your-config-file>/plugins.pkr.hcl

Make sure to adjust the path according to your specific configuration file location.

Running packer build {{image-name}}/template.json without any other modifications will create a build Droplet configured with that 1-Click, clean it, power it down, and snapshot it.

⚠️ The image validation script in common/scripts/999-img_check.sh is copied from the marketplace-partners repo. The marketplace-partners repo is the script's canonical source, so make sure you're using the latest version from there. Update it by running make update-scripts.

Creating a new 1-Click

To start adopting this configuration for your image, you can create a scaffold using the command make {{image-name}} which will create a directory {{image-name}} with a basic Packer build config.

The following variables are required.

  • do_api_token defines the DO API Token used to create resources via DigitalOcean's API. By default, it is set to the value of the DIGITALOCEAN_API_TOKEN environment variable.
  • image_name defines the name of the resulting snapshot, which by default is {{image-name}}-snapshot- with a UNIX timestamp appended.
  • application_name defines the name of the 1-Click in the Marketplace. It is saved to /var/lib/digitalocean/application.info
  • application_version defines the version of the most prominent software installed, usually what gives the 1-Click its name. If you are installing the latest version of the software, this can be a command (See the nodejs 1-Click). It is saved to /var/lib/digitalocean/application.info. Some applications are a bundle of applications and don't have a specific version (See the LAMP 1-Click).

If a 1-Click is installing a particular version of software through a script and not apt, include a variable for the version. (See the nodejs 1-Click)

You can also modify these variables at runtime by using the -var flag.

Configuration Details

By using Packer's DigitalOcean Builder to integrate with the DigitalOcean API, this configuration fully automates image creation.

This configuration uses Packer's file provisioner to upload complete directories to the Droplet. The contents of files/var/ will be uploaded to /var/. Likewise, the contents of files/etc/ will be uploaded to /etc/. One important thing to note about the file provisioner, from Packer's docs:

The destination directory must already exist. If you need to create it, use a shell provisioner just before the file provisioner to create the directory. If the destination directory does not exist, the file provisioner may succeed, but it will have undefined results.

This configuration also uses Packer's shell provisioner to run scripts from the /scripts directory and update installed APT packages using an inline task.

After making changes to the configuration, run the packer validate command.

make validate-{{image-name}}

Learn more about using Packer in the official Packer documentation.

Debugging

Get additional log information by setting the PACKER_LOG environment variable to any value other than "".

PACKER_LOG=1 packer build {{image-name}}/template.json

Add the -debug flag to prompt the user to continue at every Packer build step. The -debug flag also generates a .pem file that can be used to ssh into the droplet to inspect the current state.

packer build -debug {{image-name}}/template.json

Add the -on-error=ask flag. When the build fails, it will prompt the user to either retry, cleanup, or abort the build.

packer build -on-error=ask {{image-name}}/template.json

Notes

  • MySQL and phpMyAdmin use the same files and build script. They have separate template.json files to set different image names and application tag info.