Page MenuHomePhabricator

[QB] Build fails on EACCESS issues
Closed, ResolvedPublic

Description

After updating netlify in Query Builder in: change 1053249, the test build seems to fail during the installation phase on an EACCESS error. See: https://integration.wikimedia.org/ci/job/generic-node20-browser/454/console

Namely, the following error appears:

00:01:21.481 npm ERR! sharp: Please see https://sharp.pixelplumbing.com/install for required dependencies
16:50 00:01:21.482 npm ERR! sharp: Installation error: EACCES: permission denied, mkdir '/nonexistent/.npm'

This might be due to the fact that the sharp package is trying to access the npm cache but is not using the XDG_CACHE_HOME variable.

Event Timeline

sharp installs libvips and the code defines the cache using:

const cachePath = function () {
  const npmCachePath = env.npm_config_cache || /* istanbul ignore next */
    (env.APPDATA ? path.join(env.APPDATA, 'npm-cache') : path.join(os.homedir(), '.npm'));
  mkdirSync(npmCachePath);
  const libvipsCachePath = path.join(npmCachePath, '_libvips');
  mkdirSync(libvipsCachePath);
  return libvipsCachePath;
};

That npm_config_cache environment variable should be exposed by npm from the its cache setting. Using Fresh we have:

$ npm config list
; "env" config from environment

cache = "/cache" 
update-notifier = false 

That is because the CI images have XDG_CACHE_HOME=/cache.

On https://github.com/yarnpkg/yarn/issues/1632 , there is an explanation from 2016 about that npm_config_:

Configuration parameters are put in the environment with the npm_config_ prefix. For instance, you can view the effective root config by checking the npm_config_root environment variable.

And surely if I try:

"scripts": {
    "foo": "node -p process.env.npm_config_cache"
}

There is no such environment variable, however printing the whole env I see:

NPM_CONFIG_cache: '/cache',
NPM_CONFIG_update_notifier: 'false',

Those are the config from the environment. All the other ones are in all lower case:

  npm_config_user_agent: 'npm/9.8.0 node/v20.5.0 linux x64 workspaces/false',
  npm_node_execpath: '/usr/bin/node',
  npm_config_noproxy: '',
  npm_package_json: '/query-builder/package.json',
....

While the sharp caching system expects npm_config_cache our CI have npm exposes NPM_CONFIG_cache and the code end up falling back to use the non existent home directory.

After digging into the npm code I eventually found the mixed cased comes from the Docker images!!!

dockerfiles/node18-test/Dockerfile.template:ENV NPM_CONFIG_cache=$XDG_CACHE_HOME
dockerfiles/node18-test/Dockerfile.template:ENV NPM_CONFIG_update_notifier=false
dockerfiles/node20-test/Dockerfile.template:ENV NPM_CONFIG_cache=$XDG_CACHE_HOME
dockerfiles/node20-test/Dockerfile.template:ENV NPM_CONFIG_update_notifier=false
dockerfiles/node22-test/Dockerfile.template:ENV NPM_CONFIG_cache=$XDG_CACHE_HOME
dockerfiles/node22-test/Dockerfile.template:ENV NPM_CONFIG_update_notifier=false

That got carried over since January 2019 change https://gerrit.wikimedia.org/r/c/integration/config/+/482527/12/dockerfiles/node10-test/Dockerfile.template (that is for T212602 which is when we implemented not writing to HOME).

Why are they in mixed case? I have no idea but I guess we can change them to be all lower case.

Change #1055257 had a related patch set uploaded (by Hashar; author: Hashar):

[integration/config@master] dockerfiles: change NPM_CONFIG_cache to all lower case

https://gerrit.wikimedia.org/r/1055257

Change #1055257 merged by jenkins-bot:

[integration/config@master] dockerfiles: change NPM_CONFIG_cache to all lower case

https://gerrit.wikimedia.org/r/1055257

Change #1055429 had a related patch set uploaded (by Hashar; author: Hashar):

[integration/config@master] jjb: switch jobs to set NPM_CONFIG_cache to lower case

https://gerrit.wikimedia.org/r/1055429

Interestingly that would have been fixed byhaving HOME=/tmp (T365871) but https://gerrit.wikimedia.org/r/c/integration/config/+/1037453 did not update all the jobs ;/

I have updated the two jobs triggered by wikidata/query-builder and did a recheck on https://gerrit.wikimedia.org/r/c/wikidata/query-builder/+/1053249 : that has fixed the build issue \o/

Change #1055429 merged by jenkins-bot:

[integration/config@master] jjb: switch jobs to set NPM_CONFIG_cache to lower case

https://gerrit.wikimedia.org/r/1055429