Bitbucket Pipelines is using Docker containers to executes tasks and by default Docker containers run as root. This is a problem for NPM's lifecycle scripts because NPM tries to downgrade its privileges when it runs scripts.
When executing the postinstall
script, NPM throws an error that it cannot run in wd %s %s (wd=%s)
. The simplest solution is to run npm install with the --unsafe-perm
flag, but I don't like this approach.
Docker's best practices for writing Dockerfiles states that:
If a service can run without privileges, use USER to change to a non-root user.
When configuring a typical Docker container I would create a new, non-root user and run my npm scripts as this user.
After reading Pipelines documentation I couldn't find any equivalent to Docker's USER command. I might be able to use useradd
, chown
and su
(didn't test that yet) but is there a simpler solution?
Unfortunately adding useradd
, chown
and su
to bitbucket-pipelines.yml
script section breaks Pipelines and results in failing repo:push
webhook.
image: node:6.2
pipelines:
default:
- step:
script:
- useradd --user-group --create-home --shell /bin/false node
- chown -R node: /opt/atlassian/bitbucketci/agent/build
- su -s /bin/sh -c "npm install" node
- su -s /bin/sh -c "npm run test:coverage --silent" node
Pipelines responds with
{
"code": 500,
"message": "There was an error processing your request. It has been logged (ID <removed>)."
}
/opt/atlassian/bitbucketci/agent/build
in other PipeLines questions. Does anyone know where to find the agent info for the container that is running so i can grab the generated build? – Weakness