Use private package on Dockerfile
Expect
- Able to build image on Docker using private npm package
How
- On Dockerfile add:
ARG NPM_TOKEN
ARG NPM_SCOPE
RUN nl=$'\n' && echo "@$NPM_SCOPE:registry=https://npm.pkg.github.com/ $nl\
//npm.pkg.github.com/:_authToken=$NPM_TOKEN $nl\
" > .npmrc
RUN npm install
RUN rm -f .npmrc
Where:
- scope: (e.g: https://github.com/`this_is_scope`/repo.git) -> scope is
this_is_scope - npm token: can create on github > settings > developer settings > personal access tokens (need repo, write:packages)
note
The shell is ignoring the \n when using double quotes and that using single quotes performs no variable expansion
Then, set env:
export NPM_TOKEN=<your token>
export NPM_SCOPE=<scope>
Then, build your docker with command:
docker build -t ab_chat_sdk --build-arg NPM_TOKEN=${NPM_TOKEN} --build-arg NPM_SCOPE=${NPM_SCOPE} .