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

docs: docker-and-private-modules #285

Merged
merged 2 commits into from
Mar 16, 2023
Merged

docs: docker-and-private-modules #285

merged 2 commits into from
Mar 16, 2023

Conversation

matzar
Copy link
Contributor

@matzar matzar commented Oct 26, 2022

@MylesBorins the previous PRs have pivoted too much and their goal was not stated clearly. This is my fault so this is a final PR that will attempt to clearly and shorty state its purpose and what problems it's trying to fix.

The reason behind this PR is to securely download private npm packages when building a docker image and address the pitfalls with the current set-up in the documentation which are also explained in this article.

Current set-up will save your npm token in the final docker image. This PR solves that problem by showing you how to use the --secret flag with the docker build command and not have your npm token saved in your final docker image.

Example of how to use `--secret` flag to not expose your npm token
in the final docker image.
@matzar
Copy link
Contributor Author

matzar commented Oct 26, 2022

@MylesBorins I think you were concerned about that Docker image not working on CI?

This works for me with GitHub Actions:

- name: Build and Push Docker image
        run: |
          echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > .npmrc
          docker buildx build . -f Dockerfile -t ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY }} --secret id=npmrc,src=.npmrc --push

You have to of course set-up other steps for it like docker buildx, logging to docker etc. but that is GitHub Actions specific. The point in question is that this

RUN --mount=type=secret,id=npmrc,target=/root/.npmrc npm install

can work on CI.

@darcyclarke darcyclarke added the content Issues or PRs related to the content of the docs label Nov 7, 2022
@matzar
Copy link
Contributor Author

matzar commented Mar 16, 2023

@MylesBorins @monishcm I've tried to address the previous concerns but maybe I could improve this PR in any way?

Copy link
Contributor

@MylesBorins MylesBorins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with switching to Node.js 18

@MylesBorins
Copy link
Contributor

@matzar this looks good now. I'm going to test the new instructions locally and then assuming it all works land this

@MylesBorins MylesBorins merged commit 373f8c9 into npm:main Mar 16, 2023
@MylesBorins
Copy link
Contributor

Thanks for all the hard work and patience on seeing this through!

@matzar matzar deleted the patch-3 branch March 17, 2023 11:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
content Issues or PRs related to the content of the docs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants