Drone

Cant run tests, permissions denied

im setup a pipeline in Drone ci, my app is on Node.js, and i add the same example pipeline from the documentation of drone but it is not working for me

drone ci cant setup the permissions for execute the jest file, i tried adding a chmod in the commands of the pipeline, but it not work.

this is my .drone.yml

    kind: pipeline
name: talkier

steps:
- name: test
  image: node:11-alpine
  commands:
  - npm install
  - chmod +rwx ./node_modules/.bin/jest
  - npm test

the error is this:

+ chmod +rwx ./node_modules/.bin/jest
+ npm test
> talkier@1.0.0 test /drone/src
> sh node_modules/.bin/jest
node_modules/.bin/jest: line 2: /bin: Permission denied
node_modules/.bin/jest: line 3: syntax error: unexpected "("
npm ERR! Test failed. See above for more details.

When drone executes your yaml it basically is doing this:

$ docker volume create workspace
$ docker run --volume=workspace:/drone/src node /bin/sh -c "npm install; chmod +rwx ./node_modules/.bin/jest; npm test"

Drone does not really have any impact over whether or not bash commands succeed or fail inside a container. When things do fail, it typically signals an issue with the container, with the repository, or with the commands being executed.

In this case, it appears to be a problem with the image. I can see the image sets a default user that is non-root. This is problematic because Docker volumes are owned by root by default. Here is a more detailed breakdown of what is happening:

  1. your repository is cloned into a docker volume, mounted at /drone/src
  2. this volume is owned by root, as is default behavior with docker
  3. the node image sets a default non-root user
  4. this user has insufficient privileged to modify the file
  5. as a results, you receive a Permission denied error

I personally dislike when image maintainers set a default user for docker images for this exact reason, because it can conflict with docker volumes being mounted into the image, but I digress …

This can be solved by overriding the user. It requires Drone 1.1 or higher.

kind: pipeline
name: talkier

steps:
- name: test
  image: node:11-alpine
  user: root
  commands:
  - npm install
  - chmod +rwx ./node_modules/.bin/jest
  - npm test

thanks for the answer, i can solve the problem, it was an error in the command to run the tests in the package.json, my error.

i had this:
“test”: “sh node_modules/.bin/jest”

and the correct way to run test with jest is:
“test”:“jest”

We experience this on almost all official docker images e.g. node, php. Its very frustrating, makes the YAML files look messy.

@andrewmclagan are you using the kubernetes runtime? If so you are probably experiencing this kubernetes issue. The docs label the kubernetes runtime as experimental and not recommended for production use for reasons like this.