containers / containers/toolbox

Auto-generate configuration for Visual Studio Code's Remote-Containers extension

Open
#628 26 comments 35 reactions 0 assignees View on GitHub
1. Feature request
Dominant language
Go
Stars
3.5k
Forks
262
Avg merge
3d 1h
Merged PRs (30d)
1

Description

# Context

Following discussions in https://github.com/microsoft/vscode-remote-release/issues/3345, I would like to suggest that `toolbox` binary receives a feature to auto-generate all the configuration needed for VSCode's Remote-Containers extension to allow attaching to a given Toolbox container, which I'll name `${TOOLBOX_CONTAINER_NAME}` from now on.

# Instructions

The needed steps, based on my personal use case, could be the following (I'll suppose here that `toolbox` would support VSCode as installed from official RPM/DEB repository, but I'll also give alternatives for an eventual support for VSCode as installed from Flathub):

1. Create a folder `${HOME}/.config/Code/User/globalStorage/ms-vscode-remote.remote-containers/nameConfigs`, if it doesn't exist. I'll refer to it as `${VSCODE_ATTACHED_CONFIG_DIR}` from now on.
* If VSCode was installed from Flathub, the correct path above is `${HOME}/.var/app/com.visualstudio.code/config/Code/User/globalStorage/ms-vscode-remote.remote-containers/nameConfigs`
2. If VSCode was installed from Flathub, it's strongly recommended to inject the following variables to its environment:
```
flatpak --user --override --env HOST_DISPLAY="$DISPLAY" --env HOST_SHELL="$SHELL" --env HOST_SSH_AUTH_SOCK="$SSH_AUTH_SOCK" com.visualsudio.code
```

3. Create/Update file `${VSCODE_ATTACHED_CONFIG_DIR}/${TOOLBOX_CONTAINER_NAME}.json` with the following contents:
```
{
// Support requested in https://github.com/microsoft/vscode-remote-release/issues/4053.
// Replace ${TOOLBOX_CONTAINER_NAME} with any other name
// you want to be displayed in VSCode's status bar
// "name": "${TOOLBOX_CONTAINER_NAME}",
"remoteUser": "${localEnv:USER}",
"settings": {
"remote.containers.copyGitConfig": false,
"remote.containers.gitCredentialHelperConfigLocation": "none",
"terminal.integrated.profiles.linux": {
"capsh": {
"path": "/usr/sbin/capsh",
"args": [
"--caps=",
"--",
"-c",
"exec \"$@\"",
"/bin/sh",
"${localEnv:SHELL}",
"-l"
]
}
},
"terminal.integrated.defaultProfile.linux": "capsh"
},
"remoteEnv": {
"COLORTERM": "${localEnv:COLORTERM}",
"DBUS_SESSION_BUS_ADDRESS": "${localEnv:DBUS_SESSION_BUS_ADDRESS}",
"DESKTOP_SESSION": "${localEnv:DESKTOP_SESSION}",
"DISPLAY": "${localEnv:DISPLAY}", // or "${localEnv:HOST_DISPLAY}", If using VSCode from Flathub (see step 2 above)
"LANG": "${localEnv:LANG}",
"SHELL": "${localEnv:SHELL}", // or "${localEnv:HOST_SHELL}", If using VSCode from Flathub (see step 2 above)
"SSH_AUTH_SOCK": "${localEnv:SSH_AUTH_SOCK}", // or "${localEnv:HOST_SSH_AUTH_SOCK}", If using VSCode from Flathub (see step 2 above)
"TERM": "${localEnv:TERM}",
"VTE_VERSION": "${localEnv:VTE_VERSION}",
"XDG_CURRENT_DESKTOP": "${localEnv:XDG_CURRENT_DESKTOP}",
"XDG_DATA_DIRS": "${localEnv:XDG_DATA_DIRS}",
"XDG_MENU_PREFIX": "${localEnv:XDG_MENU_PREFIX}",
"XDG_RUNTIME_DIR": "${localEnv:XDG_RUNTIME_DIR}",
"XDG_SESSION_DESKTOP": "${localEnv:XDG_SESSION_DESKTOP}",
"XDG_SESSION_TYPE": "${localEnv:XDG_SESSION_TYPE}"
}
}
```

3. Give read/write permissions to `/root` folder within the container for the current user (or, at least, give read permissions to `/root` and create a folder `/root/.vscode-server` with read/write permissions).

4. For containers created with Toolbox **prior to version 0.0.97**, run the following command before starting VSCode:
```
toolbox -c ${TOOLBOX_CONTAINER_NAME} run true
```

5. [Additional steps](https://github.com/flathub/com.visualstudio.code/issues/189#issuecomment-723455868) are needed to make Flatpak'ed VSCode spawn `podman` from host system.

# Additional notes

* Properties `terminal.integrated.shell.linux` and `terminal.integrated.shellArgs.linux` may need to be reviewed to match `toolbox enter ${TOOLBOX_CONTAINER_NAME}` behaviour.

* There are still some discussion in https://github.com/microsoft/vscode-remote-release/issues/3345 about the fact that `.vscode-server` is being installed under `/root` folder within the container, rather than `remoteUser`'s home folder. I'm personally OK with the current behaviour, because I can keep `.vscode-server` folder within the container, but it may not be the desired behaviour for the others.

Supersedes: #610

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.