close
Skip to content

Fix: Docker build npm creds#1558

Open
shahyashish wants to merge 1 commit intoclearlydefined:masterfrom
shahyashish:gitfix-patch-1314-1776220711026
Open

Fix: Docker build npm creds#1558
shahyashish wants to merge 1 commit intoclearlydefined:masterfrom
shahyashish:gitfix-patch-1314-1776220711026

Conversation

@shahyashish
Copy link
Copy Markdown

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant