Gudlaugur Egilsson
Gudlaugur Egilsson

Reputation: 2460

Why does npm not run prepublishOnly in docker?

When developing a monorepo tool (yamrt) designed to publish npm packages in a ci/cd environment, prepublishOnly scripts were not being run in some runners.

All tests are passing in circleci image circleci/node:12

Same tests fail in the official node:12 image

Why?

Upvotes: 1

Views: 1035

Answers (1)

Gudlaugur Egilsson
Gudlaugur Egilsson

Reputation: 2460

It turns out that circleci/node:12 image adds a user to run builds, while node:12 does not have a user, and therefore processes there are run as root. npm refuses to run prepublishOnly scripts as root, with this rather cryptic message:

npm WARN lifecycle [email protected]~prepublishOnly: cannot run in wd [email protected] echo PREPUBLISHING NM (wd=.)

An obvious fix is to add a user to the ci builder image, which is of course good sense in any case.

RUN groupadd ciuser && useradd -ms /bin/bash ciuser -g ciuser
USER ciuser

Upvotes: 1

Related Questions