-
Notifications
You must be signed in to change notification settings - Fork 35
fix: build Docker image from the workspace root #118
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # Without this, `COPY . .` copies the host's node_modules over the ones | ||
| # installed by `npm ci` in the image -- host-platform binaries and all. | ||
| node_modules | ||
| **/node_modules | ||
|
|
||
| # Build artefacts, regenerated in the container | ||
| opsimate-docs/build | ||
| opsimate-docs/.docusaurus | ||
| opsimate-docs/.cache-loader | ||
|
|
||
| .git | ||
| .github | ||
| *.log | ||
| .DS_Store | ||
| .env | ||
| .env.local |
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| FROM node:24-alpine | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| # Build from the repo root, not from opsimate-docs/. This is an npm workspace, | ||
| # so the root package-lock.json is the only lockfile -- it is what CI installs | ||
| # and what Dependabot maintains. Building from the subdirectory previously used | ||
| # a second, unmaintained lockfile that had drifted out of sync with | ||
| # package.json and broke `npm ci` outright. | ||
| COPY package.json package-lock.json ./ | ||
| COPY opsimate-docs/package.json ./opsimate-docs/ | ||
|
|
||
| RUN npm ci | ||
|
|
||
| COPY . . | ||
|
|
||
| EXPOSE 3000 | ||
|
|
||
| # --host 0.0.0.0 so the server is reachable from outside the container; | ||
| # Docusaurus binds to localhost by default, which `docker run -p` cannot reach. | ||
| CMD ["npm", "run", "start", "--workspace=opsimate-docs", "--", "--host", "0.0.0.0"] | ||
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
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔒 Security & Privacy | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: OpsiMate/documentation
Length of output: 204
🏁 Script executed:
Repository: OpsiMate/documentation
Length of output: 2891
🌐 Web query:
Docker official Node Dockerfile node:alpine base image USER default CMD node USER node💡 Result:
In the official Node.js Docker images (including node:alpine), the default user at runtime is root [1][2][3]. Although these images include a pre-created, unprivileged user named node (typically with UID 1000) [4][5][3], the images are designed to start as root by default to provide maximum flexibility during the build and setup process [1]. If the user were set to node by default, any subsequent instructions in a Dockerfile that require root privileges (such as installing OS-level dependencies via apk or apt) would necessitate switching back to root [1]. To follow security best practices and adhere to the principle of least privilege, you should drop privileges after your setup is complete by adding USER node to your Dockerfile, typically just before your CMD instruction [6][7][8][3]. Example workflow in a Dockerfile: FROM node:alpine # Perform root-level operations (e.g., installing dependencies) RUN apk add --no-cache some-package WORKDIR /home/node/app # Switch to the unprivileged node user USER node # Run the application CMD ["node", "index.js"] Alternatively, you can run an existing image as the non-root user without modifying the Dockerfile by using the --user or -u flag in your docker run command: docker run -u "node" node:alpine node index.js [7][3]
Citations:
Run the documentation server as the unprivileged
nodeuser.Dockerfiledoes not setUSER, soCMDruns under the base image user. AddUSER nodebeforeCMDafter assigning/appownership to that user.Proposed fix
🧰 Tools
🪛 Trivy (0.72.0)
[error] 1-1: Image user should not be 'root'
Specify at least 1 USER command in Dockerfile with non-root user as argument
Rule: DS-0002
Learn more
(IaC/Dockerfile)
🤖 Prompt for AI Agents
Source: Linters/SAST tools