Skip to content

feat(examples/templates/gcp-devcontainer): add envbuilder provider #14405

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 6 commits into from
Aug 23, 2024

Conversation

johnstcn
Copy link
Member

This PR modifies the gcp-devcontainer example template to include support for devcontainer caching using the envbuilder provider.

This PR modifies the gcp-devcontainer example template to include
support for devcontainer caching using the envbuilder provider.
@johnstcn johnstcn self-assigned this Aug 22, 2024
Copy link
Member

@matifali matifali left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A minor suggestion to use the latest module version. Otherwise looks good to me.
Thank you for doing it 😊

}

variable "cache_repo_docker_config_path" {
default = ""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any standard path we can suggest here or mention in the description?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll mention ~/.docker/config.json but it'll depend heavily on their setup.

data "coder_parameter" "devcontainer_builder" {
description = <<-EOF
Image that will build the devcontainer.
We highly recommend using a specific release as the `:latest` tag will change.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe rephrase it to indicate it is dangerous? For example: Do not use envbuilder:latest tag due to the risk of build instability.

Comment on lines 175 to 180
# If we have a cached image, use the cached image's environment variables. Otherwise, just use
# the environment variables we've defined above.
docker_env_input = try(envbuilder_cached_image.cached.0.env_map, local.envbuilder_env)
# Convert the above to the list of arguments for the Docker run command. This is going to end
# up in our startup script metadata. These are all terminated by backslashes.
docker_env_arg_list = [for k, v in local.docker_env_input : " -e \"${k}=${v}\" \\"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should user modify these locals? If not, maybe indicate that in a comment.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah probably not :D

type = string
}

variable "insecure_cache_repo" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changeset is relatively big, so is the .tf file. Maybe wipe out this variable?

variable "project_id" {
description = "Which Google Compute Project should your workspace live in?"
}

variable "cache_repo" {
default = ""
description = "(Optional) Use a container registry as a cache to speed up builds."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

People may be struggling whether cache_repo is a path, URI, endpoint, etc.

@@ -6,16 +6,49 @@ terraform {
google = {
source = "hashicorp/google"
}
envbuilder = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curious: will we support the original form without envbuilder? if so, should we add a new example like gcp-devcontainer?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The envbuilder provider only gets used if cache_repo is set.

Copy link
Member

@mafredri mafredri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work 🎉

docker_env_input = try(envbuilder_cached_image.cached.0.env_map, local.envbuilder_env)
# Convert the above to the list of arguments for the Docker run command. This is going to end
# up in our startup script metadata. These are all terminated by backslashes.
docker_env_arg_list = [for k, v in local.docker_env_input : " -e \"${k}=${v}\" \\"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This conversion might have trouble with some inputs, writing to an env file and referencing that is an alternative as it doesn't require quoting. Newline inputs could still spell trouble though.

Copy link
Member Author

@johnstcn johnstcn Aug 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like this?

printf %s "<base64-encoded string>" | base64 -d > env.list

auth = "token"
os = "linux"
dir = "/workspaces/${trimsuffix(basename(data.coder_parameter.repo_url.value), ".git")}"
connection_timeout = 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does setting this to zero actually serve a purpose? Doesn't it just use the default of 30s in this case?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsure; this was from the original template IIRC.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, so from reading https://registry.terraform.io/providers/coder/coder/latest/docs/resources/agent#connection_timeout I could imagine that this is set to avoid the agent showing up as 'timed out' due to the GCP instance potentially taking a long time to start.

johnstcn and others added 5 commits August 23, 2024 16:00
Co-authored-by: Mathias Fredriksson <mafredri@gmail.com>
Co-authored-by: Muhammad Atif Ali <atif@coder.com>
@johnstcn johnstcn merged commit 53e5746 into main Aug 23, 2024
27 checks passed
@johnstcn johnstcn deleted the cj/examples/gcp-devcontainer branch August 23, 2024 16:36
@github-actions github-actions bot locked and limited conversation to collaborators Aug 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants