Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/docker-image.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,15 @@ function derivedTag(image, version) {
}

function derivedDockerfile(image, version) {
// Switch to root before the global npm install: many community/base
// images set a non-root default USER (e.g. `node`), which lacks write
// access to the global npm prefix and would otherwise fail with EACCES.
// The derived image is left running as root - restoring the original
// image's default user would require inspecting the base image at build
// time, which is out of scope here.
return [
`FROM ${image}`,
"USER root",
`RUN npm install -g @tbrandenburg/node-red-cli@${version}`,
`ENTRYPOINT ["node", "${SANDBOX_ENTRY_PATH}"]`,
""
Expand Down
5 changes: 5 additions & 0 deletions test/unit/docker-image.unit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ test("unit: resolveImage installs node-red-cli into a derived image when an expl
assert.match(dockerfileContent, /FROM my-registry\/my-image:latest/);
assert.match(dockerfileContent, /npm install -g @tbrandenburg\/node-red-cli@1\.2\.3/);
assert.match(dockerfileContent, /ENTRYPOINT/);
assert.match(
dockerfileContent,
/USER root\nRUN npm install -g @tbrandenburg\/node-red-cli@1\.2\.3/,
"USER root must appear immediately before the global npm install so non-root base images don't hit EACCES"
);
});

test("unit: resolveImage skips the derived build when it's already cached for that image+version", async () => {
Expand Down