Skip to content

feat(dogfood/coder): add docker volume for... docker #18455

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 47 additions & 7 deletions dogfood/coder/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,11 @@ resource "coder_agent" "dev" {
threshold = data.coder_parameter.res_mon_volume_threshold.value
path = data.coder_parameter.res_mon_volume_path.value
}
volume {
enabled = true
threshold = data.coder_parameter.res_mon_volume_threshold.value
path = "/var/lib/docker"
}
}

startup_script = <<-EOT
Expand Down Expand Up @@ -476,15 +481,13 @@ resource "coder_agent" "dev" {
#!/usr/bin/env bash
set -eux -o pipefail

# Stop all running containers and prune the system to clean up
# /var/lib/docker to prevent errors during workspace destroy.
# Clean up the unused resources to keep storage usage low.
#
# WARNING! This will remove:
# - all containers
# - all networks
# - all images
# - all build cache
docker ps -q | xargs docker stop
# - all stopped containers
# - all networks not used by at least one container
# - all images without at least one container associated to them
# - all build cache
docker system prune -a -f

# Stop the Docker service to prevent errors during workspace destroy.
Expand Down Expand Up @@ -525,6 +528,38 @@ resource "docker_volume" "home_volume" {
}
}

resource "coder_metadata" "docker_volume" {
resource_id = docker_volume.docker_volume.id
hide = true # Hide it as it is not useful to see in the UI.
}

resource "docker_volume" "docker_volume" {
name = "coder-${data.coder_workspace.me.id}-docker"
# Protect the volume from being deleted due to changes in attributes.
lifecycle {
ignore_changes = all
}
# Add labels in Docker to keep track of orphan resources.
labels {
label = "coder.owner"
value = data.coder_workspace_owner.me.name
}
labels {
label = "coder.owner_id"
value = data.coder_workspace_owner.me.id
}
labels {
label = "coder.workspace_id"
value = data.coder_workspace.me.id
}
# This field becomes outdated if the workspace is renamed but can
# be useful for debugging or cleaning out dangling volumes.
labels {
label = "coder.workspace_name_at_creation"
value = data.coder_workspace.me.name
}
}

data "docker_registry_image" "dogfood" {
name = data.coder_parameter.image_type.value
}
Expand Down Expand Up @@ -586,6 +621,11 @@ resource "docker_container" "workspace" {
volume_name = docker_volume.home_volume.name
read_only = false
}
volumes {
container_path = "/var/lib/docker/"
volume_name = docker_volume.docker_volume.name
read_only = false
}
capabilities {
add = ["CAP_NET_ADMIN", "CAP_SYS_NICE"]
}
Expand Down
Loading