{
  "variables": {
    "do_token": "{{env `DIGITALOCEAN_TOKEN`}}",
    "image_name": "photoprism-ce-marketplace-{{timestamp}}",
    "apt_packages": "software-properties-common apt-transport-https ca-certificates openssl ufw curl",
    "application_name": "PhotoPrism",
    "application_version": "latest"
  },
  "sensitive-variables": ["do_token"],
  "builders": [
    {
      "type": "digitalocean",
      "api_token": "{{user `do_token`}}",
      "image": "ubuntu-20-04-x64",
      "region": "fra1",
      "size": "s-1vcpu-1gb",
      "ssh_username": "root",
      "snapshot_name": "{{user `image_name`}}"
    }
  ],
  "provisioners": [
    {
      "type": "shell",
      "inline": [
        "cloud-init status --wait"
      ]
    },
    {
      "type": "file",
      "source": "install_photoprism.sh",
      "destination": "/var/lib/cloud/scripts/per-instance/install_photoprism.sh"
    },
    {
      "type": "shell",
      "environment_vars": [
        "DEBIAN_FRONTEND=noninteractive",
        "LC_ALL=C",
        "LANG=en_US.UTF-8",
        "LC_CTYPE=en_US.UTF-8"
      ],
      "inline": [
        "echo 'Acquire::Retries \"10\";' > /etc/apt/apt.conf.d/80retry",
        "echo 'APT::Install-Recommends \"false\";' > /etc/apt/apt.conf.d/80recommends",
        "echo 'APT::Install-Suggests \"false\";' > /etc/apt/apt.conf.d/80suggests",
        "echo 'APT::Get::Assume-Yes \"true\";' > /etc/apt/apt.conf.d/80forceyes",
        "echo 'APT::Get::Fix-Missing \"true\";' > /etc/apt/apt.conf.d/80fixmissing",
        "apt-get -qq update",
        "apt dist-upgrade 2>/dev/null",
        "apt-get -qq install {{user `apt_packages`}}",
        "apt-get -qq autoclean",
        "apt-get -qq autoremove",
        "chmod 700 /var/lib/cloud/scripts/per-instance/install_photoprism.sh"
      ]
    },
    {
      "type": "shell",
      "environment_vars": [
        "DEBIAN_FRONTEND=noninteractive",
        "LC_ALL=C",
        "LANG=en_US.UTF-8",
        "LC_CTYPE=en_US.UTF-8"
      ],
      "scripts": [
        "digitalocean/firewall.sh",
        "digitalocean/cleanup.sh",
        "digitalocean/check.sh"
      ]
    }
  ]
}