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

devcontainer.json doesn't resolve custom localEnv variable on macOS

Open iLem0n opened this issue 2 years ago • 8 comments

  • VSCode Version: 1.77.3
  • Local OS Version: macOS 13.3.1
  • Remote Extension/Connection Type: Containers

Im working behind a corporate proxy, which is again proxied through a local instance of proxydetox So on my local machine the correct proxy is: http://127.0.0.1:3128 Accessing it from within docker means setting the proxy to http://host.docker.local

To include this into my DevContainer build i have a custom ENV-variable called VSCODE_DEVCONTAINER_PROXY and my devcontainer.json looks basically like this (reduced for brevity):

{
	"build": {
		"dockerfile": "Dockerfile",
		"args": {
			"HTTP_PROXY": "${localEnv:VSCODE_DEVCONTAINER_PROXY}",
			"HTTPS_PROXY": "${localEnv:VSCODE_DEVCONTAINER_PROXY}",
			"http_proxy": "${localEnv:VSCODE_DEVCONTAINER_PROXY}",
			"https_proxy": "${localEnv:VSCODE_DEVCONTAINER_PROXY}"
		}
	}
}

The variable is exported in ~/.bashrc, ~/.bash_profile, ~/.profile and also ~/.config/fish/config.fish

I expect VSCode to pickup this localEnv and then pass it to the --build-args, but as you can see in the log the variable HTTP_PROXY etc. are empty.

I also tried to add them directly in VCCode Settings but without success. Screenshot 2023-04-26 at 12 31 39

I also tried to use another default variable like ${localEnv:PATH} (which is obviously the wrong variable) to check if localEnv is faulty in general but this resolved properly.

I even used ${localEnv:PATH} which resolves properly but has the wrong value (http://127.0.0.1:3128)

  • Logs: The only interesting line in the logs is this one, Here the build-args HTTP_PROXY etc. are empty.
[2023-04-26T10:08:59.957Z] Start: Run: docker buildx build --load --build-arg BUILDKIT_INLINE_CACHE=1 -f /var/folders/l3/bgmsx_jx1811csbpk87m58ph0000gn/T/devcontainercli/container-features/0.35.0-1682503739920/Dockerfile-with-features -t vsc-***-d6151ecda705124662c41d5272a5f10e0b05ff9fa14b91ece652d96c06cf157d --target dev_containers_target_stage --build-arg HTTP_PROXY= --build-arg HTTPS_PROXY= --build-arg http_proxy= --build-arg https_proxy= --build-context dev_containers_feature_content_source=/var/folders/l3/bgmsx_jx1811csbpk87m58ph0000gn/T/devcontainercli/container-features/0.35.0-1682503739920 --build-arg _DEV_CONTAINERS_BASE_IMAGE=dev_container_auto_added_stage_label --build-arg _DEV_CONTAINERS_IMAGE_USER=root --build-arg _DEV_CONTAINERS_FEATURE_CONTENT_SOURCE=dev_container_feature_content_temp /Users/Q278134/Projekte/BMW/SF.D/projects/Infrastruktur/pcmasfd-gen6-iac/.devcontainer

I found a similar issue: https://github.com/microsoft/vscode-remote-release/issues/3456 But none of the solutions proposed here works.

Steps to Reproduce:

  1. Define a custom env-variable
  2. Pass it as build-arg to the devcontainer.json
  3. It will be empty, no matter what's value it currently has locally

This works properly on Windows machines, so it seems to be a Mac specific problem.

iLem0n avatar Apr 26 '23 10:04 iLem0n

Having exactly the same issue even when no corporate proxies involved.

OS: macOS 13.2.1 VSCode: 1.78.1

sigma21 avatar May 11 '23 16:05 sigma21

@iLem0n my issue resolved after rebooting the OS.

sigma21 avatar May 22 '23 14:05 sigma21

I am experiencing this issue as well on Mac.

  • VSCode Version: 1.84.2
  • Mac OS Version: 14.1.1

As @iLem0n reported, none of the variables in ~/.bashrc, ~/.zshrc, ~/.bash_profile, ~/.zsh_profile, ~/.bashenv, ~/.profile, etc are able to pass into my dev container when I use ${localEnv:FOO}. I have tried using build args, containerEnv, and remoteEnv to pass in the variables, but none of them worked.

What did work was setting terminal.integrated.env.linux, because the environment variables that I set are in the resulting Linux shell. However, they were empty during the container build and the execution of post-install scripts through the postCreateCommand.

sammcmanus-idemia avatar Dec 04 '23 23:12 sammcmanus-idemia

I am also seeing this problem. What exactly are the env variables that are available in localEnv when the host is macOS with zsh shell?

UPDATE: turns out, I just had to restart VS code, then it picked up the env vars.

3f6a avatar Mar 25 '24 09:03 3f6a

I'm also experiencing this issue on mac using e.g "DOCKER_DEFAULT_PLATFORM": "${localEnv:DOCKER_DEFAULT_PLATFORM}"

imoshimuir avatar Apr 16 '24 12:04 imoshimuir

I have the same issue on Windows. Referencing ${localEnv:HOME} in the mount section of the devcontianer.json is not resolved all the time. Sometimes it works, sometimes not. Think there's some race condition going on. This is super annoying and makes me wondering if going for devcontainers was a good idea at all...

markusmauch avatar May 08 '24 09:05 markusmauch

If anyone is still having this problem, a workaround is to write your environment variables to a file and use the runArgs --env-file <path-to-env-file>.

sammcmanus-idemia avatar May 08 '24 12:05 sammcmanus-idemia

If anyone is still having this problem, a workaround is to write your environment variables to a file and use the runArgs --env-file <path-to-env-file>.

I have to mount a file from the user's home directory. And of course the repo is used by more than one user... Don't see how using the --env-file argument would be useful here. I need ${localEnv:HOME} or ${localEnv:USER}.

markusmauch avatar May 10 '24 05:05 markusmauch