Use github private repo deploy key inside build stage in docker for npm install

后端 未结 1 863
孤街浪徒
孤街浪徒 2021-01-02 18:53

My use case is that I have multiple express micro-services that use the same middleware and I would like to create a different repo in the format of an npm module for each m

相关标签:
1条回答
  • 2021-01-02 19:34

    Let's experiment with this new feature: Docker multi stage build

    You can selectively copy artifacts from one stage to another, leaving behind everything you don’t want in the final image.

    The idea is to build a temporary base image, then start the build again only taking what you want from the previous image. It uses multiple FROM in the same Dockerfile:

    FROM node as base-node-modules
    COPY your_secret_key /some/path
    COPY package.json /somewhere
    RUN npm install <Wich use your key>
    
    FROM node #yes again!
    ...
    ...
    COPY --from=base-node-modules /somewhere/node_modules /some/place/node_modules
    ...
    ... # the rest of your Dockerfile
    ...
    

    Docker will discard everything what you don't save from the first FROM.

    0 讨论(0)
提交回复
热议问题