vscode-remote-release icon indicating copy to clipboard operation
vscode-remote-release copied to clipboard

Allow localEnv in feature environment variables.

Open Clockwork-Muse opened this issue 2 years ago • 8 comments

Part of the feature spec is a containerEnv property (note - for features, not the devcontainer.json property). It would be nice if it was possible to use the localEnv reference here, so that people who use my feature aren't required to define the environment variable themselves.

Example devcontainer-feature.json

{
    "name": "Some Feature",
    "id": "some-feature",
    "version": "1.0.0",
    "description": "A Feature.",
    "containerEnv": {
        // Currently fails because the substitution isn't performed.
        "DISPLAY": "${localEnv:DISPLAY}",
    },
    // X-11 socket, for window control
    {
        "source": "/tmp/.X11-unix",
        "target": "/tmp/.X11-unix",
        "type": "bind"
    },
    "installsAfter": [
        "ghcr.io/devcontainers/features/common-utils",
    ]
}

Clockwork-Muse avatar Dec 23 '22 19:12 Clockwork-Muse

This would be great. Hope to see this soon 😁

fightingsleep avatar Sep 19 '23 12:09 fightingsleep

Sorry but any plan about this? Just ran into this issue:

ERROR: failed to solve: failed to process "\"${localEnv:WAYLAND_DISPLAY}\"": unsupported modifier (W) in substitution

hellodword avatar Feb 13 '24 03:02 hellodword

@Clockwork-Muse @fightingsleep The following works for me:

{
	"image": "mcr.microsoft.com/devcontainers/base:jammy",
	"containerEnv": {
		"LOCAL_PATH": "${localEnv:PATH}"
	}
}

@hellodword The error looks like you might be using this in something other than a devcontainer.json, e.g., a docker-compose.yml.

chrmarti avatar Feb 13 '24 14:02 chrmarti

@Clockwork-Muse @fightingsleep The following works for me:

{
	"image": "mcr.microsoft.com/devcontainers/base:jammy",
	"containerEnv": {
		"LOCAL_PATH": "${localEnv:PATH}"
	}
}

@hellodword The error looks like you might be using this in something other than a devcontainer.json, e.g., a docker-compose.yml.

I know I can do that in a devcontainer.json, that's not what I want to do. I want to be able to reference local environment variables in features, so a .devcontainer/some feature/devcontainer-feature.json file.

Presumably that's what @hellodword tried when they got that error.

Clockwork-Muse avatar Feb 13 '24 16:02 Clockwork-Muse

Yeah, it's about the devcontainer-feature.json.

hellodword avatar Feb 14 '24 01:02 hellodword

Thanks, I was reading too quickly. :)

Since the original example is for DISPLAY: The X11 display is automatically forwarded into the container when DISPLAY is set locally when using the Dev Containers extension. Not as a container env variable, but as part of VS Code's process in the container.

chrmarti avatar Feb 14 '24 08:02 chrmarti

It is now, sure (and the relevant socket mapped too). It was not at the time of writing.

This feature was intended to be more generally useful.

Clockwork-Muse avatar Feb 14 '24 16:02 Clockwork-Muse

I am now in a situation where a feature installs a binary and when a dev-container with this feature is started, the binary needs to be called and passed the username of the host (WSL in my case). So I would need to set a environment variable to ${localEnv:USER}. This needs currently needs to be done from the devcontainer.json file but it would be nicer to be able to set that in the devcontainer-feature.json file.

Roemer avatar Jun 18 '24 09:06 Roemer