Open fyyyyy opened 3 years ago
Another option would be to pass the values as local variables with the devcontainer.json:
{
"build": {
"dockerfile": "Dockerfile",
"args": {
"NPM_USER": "${localEnv:NPM_USER}"
}
}
}
Another option would be to pass the values as local variables with the devcontainer.json: "NPM_USER": "${localEnv:NPM_USER}"
This only seems to work when launching VScode via commandline, not via app icon.
Also we would prefer to not pollute the OS env with project specific NPM credentials
Another option to solve this would be to add a prebuild:
script to devcontainer.json
This would probably be more flexible as we can copy files to the context, read envs via shell scripts etc.
Currently waiting on this feature, any updates?
+1 would be very handy.
Another option would be to pass the values as local variables with the devcontainer.json:
{ "build": { "dockerfile": "Dockerfile", "args": { "NPM_USER": "${localEnv:NPM_USER}" } } }
This can work in some cases. It would pollute the dev machine with a user-global env var that exists all the time while it is only required when someone works on this specific project.
But also: we might be working in multiple devcontainers at the same time that all refer to the same env var name, simply because it is a meaningful quality name, but in each instance the env var needs to have a different value.
❓ It would be nice if VScode devcontainer.json supports reading build args from a file. So we won't need this workaround:
I have found a workaround to set ENV vars from a file during the docker BUILD. This is i.e. necessary if you want to use a private NPM registry during build, but you don't want to write the secrets in devcontainer.json or Dockerfile, as these files are committed to the repo.
.devcontainer/devcontainer.env ( add this file to .gitignore )
In the Dockerfile:
EDIT: Another option to solve this would be to add a
prebuild:
property / script to devcontainer.json analog topostbuild:
. This could be even more flexible as users can copy files to the context, read envs via shell scripts and many more operations that are usually possible by calling docker build manually.