CircleCI-Public / node-orb

An orb for working with Node.js on CircleCI
https://circleci.com/orbs/registry/orb/circleci/node
MIT License
54 stars 81 forks source link

Include CPU architecture in nvm cache key #237

Open jeremiewtd opened 1 month ago

jeremiewtd commented 1 month ago

Orb version: 6.3.0

What happened:

Every executor using the node orb are sharing the same cache no matter what CPU architecture is it : amd or arm. It causes them to always use the same node binary instead of using the one for the CPU arch. So, for the "bad" arch, it always download node instead of using cache because the version in cache is not the good one for it.

For instance this job is running on macOS M1 and get cache from a linux amd job :

Found a cache from build 63049 at nvm-v1-cache-20
Size: 70 MiB
Cached paths:
  * /home/circleci/.nvm/.cache
  * /opt/circleci/.nvm/.cache

Downloading cache archive...
Validating cache...
Download duration for cache file /var/folders/00/9j8kyjwn2cdcdnlxlcpqr5gh0000gn/T/cache65040814: 1.295565458s

Unarchiving cache...
Skipping writing "opt/circleci/.nvm/.cache/" - mkdir /opt/circleci: permission denied
Skipping writing "opt/circleci/.nvm/.cache/bin/" - mkdir /opt/circleci: permission denied
Skipping writing "opt/circleci/.nvm/.cache/bin/node-v18.15.0-linux-x64/" - mkdir /opt/circleci: permission denied
Skipping writing "opt/circleci/.nvm/.cache/bin/node-v18.15.0-linux-x64/node-v18.15.0-linux-x64.tar.xz" - mkdir /opt/circleci: permission denied
Skipping writing "opt/circleci/.nvm/.cache/bin/node-v19.8.1-linux-x64/" - mkdir /opt/circleci: permission denied
Skipping writing "opt/circleci/.nvm/.cache/bin/node-v19.8.1-linux-x64/node-v19.8.1-linux-x64.tar.xz" - mkdir /opt/circleci: permission denied
Skipping writing "opt/circleci/.nvm/.cache/bin/node-v20.18.0-linux-x64/" - mkdir /opt/circleci: permission denied
Skipping writing "opt/circleci/.nvm/.cache/bin/node-v20.18.0-linux-x64/node-v20.18.0-linux-x64.tar.xz" - mkdir /opt/circleci: permission denied
Unable to set permissions on "/opt/circleci/.nvm/.cache" - chmod /opt/circleci/.nvm/.cache: no such file or directory
Unable to set permissions on "/opt/circleci/.nvm/.cache/bin" - chmod /opt/circleci/.nvm/.cache/bin: no such file or directory
Unable to set permissions on "/opt/circleci/.nvm/.cache/bin/node-v18.15.0-linux-x64" - chmod /opt/circleci/.nvm/.cache/bin/node-v18.15.0-linux-x64: no such file or directory
Unable to set permissions on "/opt/circleci/.nvm/.cache/bin/node-v19.8.1-linux-x64" - chmod /opt/circleci/.nvm/.cache/bin/node-v19.8.1-linux-x64: no such file or directory
Unable to set permissions on "/opt/circleci/.nvm/.cache/bin/node-v20.18.0-linux-x64" - chmod /opt/circleci/.nvm/.cache/bin/node-v20.18.0-linux-x64: no such file or directory
Extraction duration for nvm-v1-cache-20: 38.799792ms

Expected behavior:

Each CPU architecture has its own cache key so that it gets the correct node binary for it.

Thank you

marboledacci commented 1 month ago

Hello @jeremiewtd, we are considering if this should be added to the orb by default or not. You can achieve the expected behavior changing the nvm-cache-key parameter, you can either specify an executor or use {{ arch }}:

- node/install:
          node-version: "20"
          nvm-cache-key: {{ arch }}
jeremiewtd commented 1 month ago

Why this should not be added? It doesn't work as expected without this

marboledacci commented 1 month ago

Hi @jeremiewtd, while adding this specific parameter to the cache is unlikely to cause issues, in this case is easier to solve on user side with the example I showed. Adding too many defaults to the cache key might lead to a situation where it's not suitable for everyone. I have a draft for this #238, but right now is faster to add the key yourself.

jeremiewtd commented 1 month ago

OK thank you, although I still don't understand why 🙂