Skip to content
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

Permission denied on mkdir .../cypress/dist when installing globally #42

Closed
Flambe opened this issue Apr 17, 2018 · 8 comments
Closed

Comments

@Flambe
Copy link

Flambe commented Apr 17, 2018

We're using the docker image to avoid having to install cypress on every build.

Our docker image only runs this:

FROM cypress/base

RUN npm install -g cypress

We've used this to install cypress fine, then we could use it in our tests.

I've just tried running the build command for this docker, but we're now getting permission denied errors.

Step 3/3 : RUN npm install -g cypress // step 3 as I removed the maintainer line above
 ---> Running in 4a4330ea5831
/usr/local/bin/cypress -> /usr/local/lib/node_modules/cypress/bin/cypress

> cypress@2.1.0 postinstall /usr/local/lib/node_modules/cypress
> node index.js --exec install

EACCES: permission denied, mkdir '/usr/local/lib/node_modules/cypress/dist'
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! cypress@2.1.0 postinstall: `node index.js --exec install`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the cypress@2.1.0 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2018-04-17T14_22_58_013Z-debug.log
The command '/bin/sh -c npm install -g cypress' returned a non-zero code: 1

Has anything changed that could have caused this? We can create the folder manually, but it's still failing.

@bahmutov
Copy link
Contributor

We have recently made cypress/base:8 the default image in #34 (which upgrades Node to 8), so you should switch to building from cypress/base:6 image. Then it works

FROM cypress/base:6

RUN npm install -g cypress
RUN cypress version
RUN cypress verify
$ docker build .
Sending build context to Docker daemon  36.86kB
Step 1/4 : FROM cypress/base:6
 ---> 79e6b8ee7ca4
Step 2/4 : RUN npm install -g cypress
 ---> Using cache
 ---> 47f787811594
Step 3/4 : RUN cypress version
 ---> Running in 59a161dd1c0b
Cypress package version: 2.1.0
Cypress binary version: 2.1.0
Removing intermediate container 59a161dd1c0b
 ---> 35653303a9db
Step 4/4 : RUN cypress verify
 ---> Running in 204d86b7f280
It looks like this is your first time using Cypress: 2.1.0

[14:34:05]  Verifying Cypress can run /usr/local/lib/node_modules/cypress/dist/Cypress [started]
[14:34:06]  Verified Cypress!       /usr/local/lib/node_modules/cypress/dist/Cypress [title changed]
[14:34:06]  Verified Cypress!       /usr/local/lib/node_modules/cypress/dist/Cypress [completed]
Removing intermediate container 204d86b7f280
 ---> 944e171ba654
Successfully built 944e171ba654

@Flambe
Copy link
Author

Flambe commented Apr 17, 2018

That's worked, thank you!

Do you happen to know why node 8 breaks it?

@bahmutov
Copy link
Contributor

the combination of the default user and npm install permissions I think, but the use case for installing Cypress globally is pretty slim right now, so we recommend installing it locally just like a regular dependency. Plus once we do a better job caching the downloaded binary (cypress-io/cypress#1300) then it would not be very painful even locally.

@Flambe
Copy link
Author

Flambe commented Apr 17, 2018

Ah right.

The biggest problem with caching locally (for us) is that our current CI setup runs in disposable dockers each time. This'd mean that we're still installing from scratch each time.

If you do end up pre-caching in the base images, that'd be good (for us).

@bahmutov
Copy link
Contributor

yeah, it is a problem. So on CircleCI and on Travis you can cache installed dependencies, even for Docker builds, other CIs should allow the same. For example cypress-example-recipes shows how to do this

And if you are hardcore Docker user, you could make a Docker images using your dependencies as a first step of the build using something like this https://github.com/bahmutov/double-docker

@Flambe
Copy link
Author

Flambe commented Apr 17, 2018

We're using jenkins, but yeah, there should be something out there that I can find.

Thank you for all the info and help! I'll keep looking into it.

@bsimpson53
Copy link

Got exactly the same problem (cypress + docker + jenkins)

@bsimpson53
Copy link

In case this helps someone else...

I'm using the jenkins declarative pipeline syntax in a Jenkinsfile, jenkins runs containers by default as the jenkins user on the host but I've found (unexpectedly) that you can override that (feel free not to use root ;) ) with:

    stage('Cypress') {
      agent {
        dockerfile {
          dir 'test/cypress'
          args '-u 0:0'
        }
      }
      steps {
        sh 'PROJECT=$(pwd) && cd /opt/cypress && $(npm bin)/cypress run --project ${PROJECT}/test/cypress'
      }
    }

With test/cypress/Dockerfile:

FROM cypress/base:8

WORKDIR /opt/cypress

RUN echo '{}' > package.json && \
    npm install cypress

Thanks @Flambe and @bahmutov for documenting!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants