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

Read build args from env file i.e. private npm registry #5475

Open
fyyyyy opened this issue Aug 18, 2021 · 7 comments
Open

Read build args from env file i.e. private npm registry #5475

fyyyyy opened this issue Aug 18, 2021 · 7 comments
Labels
containers Issue in vscode-remote containers feature-request Request for new features or functionality
Milestone

Comments

@fyyyyy
Copy link

fyyyyy commented Aug 18, 2021

❓ 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 )

export NPM_USER=***
export NPM_PASS=***
export NPM_EMAIL=***

In the Dockerfile:

# Install npm-cli-adduser which can perform a cli npm login by reading env vars
RUN npm i -g --production --registry https://registry.npmjs.org/ npm-cli-adduser

# Set env variables from devcontainer.env. Needs to be in same RUN step as env vars will be lost in next RUN
COPY devcontainer.env devcontainer.env
RUN $(cat devcontainer.env) && npm-cli-adduser -r https://private.registry.url \
&& npm whoami

# install private registry package
RUN npm i -g -r https://private.registry.url private-registry-package

EDIT:
Another option to solve this would be to add a prebuild: property / script to devcontainer.json analog to postbuild:.
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.

@github-actions github-actions bot added the containers Issue in vscode-remote containers label Aug 18, 2021
@chrmarti
Copy link
Contributor

chrmarti commented Aug 23, 2021

Another option would be to pass the values as local variables with the devcontainer.json:

{
  "build": {
    "dockerfile": "Dockerfile",
    "args": {
      "NPM_USER": "${localEnv:NPM_USER}"
    }
  }
}

@chrmarti chrmarti added the feature-request Request for new features or functionality label Aug 23, 2021
@fyyyyy
Copy link
Author

fyyyyy commented Aug 23, 2021

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

@fyyyyy
Copy link
Author

fyyyyy commented Aug 31, 2021

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.

@dlangerm
Copy link

dlangerm commented Mar 3, 2022

Currently waiting on this feature, any updates?

@bence42
Copy link

bence42 commented Jul 22, 2022

+1 would be very handy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
containers Issue in vscode-remote containers feature-request Request for new features or functionality
Projects
None yet
Development

No branches or pull requests

5 participants
@fyyyyy @chrmarti @dlangerm @bence42 and others