vscode-remote-release
vscode-remote-release copied to clipboard
Same workspace path for definitions with docker-compose as for definitions using single image/Dockerfile. Possible?
``When opening a directory in a devcontainer (based on a single image or Docker file) the workspace path is automatically set to workspaces/myrepo
(where 'myrepo' is the base path of the directory which is opened in the container). Which is perfect and the opened folder can easily identified in VS Code and even when switching between multiple windows by the title of the window. Example:
But when a docker-compose file is used one have to configure the workspace path hardcoded manually. Most of the examples just use /workspaces. But this gives IHMO not a great user experience because it is quite more difficult to identify which repo / directory is opened. Especially given the fact that you have open multiple windows with different directories/repos and everyone of them just shows "workspace" in the window title and in VS Code. Then it may be quite difficult to spot the right window. Especially if you want to switch between windows with alt + tab or win + tab.
So it would be cool if there would be a pre-defined environment variable or something available which contents the base path of the current opened directory which can then be used in the docker compose file. Something like this:
services:
dev:
build:
context: .
dockerfile: Dockerfile
command: sleep infinity
volumes:
- "..:/workspaces/${WorkspaceFolderBasename}"
I have tried to use an 'initializeCommand' to define a environment variable based on the '${localWorkspaceFolderBasename}' by adding the following to the devcontainer.json:
"initializeCommand": "export repobasepath=${localWorkspaceFolderBasename} "
While the initialize command worked as expected the variable was however not picked up by docker-compose.
So finally after trying different things I found the following working "solution": devcontainer.json:
...
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
"initializeCommand": "echo repobasepath=${localWorkspaceFolderBasename} > .devcontainer/.env",
...
And then in the docker-compose.yml I can use the 'repobasepath' variable:
services:
dev:
build:
context: .
dockerfile: Dockerfile
command: sleep infinity
volumes:
- "..:/workspaces/${repobasepath}"
So I wondering if there is really not a simpler solution? I think the best would be when the 'localWorkspaceFolderBasename' variable from the devcontainer.json would also available as an environment variable during the container build so it can then also be used in docker-compose.
Thank you!