Skip to content

Commit e3616e9

Browse files
committed
make cache_repo a template var instead of a parameter
1 parent 8f708de commit e3616e9

File tree

3 files changed

+20
-21
lines changed

3 files changed

+20
-21
lines changed

examples/templates/devcontainer-docker/README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ tags: [container, docker, devcontainer]
99

1010
# Remote Development on Docker Containers (with Devcontainers)
1111

12-
Provision Devcontainers as [Coder workspaces](https://coder.com/docs/v2/latest/workspaces) with this example template.
12+
Provision Devcontainers as [Coder workspaces](https://coder.com/docs/v2/latest/workspaces) in Docker with this example template.
1313

1414
## Prerequisites
1515

@@ -54,7 +54,10 @@ See the [Envbuilder documentation](https://github.com/coder/envbuilder/blob/main
5454

5555
## Caching
5656

57-
To speed up your builds, you can run a local registry and use it as a cache. For example:
57+
To speed up your builds, you can use a container registry as a cache.
58+
When creating the template, set the parameter `cache_repo`.
59+
60+
For example, you can run a local registry:
5861

5962
```shell
6063
docker run --detach \
@@ -65,7 +68,7 @@ docker run --detach \
6568
registry:2
6669
```
6770

68-
Then, when creating a workspace, enter `localhost:5000/devcontainer-cache` for the parameter `cache_repo`.
71+
Then, when creating the template, enter `localhost:5000/devcontainer-cache` for the parameter `cache_repo`.
6972

7073
> [!NOTE] We recommend using a registry cache with authentication enabled.
7174
> To allow Envbuilder to authenticate with the registry cache, specify the variable `cache_repo_docker_config_path`

examples/templates/devcontainer-docker/main.tf

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,11 @@ EOF
8787
order = 4
8888
}
8989

90-
data "coder_parameter" "cache_repo" {
91-
default = ""
92-
description = "Enter a cache repo here to speed up builds."
93-
display_name = "Cache Repo"
94-
mutable = true
95-
name = "cache_repo"
96-
order = 6
90+
variable "cache_repo" {
91+
default = ""
92+
description = "Use a container registry as a cache to speed up builds."
93+
sensitive = true
94+
type = string
9795
}
9896

9997
variable "cache_repo_docker_config_path" {
@@ -161,7 +159,7 @@ resource "docker_container" "workspace" {
161159
"ENVBUILDER_GIT_URL=${local.repo_url}",
162160
"ENVBUILDER_INIT_SCRIPT=${replace(coder_agent.main.init_script, "/localhost|127\\.0\\.0\\.1/", "host.docker.internal")}",
163161
"ENVBUILDER_FALLBACK_IMAGE=${data.coder_parameter.fallback_image.value}",
164-
"ENVBUILDER_CACHE_REPO=${data.coder_parameter.cache_repo.value}",
162+
"ENVBUILDER_CACHE_REPO=${var.cache_repo}",
165163
"ENVBUILDER_DOCKER_CONFIG_BASE64=${try(data.local_sensitive_file.cache_repo_dockerconfigjson[0].content_base64, "")}",
166164
]
167165
host {

examples/templates/devcontainer-kubernetes/main.tf

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ variable "namespace" {
4040
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."
4141
}
4242

43+
variable "cache_repo" {
44+
default = ""
45+
description = "Use a container registry as a cache to speed up builds."
46+
sensitive = true
47+
type = string
48+
}
49+
4350
data "coder_parameter" "cpu" {
4451
type = "number"
4552
name = "cpu"
@@ -116,15 +123,6 @@ EOF
116123
order = 7
117124
}
118125

119-
data "coder_parameter" "cache_repo" {
120-
default = ""
121-
description = "Enter a cache repo here to speed up builds."
122-
display_name = "Cache Repo"
123-
mutable = true
124-
name = "cache_repo"
125-
order = 8
126-
}
127-
128126
variable "cache_repo_secret_name" {
129127
default = ""
130128
description = "Path to a docker config.json containing credentials to the provided cache repo, if required."
@@ -249,7 +247,7 @@ resource "kubernetes_deployment" "main" {
249247
}
250248
env {
251249
name = "ENVBUILDER_CACHE_REPO"
252-
value = data.coder_parameter.cache_repo.value
250+
value = var.cache_repo
253251
}
254252
env {
255253
name = "ENVBUILDER_DOCKER_CONFIG_BASE64"

0 commit comments

Comments
 (0)