Skip to content

agent: support recreating a running devcontainer #481

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

Closed
johnstcn opened this issue Mar 12, 2025 · 1 comment · Fixed by coder/coder#17308
Closed

agent: support recreating a running devcontainer #481

johnstcn opened this issue Mar 12, 2025 · 1 comment · Fixed by coder/coder#17308
Assignees

Comments

@johnstcn
Copy link
Member

Required by coder/coder#16424

Given a running devcontainer, provide the ability for the agent to recreate the devcontainer.

Here is the sample invocation of recreating a devcontainer as performed by the VSCode Devcontainer plugin:

[132 ms] Start: Run: /Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (Plugin).app/Contents/MacOS/Code Helper (Plugin) /Users/cian/.vscode/extensions/ms-vscode-remote.remote-containers-0.401.0/dist/spec-node/devContainersSpecCLI.js up --user-data-folder /Users/cian/Library/Application Support/Code/User/globalStorage/ms-vscode-remote.remote-containers/data --container-session-data-folder /tmp/devcontainers-db406014-703e-46ab-b72f-1496ba8685ac1741616579267 --workspace-folder /Users/cian/src/coder/envbuilder-starter-devcontainer --workspace-mount-consistency cached --gpu-availability detect --id-label devcontainer.local_folder=/Users/cian/src/coder/envbuilder-starter-devcontainer --id-label devcontainer.config_file=/Users/cian/src/coder/envbuilder-starter-devcontainer/.devcontainer/devcontainer.json --log-level debug --log-format json --config /Users/cian/src/coder/envbuilder-starter-devcontainer/.devcontainer/devcontainer.json --default-user-env-probe loginInteractiveShell --build-no-cache --remove-existing-container --mount type=volume,source=vscode,target=/vscode,external=true --skip-post-create --update-remote-user-uid-default on --mount-workspace-git-root --include-configuration --include-merged-configuration

Things to note:

  • The devcontainer-cli really needs --id-label in conjunction with --remove-existing-container in order for it to know which container to delete.
  • It's not immediately clear which of the above options are always needed, which are specified inside the devcontainer.json (for example, userEnvProbe can be specified in devcontainer.json), and which we need to figure out on the fly.
@mafredri
Copy link
Member

mafredri commented Mar 27, 2025

I did some experimentation to verify the role of --id-label, and what I found is that it's not really needed when invoking @devcontainers/cli or VS Code devcontainer extension without any custom options.

For instance, "entering devcontainer" in VS Code does not specify any custom labels, these defaults will be used:

{
  "devcontainer.config_file": "/home/coder/coder/.devcontainer/devcontainer.json",
  "devcontainer.local_folder": "/home/coder/coder"
}

These are the same ones created by @devcontainers/cli. So running the following command works as expected:

cd ~/coder
devcontainer up --workspace-folder . --remove-existing-container

VS Code is also able to connect into the new container created by @devcontainers/cli.

Where things get a bit interesting is when --id-label is being manually specified.

For instance, a dev container started with:

devcontainer up --id-label coder=coder --workspace-folder . --remove-existing-container

Will not create either devcontainer.config_file nor devcontainer.local_folder labels, and instead only add the following label:

{
  "coder": "coder"
}

This devcontainer won't be detected by VS Code and will also be filtered out by our current agentcontainers implementation/usage.


We don't need to support the custom label use-case, and we can always expect that devcontainer.local_folder=[workspace_folder] will be handled implicitly. The only case where I think --id-label matters is if a non-default path is used for devcontainer.config_file.

For container re-recreation, we can specify both from the docker container label just to be sure that's the one we re-create.

mafredri added a commit to coder/coder that referenced this issue Apr 9, 2025
mafredri added a commit to coder/coder that referenced this issue Apr 9, 2025
mafredri added a commit to coder/coder that referenced this issue Apr 9, 2025
mafredri added a commit to coder/coder that referenced this issue Apr 9, 2025
mafredri added a commit to coder/coder that referenced this issue Apr 10, 2025
This change implements an interface for running `@devcontainers/cli up`
and an API endpoint on the agent for triggering recreate for a running
devcontainer.

A couple of limitations:

1. Synchronous HTTP request, meaning the browser might choose to time it
out before it's done => no result/error (and devcontainer cli command
probably gets killed via ctx cancel).
2. Logs are only written to agent logs via slog, not as a "script" in
the UI.

Both 1 and 2 will be improved in future refactors.

Fixes coder/internal#481
Fixes coder/internal#482
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants