Skip to content

Commit 740f6a9

Browse files
committed
address PR comments
1 parent fafb47c commit 740f6a9

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

examples/templates/gcp-devcontainer/README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,29 @@ a service account:
5151

5252
This template provisions the following resources:
5353

54-
- GCP VM (persistent)
54+
- Envbuilder cached image (conditional, persistent) using [`terraform-provider-envbuilder`](https://github.com/coder/terraform-provider-envbuilder)
55+
- GCP VM (persistent) with a running Docker daemon
5556
- GCP Disk (persistent, mounted to root)
57+
- [Envbuilder container](https://github.com/coder/envbuilder) inside the GCP VM
5658

5759
Coder persists the root volume. The full filesystem is preserved when the workspace restarts.
60+
When the GCP VM starts, a startup script runs that ensures a running Docker daemon, and starts
61+
an Envbuilder container using this Docker daemon. The Docker socket is also mounted inside the container to allow running Docker containers inside the workspace.
5862

5963
> **Note**
6064
> This template is designed to be a starting point! Edit the Terraform to extend the template to support your use case.
6165
66+
## Caching
67+
68+
To speed up your builds, you can use a container registry as a cache.
69+
When creating the template, set the parameter `cache_repo` to a valid Docker repository in the form `host.tld/path/to/repo`.
70+
71+
See the [Envbuilder Terraform Provider Examples](https://github.com/coder/terraform-provider-envbuilder/blob/main/examples/resources/envbuilder_cached_image/envbuilder_cached_image_resource.tf/) for a more complete example of how the provider works.
72+
73+
> [!NOTE] We recommend using a registry cache with authentication enabled.
74+
> To allow Envbuilder to authenticate with the registry cache, specify the variable `cache_repo_docker_config_path`
75+
> with the path to a Docker config `.json` on disk containing valid credentials for the registry.
76+
6277
## code-server
6378

6479
`code-server` is installed via the [`code-server`](https://registry.coder.com/modules/code-server) registry module. Please check [Coder Registry](https://registry.coder.com) for a list of all modules and templates.

examples/templates/gcp-devcontainer/main.tf

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ terraform {
1212
}
1313
}
1414

15-
provider "coder" {
16-
}
15+
provider "coder" {}
1716

1817
provider "google" {
1918
zone = data.coder_parameter.zone.value
@@ -31,19 +30,13 @@ variable "project_id" {
3130

3231
variable "cache_repo" {
3332
default = ""
34-
description = "(Optional) Use a container registry as a cache to speed up builds."
33+
description = "(Optional) Use a container registry as a cache to speed up builds. Example: host.tld/path/to/repo."
3534
type = string
3635
}
3736

38-
variable "insecure_cache_repo" {
39-
default = false
40-
description = "Enable this option if your cache registry does not serve HTTPS."
41-
type = bool
42-
}
43-
4437
variable "cache_repo_docker_config_path" {
4538
default = ""
46-
description = "(Optional) Path to a docker config.json containing credentials to the provided cache repo, if required."
39+
description = "(Optional) Path to a docker config.json containing credentials to the provided cache repo, if required. This will depend on your Coder setup. Example: `/home/coder/.docker/config.json`."
4740
sensitive = true
4841
type = string
4942
}
@@ -118,8 +111,8 @@ data "coder_parameter" "fallback_image" {
118111
data "coder_parameter" "devcontainer_builder" {
119112
description = <<-EOF
120113
Image that will build the devcontainer.
121-
We highly recommend using a specific release as the `:latest` tag will change.
122114
Find the latest version of Envbuilder here: https://ghcr.io/coder/envbuilder
115+
Be aware that using the `:latest` tag may expose you to breaking changes.
123116
EOF
124117
display_name = "Devcontainer Builder"
125118
mutable = true
@@ -141,7 +134,7 @@ data "local_sensitive_file" "cache_repo_dockerconfigjson" {
141134
filename = var.cache_repo_docker_config_path
142135
}
143136

144-
137+
# Be careful when modifying the below locals!
145138
locals {
146139
# Ensure Coder username is a valid Linux username
147140
linux_user = lower(substr(data.coder_workspace_owner.me.name, 0, 32))
@@ -169,7 +162,8 @@ locals {
169162
# The following are used to push the image to the cache repo, if defined.
170163
"ENVBUILDER_CACHE_REPO" : var.cache_repo,
171164
"ENVBUILDER_PUSH_IMAGE" : var.cache_repo == "" ? "" : "true",
172-
"ENVBUILDER_INSECURE" : "${var.insecure_cache_repo}",
165+
# You can add other required environment variables here.
166+
# See: https://github.com/coder/envbuilder/?tab=readme-ov-file#environment-variables
173167
}
174168
# If we have a cached image, use the cached image's environment variables. Otherwise, just use
175169
# the environment variables we've defined above.
@@ -239,7 +233,6 @@ resource "envbuilder_cached_image" "cached" {
239233
git_url = data.coder_parameter.repo_url.value
240234
cache_repo = var.cache_repo
241235
extra_env = local.envbuilder_env
242-
insecure = var.insecure_cache_repo
243236
}
244237

245238
# This is useful for debugging the startup script. Left here for reference.

0 commit comments

Comments
 (0)