Skip to content

Commit 19b1f86

Browse files
chapterjasonclaude
andcommitted
Auto-pull new workspace image when registry digest advances
`docker_container.image` was a floating `:base` tag string, which Docker's cache treats as "already have it" — `coder update` / workspace restart would keep running the old image even after CI pushed a new one. Add a `docker_registry_image` data source that reads the current remote digest and a `docker_image` resource with `pull_triggers = [<digest>]` so every `terraform apply` re-checks the registry: when the digest changes, the image is re-pulled, `image_id` changes, and `docker_container.workspace` replans to recreate with the new image. `projects_volume` (per-workspace) survives the recreate; `coder-shared` and `coder-<owner>-home-persist` aren't in state so they're untouched. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 941cd8a commit 19b1f86

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

main.tf

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,9 +402,23 @@ resource "docker_volume" "projects_volume" {
402402
}
403403
}
404404

405+
# Re-pull the workspace image on every plan when the registry digest has
406+
# advanced. The data source reads the remote digest; docker_image.pull_triggers
407+
# fires when it changes, yielding a new local image_id; the container depends
408+
# on that image_id so a new push → container recreate on next apply.
409+
data "docker_registry_image" "workspace" {
410+
name = local.workspace_images[data.coder_parameter.workspace_image.value]
411+
}
412+
413+
resource "docker_image" "workspace" {
414+
name = data.docker_registry_image.workspace.name
415+
pull_triggers = [data.docker_registry_image.workspace.sha256_digest]
416+
keep_locally = true
417+
}
418+
405419
resource "docker_container" "workspace" {
406420
count = data.coder_workspace.me.start_count
407-
image = local.workspace_images[data.coder_parameter.workspace_image.value]
421+
image = docker_image.workspace.image_id
408422
runtime = "sysbox-runc"
409423

410424
name = "coder-${data.coder_workspace_owner.me.name}-${lower(data.coder_workspace.me.name)}"

0 commit comments

Comments
 (0)