netlify-plugin-cypress icon indicating copy to clipboard operation
netlify-plugin-cypress copied to clipboard

Cypress caching in `~/.cache/Cypress`

Open ehmicky opened this issue 5 years ago • 4 comments
trafficstars

Installing Build plugins takes time. To make builds as fast as possible, Netlify is now pre-installing all known Build plugins before the build even starts, leading to 0s additional installation time. This is done as part of the build step of our main Docker image.

However, Cypress downloads binaries and caches them in ~/.cache/Cypress (on Linux). By default, ~/.cache is restored/saved to a cache at the beginning/end of every build. Since ~/.cache/Cypress takes 580MB, this adds 20s to 30s additional time to every build.

We are discussing with @mikeh and @vbrown608 how to fix this performance issue. One way would be to use the CYPRESS_CACHE_FOLDER environment variable to change the location of this directory. Note: this would mean the following section of this plugin's README would need to be updated.

What are your thoughts on this @bahmutov? Do you think this is a viable approach?

ehmicky avatar May 23 '20 13:05 ehmicky

We have added the CYPRESS_CACHE_FOLDER environment variable to point to /opt/buildhome/.cypress-cache instead. That cache directory is thrown away after the initial pre-installation (before the build starts). When this plugin's onPreBuild kicks in, cypress install is run, which should add ~/.cache/Cypress, which is then saved in the build cache.

Please let us know if there is anything problematic with this approach.

ehmicky avatar Jun 02 '20 21:06 ehmicky

I've been trying to integrate this plugin and no matter what I try I get this error:

2:08:10 PM: ┌────────────────────────────────────────────────┐
2:08:10 PM: │ Plugin "netlify-plugin-cypress" internal error │
2:08:10 PM: └────────────────────────────────────────────────┘
2:08:10 PM: ​
2:08:10 PM:   Error message
2:08:10 PM:   Error: The cypress npm package is installed, but the Cypress binary is missing.
2:08:10 PM: ​
2:08:10 PM:   We expected the binary to be installed here: /opt/build/repo/node_modules/CypressBinary/4.9.0/Cypress/Cypress
2:08:10 PM: ​
2:08:10 PM:   Reasons it may be missing:
2:08:10 PM: ​
2:08:10 PM:   - You're caching 'node_modules' but are not caching this path: /opt/buildhome/.cache/Cypress
  - You ran 'npm install' at an earlier build step but did not persist: /opt/buildhome/.cache/Cypress
2:08:10 PM: ​
2:08:10 PM:   Properly caching the binary will fix this error and avoid downloading and unzipping Cypress.
2:08:10 PM: ​
2:08:10 PM:   Alternatively, you can run 'cypress install' to download the binary again.

I've tried with and without CYPRESS_CACHE_FOLDER in the [build.enviroment] netlify toml section.

My netlify toml looks like this:

[build]
  base = ""
  functions = "functions"
  publish = "public/"
  command = "yarn build && yarn build:functions"

[[plugins]]
  package = "netlify-plugin-cypress"
    [plugins.inputs]
      record = true

Installed cypress via yarn add -D cypress.

quantizor avatar Jul 16 '20 18:07 quantizor

Was missing installing the plugin itself as well as a node dependency. I think some of the blogs forget to mention that step

quantizor avatar Jul 16 '20 19:07 quantizor

^^ I was having the same drama.

To be clear. on the solution, I had to install netlify-plugin-cypres in the root of the project.

SimeonUnder2 avatar Aug 04 '20 14:08 SimeonUnder2