Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 53e5746

Browse files
johnstcnmafredrimatifali
authored
feat(examples/templates/gcp-devcontainer): add envbuilder provider (#14405)
This PR modifies the gcp-devcontainer example template to include support for devcontainer caching using the envbuilder provider. Co-authored-by: Mathias Fredriksson <[email protected]> Co-authored-by: Muhammad Atif Ali <[email protected]>
1 parent a4d785d commit 53e5746

File tree

4 files changed

+232
-84
lines changed

4 files changed

+232
-84
lines changed

examples/examples.gen.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
"gcp",
9393
"devcontainer"
9494
],
95-
"markdown": "\n# Remote Development in a Devcontainer on Google Compute Engine\n\n![Architecture Diagram](./architecture.svg)\n\n## Prerequisites\n\n### Authentication\n\nThis template assumes that coderd is run in an environment that is authenticated\nwith Google Cloud. For example, run `gcloud auth application-default login` to\nimport credentials on the system and user running coderd. For other ways to\nauthenticate [consult the Terraform\ndocs](https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/getting_started#adding-credentials).\n\nCoder requires a Google Cloud Service Account to provision workspaces. To create\na service account:\n\n1. Navigate to the [CGP\n console](https://console.cloud.google.com/projectselector/iam-admin/serviceaccounts/create),\n and select your Cloud project (if you have more than one project associated\n with your account)\n\n1. Provide a service account name (this name is used to generate the service\n account ID)\n\n1. Click **Create and continue**, and choose the following IAM roles to grant to\n the service account:\n\n - Compute Admin\n - Service Account User\n\n Click **Continue**.\n\n1. Click on the created key, and navigate to the **Keys** tab.\n\n1. Click **Add key** \u003e **Create new key**.\n\n1. Generate a **JSON private key**, which will be what you provide to Coder\n during the setup process.\n\n## Architecture\n\nThis template provisions the following resources:\n\n- GCP VM (persistent)\n- GCP Disk (persistent, mounted to root)\n\nCoder persists the root volume. The full filesystem is preserved when the workspace restarts.\n\n\u003e **Note**\n\u003e This template is designed to be a starting point! Edit the Terraform to extend the template to support your use case.\n\n## code-server\n\n`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.\n"
95+
"markdown": "\n# Remote Development in a Devcontainer on Google Compute Engine\n\n![Architecture Diagram](./architecture.svg)\n\n## Prerequisites\n\n### Authentication\n\nThis template assumes that coderd is run in an environment that is authenticated\nwith Google Cloud. For example, run `gcloud auth application-default login` to\nimport credentials on the system and user running coderd. For other ways to\nauthenticate [consult the Terraform\ndocs](https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/getting_started#adding-credentials).\n\nCoder requires a Google Cloud Service Account to provision workspaces. To create\na service account:\n\n1. Navigate to the [CGP\n console](https://console.cloud.google.com/projectselector/iam-admin/serviceaccounts/create),\n and select your Cloud project (if you have more than one project associated\n with your account)\n\n1. Provide a service account name (this name is used to generate the service\n account ID)\n\n1. Click **Create and continue**, and choose the following IAM roles to grant to\n the service account:\n\n - Compute Admin\n - Service Account User\n\n Click **Continue**.\n\n1. Click on the created key, and navigate to the **Keys** tab.\n\n1. Click **Add key** \u003e **Create new key**.\n\n1. Generate a **JSON private key**, which will be what you provide to Coder\n during the setup process.\n\n## Architecture\n\nThis template provisions the following resources:\n\n- Envbuilder cached image (conditional, persistent) using [`terraform-provider-envbuilder`](https://github.com/coder/terraform-provider-envbuilder)\n- GCP VM (persistent) with a running Docker daemon\n- GCP Disk (persistent, mounted to root)\n- [Envbuilder container](https://github.com/coder/envbuilder) inside the GCP VM\n\nCoder persists the root volume. The full filesystem is preserved when the workspace restarts.\nWhen the GCP VM starts, a startup script runs that ensures a running Docker daemon, and starts\nan Envbuilder container using this Docker daemon. The Docker socket is also mounted inside the container to allow running Docker containers inside the workspace.\n\n\u003e **Note**\n\u003e This template is designed to be a starting point! Edit the Terraform to extend the template to support your use case.\n\n## Caching\n\nTo speed up your builds, you can use a container registry as a cache.\nWhen creating the template, set the parameter `cache_repo` to a valid Docker repository in the form `host.tld/path/to/repo`.\n\nSee 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.\n\n\u003e [!NOTE] We recommend using a registry cache with authentication enabled.\n\u003e To allow Envbuilder to authenticate with the registry cache, specify the variable `cache_repo_docker_config_path`\n\u003e with the path to a Docker config `.json` on disk containing valid credentials for the registry.\n\n## code-server\n\n`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.\n"
9696
},
9797
{
9898
"id": "gcp-linux",

examples/templates/devcontainer-docker/README.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,11 @@ Coder supports Devcontainers via [envbuilder](https://github.com/coder/envbuilde
3434

3535
This template provisions the following resources:
3636

37-
- Envbuilder cached image (conditional, persistent)
38-
- Docker image (persistent)
37+
- Envbuilder cached image (conditional, persistent) using [`terraform-provider-envbuilder`](https://github.com/coder/terraform-provider-envbuilder)
38+
- Docker image (persistent) using [`envbuilder`](https://github.com/coder/envbuilder)
3939
- Docker container (ephemeral)
4040
- Docker volume (persistent on `/workspaces`)
4141

42-
with [`envbuilder`](https://github.com/coder/envbuilder) and [`terraform-provider-envbuilder`](https://github.com/coder/terraform-provider-envbuilder).
4342
The Git repository is cloned inside the `/workspaces` volume if not present.
4443
Any local changes to the Devcontainer files inside the volume will be applied when you restart the workspace.
4544
Keep in mind that any tools or files outside of `/workspaces` or not added as part of the Devcontainer specification are not persisted.

examples/templates/gcp-devcontainer/README.md

+16-1
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.

0 commit comments

Comments
 (0)