Fix: Docker build npm creds#1558
Open
shahyashish wants to merge 1 commit intoclearlydefined:masterfrom
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixed by GitFix AI Agent.
To resolve the issue of accessing private npm packages on npm.pkg.github.com while maintaining security, I updated the Dockerfile to use Docker BuildKit's secret mounting feature. Specifically, I removed '.npmrc' from the 'COPY' instruction, which previously baked the credentials into the image layers. I then modified the 'npm install' command to use '--mount=type=secret,id=npmrc,target=/tmp/.npmrc'. This temporarily mounts the credentials into the working directory during the dependency installation phase only, ensuring they are not present in the final container image or its history.
Test: 1. Create a local '.npmrc' file containing the GitHub registry configuration and authentication token (e.g., //npm.pkg.github.com/:_authToken=${TOKEN}).
2. Build the image with BuildKit enabled and the secret provided: 'DOCKER_BUILDKIT=1 docker build --secret id=npmrc,src=.npmrc -t clearlydefined-service .'.
3. Verify that the '@clearlydefined/spdx' package is successfully retrieved and the build completes.
4. Run 'docker history clearlydefined-service' to confirm that no '.npmrc' file was added as a file system layer.
5. Run the image and verify that '/opt/service/.npmrc' does not exist.