microsoft / microsoft/vscode-remote-release

Launch a dev container using current process' environment

Open
#9,339 7 comments 15 reactions 1 assignee View on GitHub

@chrmarti is already working on this.

Since Dec 13, 2024.

containers feature-request
Dominant language
Dockerfile
Stars
4.2k
Forks
470
Avg merge
1d 1h
Merged PRs (30d)
1

Description

We have many devcontainers for many different projects, and these projects use environment variables to access secrets.

Our current strategy to manage this is having all the secrets for all the projects set in Windows, with the variables listed in WSLENV, and then we use remoteEnv in the devcontainer.json files to make the appropriate subset of variables available inside each devcontainer.

To tidy this up, I wanted to store the secrets in 1Password, store references to them in a .env file in each repository, and then use the 1Password CLI to launch the devcontainer using the appropriate .env file.

The way this works is that the .env file for each repo contains entries like:

BATCH_ACCOUNT_KEY="op://dev/azure-batch/account-key"

And you launch VSCode with the 1Password CLI like so:

op run --env-file .env -- code .

The 1Password CLI parses the .env file, resolves the references, and launches VSCode with those resolved variables set in the process' environment.

The above works perfectly when running VSCode in Windows and in Remote: WSL, but I can't seem to get the environment variables to pass through into a devcontainer.

To launch the devcontainer I am doing the following:

mypath="$(wslpath -w $PWD)" && p=$(printf "%s" "$mypath" | hexdump -v -e '/1 "%02x"') && op run --env-file .env -- code --folder-uri "vscode-remote://dev-container+${p}/workspaces/$(basename $PWD)"

This uses one of the solutions from here to launch VSCode directly into a devcontainer, with op run inserted at the appropriate point to launch VSCode. However, currently the dev container doesn't seem to get its environment from the process that launched it.

The simple test of this is just to export FOO=BAR in a shell and then try and launch a VSCode devcontainer from the same shell and have that local FOO envionment variable available in the devcontainer.

Would it be possible to support this scenario?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.