Skip to content
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

Allow for use of variables in devcontainer.json #306

Closed
ahayzen opened this issue May 13, 2019 · 9 comments
Closed

Allow for use of variables in devcontainer.json #306

ahayzen opened this issue May 13, 2019 · 9 comments
Labels
containers Issue in vscode-remote containers feature-request Request for new features or functionality

Comments

@ahayzen
Copy link

ahayzen commented May 13, 2019

It would be useful if variables ( https://code.visualstudio.com/docs/editor/variables-reference ) could be used in devcontainers.json, at the moment adding variables to, eg, runArgs fails.

A use case for this might be trying to mount data in the project folder to a specific location eg --volume=${workspaceFolder}/mydb.sqlite:/srv/webapp/mydb.sqlite.

It is possible to workaround this at the moment by using absolute paths but this may allow for more dynamic definitions.

Note environment variable do work.

@egamma
Copy link
Member

egamma commented May 14, 2019

Variables are supported in runArgs see #142 (comment).

@Chuxel I haven't found this documented?

@egamma egamma added the doc label May 14, 2019
Chuxel added a commit to microsoft/vscode-docs that referenced this issue May 14, 2019
@Chuxel
Copy link
Member

Chuxel commented May 14, 2019

@egamma You are right, looks like it isn't. I added it as another sample that uses it to bind mount your home directory into the container. Mounting additional volumes is another topic we support but is in tips and tricks, but is more common. Two birds with one stone.

I've got it queued up to go with the advanced topics when that goes.

@ahayzen
Copy link
Author

ahayzen commented May 14, 2019

Thanks for adding docs !

Yes I found that env variables work in the runArgs but I have found that the "predefined variables" that don't seem to work, eg using ${workspaceFolder} does not work.

Eg a runArgs such as the following

"runArgs": [
	"--volume=${workspaceFolder}:/test:ro"
]

Fails like this

Run: docker run -a STDOUT -a STDERR -v /home/andrew/Projects/vscode-qt-test:/workspaces/vscode-qt-test -v /home/andrew/.gitconfig:/home/developer/.gitconfig -l vsch.quality=insider -l vsch.local.folder=/home/andrew/Projects/vscode-qt-test -l vsch.remote.devPort=9753 --volume=${workspaceFolder}:/test:ro vsc-vscode-qt-test-4a8273a754e9fdaf0918bfb644b6eec3 /bin/sh -c echo Container started ;  while sleep 1; do :; done
docker: Error response from daemon: create ${workspaceFolder}: "${workspaceFolder}" includes invalid characters for a local volume name, only "[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed. If you intended to pass a host directory, use absolute path.
See 'docker run --help'.
Failed: Starting the development container
Command failed: docker run -a STDOUT -a STDERR -v /home/andrew/Projects/vscode-qt-test:/workspaces/vscode-qt-test -v /home/andrew/.gitconfig:/home/developer/.gitconfig -l vsch.quality=insider -l vsch.local.folder=/home/andrew/Projects/vscode-qt-test -l vsch.remote.devPort=9753 --volume=${workspaceFolder}:/test:ro vsc-vscode-qt-test-4a8273a754e9fdaf0918bfb644b6eec3 /bin/sh -c echo Container started ;  while sleep 1; do :; done

I was expecting this to mount the workspace folder from the host into the container at the specified mount point.

@Chuxel Chuxel added feature-request Request for new features or functionality containers Issue in vscode-remote containers and removed doc labels May 14, 2019
@Chuxel Chuxel removed their assignment May 14, 2019
@Chuxel
Copy link
Member

Chuxel commented May 14, 2019

@ahayzen Ah! Got it - yes, that is a feature request, you are right. Removed docs and added the feature-request label given that.

@ulrichSchreiner
Copy link

hi,

it would be great to support the variables not only in runArgs. i tried to do this

"workspaceFolder": "${workspaceFolder}",

and it also did not work. the remote workspace is /.

i want the path of my sources to be equal to the real path. when you're doing go (or other compiler based languages i guess) the path to the sources is part of a stacktrace. i can compile the sources in the container or outside and depending on where i compiled, the source-path's are different.

you also cannot debug a binary which was not compiled in the dev-container when the source path's are wrong. everything is easier if the dev-container feels like your local machine.

so it would be great to mount and open the same path as it is locally.

@Ciantic
Copy link

Ciantic commented Aug 10, 2019

Error response from daemon: invalid mount config for type "bind": invalid mount path: '${workspaceFolder}/keymap' mount path must be absolute.

With devcontainer.json

{
	"workspaceMount": "src=${workspaceFolder}/keymap,dst=/qmk_firmware/keyboards/ergodox_ez/keymaps/ciantic,type=bind,consistency=cached",
	"workspaceFolder": "/qmk_firmware",
}

@KevinGuancheDarias
Copy link

@Ciantic I had this issue too, maybe you are using Docker Toolbox in a Windows machine, when passing the path to the docker command, is doing something like c:/Users/foo/bar which to Linux is a relative path

@Chuxel
Copy link
Member

Chuxel commented Dec 2, 2019

@KevinGuancheDarias @Ciantic ${localWorkspaceFolder} is the local path, but if you are connecting to something remote, be aware that this will be the local filesystem's view of the folder, not the container's (this was added in #442). The name isn't workspaceFolder because the name is ambiguous - it can be either the container or local one.

@chrmarti Should we consider closing this to avoid future confusion? Even though this mentions other variables, I've never actually seen anyone mention anything other thank workspaceFolder.

@chrmarti
Copy link
Contributor

chrmarti commented Dec 2, 2019

I agree, we support ${env:XYZ} and ${localWorkspaceFolder}. (${localEnv:XYZ} and ${containerEnv} in Insiders.)

Let's track additional variables in new tasks. Closing this one.

@chrmarti chrmarti closed this as completed Dec 2, 2019
@vscodebot vscodebot bot locked and limited conversation to collaborators Jan 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
containers Issue in vscode-remote containers feature-request Request for new features or functionality
Projects
None yet
Development

No branches or pull requests

7 participants