From d11a20c0ee7921ca65989540d2a790cd8f5b7468 Mon Sep 17 00:00:00 2001 From: Ben Potter Date: Mon, 6 Jul 2026 18:37:21 +0000 Subject: [PATCH] feat(registry/coder/templates): add image variable to docker and kubernetes templates --- registry/coder/templates/docker/README.md | 13 +++++++++++++ registry/coder/templates/docker/main.tf | 12 +++++++++++- registry/coder/templates/kubernetes/README.md | 13 ++++++++++++- registry/coder/templates/kubernetes/main.tf | 12 +++++++++++- 4 files changed, 47 insertions(+), 3 deletions(-) diff --git a/registry/coder/templates/docker/README.md b/registry/coder/templates/docker/README.md index 2b5885bb7..0534c2966 100644 --- a/registry/coder/templates/docker/README.md +++ b/registry/coder/templates/docker/README.md @@ -14,6 +14,19 @@ Provision Docker containers as [Coder workspaces](https://coder.com/docs/workspa ## Prerequisites +### Workspace image + +This template exposes an `image` variable that controls which container image workspaces run. The image determines what tools, languages, and runtimes are available in the workspace out of the box, so it has a major impact on the developer experience. + +Some options to consider: + +| Image | Tradeoffs | +| ------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- | +| [`codercom/example-base:ubuntu`](https://github.com/coder/images/tree/main/images/base) (default) | Minimal and lightweight, but may not include many tools developers expect by default | +| [`codercom/example-universal:ubuntu`](https://github.com/coder/images/tree/main/images/universal) | Catch-all image with many languages and tools available, but larger and slower to pull | + +More language-specific images (Go, Java, Node.js, and more) are available in [coder/images](https://github.com/coder/images), and the [devcontainers/images](https://github.com/devcontainers/images) collection is another good source of ready-made development images. You can also build your own image to pre-bake the exact tools your team needs. See [Coder's image management docs](https://coder.com/docs/admin/templates/managing-templates/image-management) for additional guidance. + ### Infrastructure #### Running Coder inside Docker diff --git a/registry/coder/templates/docker/main.tf b/registry/coder/templates/docker/main.tf index b7d0ef159..cdb614b86 100644 --- a/registry/coder/templates/docker/main.tf +++ b/registry/coder/templates/docker/main.tf @@ -19,6 +19,16 @@ variable "docker_socket" { type = string } +variable "image" { + description = <<-EOF + Container image for workspaces. The image determines which tools and + languages are available in the workspace by default. See the template + README for guidance on choosing an image. + EOF + type = string + default = "codercom/example-base:ubuntu" +} + provider "docker" { # Defaulting to null if the variable is an empty string lets us have an optional variable without having to set our own default host = var.docker_socket != "" ? var.docker_socket : null @@ -173,7 +183,7 @@ resource "docker_volume" "home_volume" { resource "docker_container" "workspace" { count = data.coder_workspace.me.start_count - image = "codercom/enterprise-base:ubuntu" + image = var.image # Uses lower() to avoid Docker restriction on container names. name = "coder-${data.coder_workspace_owner.me.name}-${lower(data.coder_workspace.me.name)}" # Hostname makes the shell more user friendly: coder@my-workspace:~$ diff --git a/registry/coder/templates/kubernetes/README.md b/registry/coder/templates/kubernetes/README.md index 0bd7242c7..26e03cb37 100644 --- a/registry/coder/templates/kubernetes/README.md +++ b/registry/coder/templates/kubernetes/README.md @@ -18,7 +18,18 @@ Provision Kubernetes Pods as [Coder workspaces](https://coder.com/docs/workspace **Cluster**: This template requires an existing Kubernetes cluster -**Container Image**: This template uses the [codercom/enterprise-base:ubuntu image](https://github.com/coder/enterprise-images/tree/main/images/base) with some dev tools preinstalled. To add additional tools, extend this image or build it yourself. +### Workspace image + +This template exposes an `image` variable that controls which container image workspaces run. The image determines what tools, languages, and runtimes are available in the workspace out of the box, so it has a major impact on the developer experience. + +Some options to consider: + +| Image | Tradeoffs | +| ------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- | +| [`codercom/example-base:ubuntu`](https://github.com/coder/images/tree/main/images/base) (default) | Minimal and lightweight, but may not include many tools developers expect by default | +| [`codercom/example-universal:ubuntu`](https://github.com/coder/images/tree/main/images/universal) | Catch-all image with many languages and tools available, but larger and slower to pull | + +More language-specific images (Go, Java, Node.js, and more) are available in [coder/images](https://github.com/coder/images), and the [devcontainers/images](https://github.com/devcontainers/images) collection is another good source of ready-made development images. You can also build your own image to pre-bake the exact tools your team needs. See [Coder's image management docs](https://coder.com/docs/admin/templates/managing-templates/image-management) for additional guidance. ### Authentication diff --git a/registry/coder/templates/kubernetes/main.tf b/registry/coder/templates/kubernetes/main.tf index c324331fe..d148e05b4 100644 --- a/registry/coder/templates/kubernetes/main.tf +++ b/registry/coder/templates/kubernetes/main.tf @@ -31,6 +31,16 @@ variable "namespace" { description = "The Kubernetes namespace to create workspaces in (must exist prior to creating workspaces). If the Coder host is itself running as a Pod on the same Kubernetes cluster as you are deploying workspaces to, set this to the same namespace." } +variable "image" { + description = <<-EOF + Container image for workspaces. The image determines which tools and + languages are available in the workspace by default. See the template + README for guidance on choosing an image. + EOF + type = string + default = "codercom/example-base:ubuntu" +} + data "coder_parameter" "cpu" { name = "cpu" display_name = "CPU" @@ -286,7 +296,7 @@ resource "kubernetes_deployment_v1" "main" { container { name = "dev" - image = "codercom/enterprise-base:ubuntu" + image = var.image image_pull_policy = "IfNotPresent" command = ["sh", "-c", coder_agent.main.init_script] security_context {