Use docker-build.yaml environment variable in angular package.json

Viewed 77

I am trying to get the access token that is available in docker-build.yaml as an environemnt variable to package.json in my angular project

I am basically trying to get that auth token to access a private repository and install as a dependency

"repo_name": "https://github.com/<>:_authToken=${env.NPM_TOKEN}",

something like this. when I tried this, it didn't work as the env.NPM_token is not received.

So trying to see how to get that value in package.json

1 Answers

So, first and foremost; you should never expose sensitive information like this in an ENV or ARG variable, as they will be easily found by anyone.

A way around this is to use so-called docker secrets. Since you're using yaml, you have it relatively easy.

version: '3'

secrets:
  npm_token:
    file: ./token_on_host_system.txt

services:
  node:
  image: nodejs
  secrets: 
    - npm_token
  environment:
    - NPM_TOKEN_FILE=/run/secrets/npm_token

now, the NPM_TOKEN_FILE env variable will point to the file containing your secret. You can now cat this file and use it in your scripts using sed or your tool of preference.

Related