Skip to content

Commit c56cc1d

Browse files
chapterjasonclaude
andcommitted
Stop destroying shared volumes on workspace delete; pin web-shell 0.5.0
docker_volume.shared and docker_volume.home_persist were declared in the per-workspace terraform state, so `terraform destroy` on any workspace also tried to remove them. They're deployment-wide / per-owner — Docker refused removal while other workspaces still had them mounted, failing the destroy and leaving partial state. Removed both docker_volume resources and reference the volumes by literal name in docker_container.workspace. Docker auto-creates named volumes on first container attach (standard `-v name:/path` semantics), so first workspace for an owner silently creates coder-<owner>-home-persist and first workspace anywhere creates coder-shared. Subsequent workspaces reuse them; delete only tears down the container and workspace-scoped volumes. Trade-off: auto-created volumes have no coder.owner / coder.owner_id labels. Doesn't affect runtime — only orphan-cleanup tooling that filters by label. Also pin web-shell to 0.5.0 (was floating on `latest`) so image builds are reproducible across CI runs. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent b345208 commit c56cc1d

2 files changed

Lines changed: 8 additions & 30 deletions

File tree

main.tf

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -358,33 +358,6 @@ resource "docker_volume" "docker_data" {
358358
}
359359
}
360360

361-
# Per-owner persistence volume. Follows the owner across every workspace they
362-
# open. Survives workspace deletion. Bind-mounted at /mnt/home-persist; the
363-
# home-persist resolver symlinks declared $HOME paths into it.
364-
resource "docker_volume" "home_persist" {
365-
name = "coder-${data.coder_workspace_owner.me.name}-home-persist"
366-
lifecycle {
367-
ignore_changes = all
368-
}
369-
labels {
370-
label = "coder.owner"
371-
value = data.coder_workspace_owner.me.name
372-
}
373-
labels {
374-
label = "coder.owner_id"
375-
value = data.coder_workspace_owner.me.id
376-
}
377-
}
378-
379-
# Deployment-wide shared drop box. A single docker volume — fixed name, no
380-
# per-owner/per-workspace suffix — attached to every workspace.
381-
resource "docker_volume" "shared" {
382-
name = "coder-shared"
383-
lifecycle {
384-
ignore_changes = all
385-
}
386-
}
387-
388361
# Per-workspace $HOME volume. Persists user data (~/.bashrc tweaks, cloned
389362
# repo, build artefacts) across workspace restarts.
390363
resource "docker_volume" "home_volume" {
@@ -446,9 +419,14 @@ resource "docker_container" "workspace" {
446419
read_only = false
447420
}
448421

422+
# home_persist and shared are NOT terraform-managed — they're owned outside
423+
# this workspace's lifecycle (per-owner and deployment-wide respectively).
424+
# Referencing them by name means workspace destroy won't try to remove them
425+
# (which would fail while other workspaces hold them). Docker auto-creates
426+
# on first attach; pre-create on the host if you want labels for tracking.
449427
volumes {
450428
container_path = "/mnt/home-persist"
451-
volume_name = docker_volume.home_persist.name
429+
volume_name = "coder-${data.coder_workspace_owner.me.name}-home-persist"
452430
read_only = false
453431
}
454432

@@ -460,7 +438,7 @@ resource "docker_container" "workspace" {
460438

461439
volumes {
462440
container_path = "/mnt/shared"
463-
volume_name = docker_volume.shared.name
441+
volume_name = "coder-shared"
464442
read_only = false
465443
}
466444

scripts/web-shell/install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# reached via Coder's reverse proxy, which gates access with Coder auth.
1717
set -e
1818

19-
WS_VERSION_OPT="${VERSION:-latest}"
19+
WS_VERSION_OPT="${VERSION:-0.5.0}"
2020
WS_PORT="${PORT:-4000}"
2121

2222
# Resolve the container's remote user. $_REMOTE_USER is set by the Dockerfile's

0 commit comments

Comments
 (0)