8000 chore(examples): update devcontainer-docker template by johnstcn · Pull Request #14199 · coder/coder · GitHub
[go: up one dir, main page]

Skip to content

chore(examples): update devcontainer-docker template #14199

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 14, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
update devcontainer template
  • Loading branch information
johnstcn committed Aug 13, 2024
commit e40dd7a0ddd30ba2f590d4fa51e606b09904417a
18 changes: 17 additions & 1 deletion examples/templates/devcontainer-docker/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@ terraform {
docker = {
source = "kreuzwerker/docker"
}
envbuilder = {
source = "coder/envbuilder"
}
}
}

provider "coder" {}
provider "docker" {}
provider "envbuilder" {}
data "coder_provisioner" "me" {}
data "coder_workspace" "me" {}
data "coder_workspace_owner" "me" {}
Expand Down Expand Up @@ -145,9 +149,18 @@ resource "docker_volume" "workspaces" {
}
}

# Check for the presence of a prebuilt image in the cache repo
# that we can use instead.
resource "envbuilder_cached_image" "cached" {
count = data.coder_workspace.me.start_count
builder_image = local.devcontainer_builder_image
git_url = local.repo_url
cache_repo = var.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.

Should we make these optional and let them be provided via extra env too? Would simplify a bit and a user knows they can just cram everything in extra.

Right now for url is given here and in extra, what if the values differ? What's the behavior? (IMO maybe it's an error).

Copy link
Member Author

Choose a reason for hiding this comment

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

Alternatively, we could validate at runtime that extra_env does not contain any duplicated variables from the inputs?

Copy link
Member

Choose a reason for hiding this comment

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

I agree, that’s what I had in mind, but in a more roundabout way 😅. I think it would help with avoiding mistakes, and remove ambiguity.

}

resource "docker_container" "workspace" {
count = data.coder_workspace.me.start_count
image = local.devcontainer_builder_image
image = envbuilder_cached_image.cached.0.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:~$
Expand All @@ -161,7 +174,10 @@ resource "docker_container" "workspace" {
"ENVBUILDER_FALLBACK_IMAGE=${data.coder_parameter.fallback_image.value}",
"ENVBUILDER_CACHE_REPO=${var.cache_repo}",
"ENVBUILDER_DOCKER_CONFIG_BASE64=${try(data.local_sensitive_file.cache_repo_dockerconfigjson[0].content_base64, "")}",
Copy link
Member

Choose a reason for hiding this comment

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

Should this also be passed to enbuilder_cached_image? What about utilizing the output envbuilder_cached_image.cached.env?

Copy link
Member Author

Choose a reason for hiding this comment

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

oop, forgot about the env 👍

Copy link
Member Author
@johnstcn johnstcn Aug 13, 2024

Choose a reason for hiding this comment

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

OK, I took a stab at this -- unfortunately there's a bug in the provider that mangles the init script. I can remove the FIXME after this is done though.

"ENVBUILDER_PUSH_IMAGE=${var.cache_repo != "" ? "true" : ""}",
#"ENVBUILDER_INSECURE=true", # Uncomment if testing with a local registry.
]
# network_mode = "host" # Uncomment if testing with a local registry.
host {
host = "host.docker.internal"
ip = "host-gateway"
Expand Down
0