Question

Use latest version of Docker image for app platform -> deploy latest using Terraform

Hi guys … I’m using Terraform to deploy to the DigitalOcean App platform which basically works good. I’m deploying a public image from DockerHub.

This is my config.

resource "digitalocean_app" "docs-page" {
  spec {
    domain {
      name = "${var.do_subdomain_docs}.${var.do_base_domain}"
    }
    name   = "docs-page"
    region = var.do_region

    service {
      name               = "docs-page-app"
      http_port          = 80
      instance_count     = 1
      instance_size_slug = var.do_instance_smallest
      internal_ports     = []
      source_dir         = "/"

      image {
        registry_type = "DOCKER_HUB"
        registry      = "sommerfeldio"
        repository    = "docs-website"
        tag           = "stable"
      }

      routes {
        path                 = "/"
        preserve_path_prefix = false
      }
    }
  }
}

The image of choice is my sommerfeldio/docs-website:stable (docker pull sommerfeldio/docs-website:stable).

My problem is this: I deploy a new version of my image to DockerHub. Then I trigger terraform apply to update my DigitalOcean infrastructure and terraform states, that nothing has changed (“Apply complete! Resources: 0 added, 0 changed, 0 destroyed.”). This might be true from an infrastructure-pount-of-view because there is no chagne to e.g. the instances count or domain name or whatever. But my image did change. And this change is not picked up. To update my DigitalOcean app I have to destroy and re-provision everything. Which is not something I wanna do.

I’m using this provider: https://registry.terraform.io/providers/digitalocean/digitalocean/latest/docs

How can I tell the terraform-digitalocean-provider to (1) re-deploy the app with the latest image version from DockerHub or (2) update my above mentioned config in a way that it is mandatory to load the image from DockerHub all the time?


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi there,

There are two suggestions that come to my mind:

  • If you were to use the DigitalOcean Container Registry rather than Docker Hub, you will be able to enable automatic deployments, so that whenever you push a new image to that tag, the App Platform will automatically deploy it without you having to do any extra actions:

  • Alternatively, you could use the doctl CLI tool, to trigger a new forced rebuild, that way you would not have to re-provision everything each time.

If you want to force a rebuild you can do so with doctl, DigitalOcean’s command-line utility.

First, find the app’s ID with doctl app list, and then create a new deployment with the --force-rebuild option. Ex. doctl app create-deployment --force-rebuild 42a33f83-5093-44c7-acb5-53f0a218b732.

Hope that this helps!

Best,

Bobby