coder / envbuilder

Build development environments from a Dockerfile on Docker, Kubernetes, and OpenShift. Enable developers to modify their development environment quickly.
Apache License 2.0
142 stars 26 forks source link

Dev Containers: Support volume mounts of devcontainer spec #220

Open mtojek opened 4 months ago

mtojek commented 4 months ago

Follow-up: https://github.com/coder/envbuilder/pull/219

Currently, Envbuilder does not support volume mounts at all

Scope: TBD

matifali commented 4 months ago

It is still possible to persist the workspace directory in a docker workspace build using envbuilder an envbuilder. For example the following snippet uses a docker volume to persist the /workspace directory. A full example is here.

resource "docker_volume" "workspaces" {
  name = "coder-${data.coder_workspace.me.id}"
}

resource "docker_container" "workspace" {
  count = data.coder_workspace.me.start_count
  image = "ghcr.io/coder/envbuilder:latest"
  name = "coder-${data.coder_workspace_owner.me.name}-${lower(data.coder_workspace.me.name)}"
  hostname = data.coder_workspace.me.name
  # Use the docker gateway if the access URL is 127.0.0.1
  env = [
    "CODER_AGENT_TOKEN=${coder_agent.main.token}",
    "CODER_AGENT_URL=${replace(data.coder_workspace.me.access_url, "/localhost|127\\.0\\.0\\.1/", "host.docker.internal")}",
    "GIT_URL="https://github.com/coder/envbuilder-starter-devcontainer",
    "INIT_SCRIPT=${replace(coder_agent.main.init_script, "/localhost|127\\.0\\.0\\.1/", "host.docker.internal")}",
    "FALLBACK_IMAGE=codercom/enterprise-base:ubuntu" # This image runs if builds fail
  ]
  host {
    host = "host.docker.internal"
    ip   = "host-gateway"
  }
  volumes {
    container_path = "/workspaces"
    volume_name    = docker_volume.workspaces.name
    read_only      = false
  }
}
johnstcn commented 3 months ago

@matifali this relates to the devcontainer specification and not mounting in a volume via Terraform.

See: https://containers.dev/implementors/json_reference/#mounts