feat(node): install Corepack and centralize package-manager caches - #303
Open
vladfrangu wants to merge 3 commits into
Open
feat(node): install Corepack and centralize package-manager caches#303vladfrangu wants to merge 3 commits into
vladfrangu wants to merge 3 commits into
Conversation
Route npm, yarn, and pnpm caches to a single world-writable /pkg-cache/<pm> tree (out of $HOME) so they can be wiped or tmpfs-mounted to reclaim space, install the latest Corepack globally so Actors can use yarn or pnpm, and make pnpm use the hoisted (npm-style) node_modules layout instead of symlinks. Applies to all built Node images: node, node-playwright(-chrome/-firefox/ -webkit/-camoufox), and node-puppeteer-chrome.
Yarn Berry (what Corepack installs) defaults to Plug'n'Play; set YARN_NODE_LINKER=node-modules so yarn installs produce a plain node_modules tree, matching npm and the hoisted pnpm linker.
npm's default per-user cache lives in ~/.npm. Point /root/.npm and /home/myuser/.npm at /pkg-cache/npm so tooling that bypasses NPM_CONFIG_CACHE still hits the shared cache, and existing templates that run `rm -r ~/.npm` after install keep working.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
All 7 node base images (
node,node-playwright[-chrome/-firefox/-webkit/-camoufox],node-puppeteer-chrome) now:Install Corepack (
npm install -g corepack@latest && corepack enable) so Actors can use yarn or pnpm out of the box.Redirect every package-manager cache to a stable location under
/pkg-cache:NPM_CONFIG_CACHE=/pkg-cache/npmYARN_CACHE_FOLDER/YARN_GLOBAL_FOLDER=/pkg-cache/yarnPNPM_CONFIG_STORE_DIR=/pkg-cache/pnpm/store,PNPM_CONFIG_CACHE_DIR=/pkg-cache/pnpm/cacheThe tree is pre-created and world-writable (
777), so whatever user the Actor runs as can populate it — andrm -rf /pkg-cacheat the end of a build to reclaim space, since it only ever holds throwaway cache data.Symlink the default npm cache dirs (
/root/.npmand/home/myuser/.npm) to/pkg-cache/npm, so tooling that bypassesNPM_CONFIG_CACHEstill hits the shared cache, and existing templates that runrm -r ~/.npmafter install keep working.Force node_modules-style installs for the alternative package managers:
PNPM_CONFIG_NODE_LINKER=hoisted(no symlinked store layout) andYARN_NODE_LINKER=node-modules(yarn Berry would otherwise default to Plug'n'Play).Why
A single, predictable cache location is a prerequisite for dependency-caching strategies (pre-baked caches, BuildKit
--mount=type=cacheon/pkg-cache, tmpfs mounts), and Corepack makes yarn/pnpm first-class without users hacking it into their Dockerfiles.Verification
Built
apify/actor-node:24locally from this branch and checked inside the image:/root/.npmand/home/myuser/.npm→/pkg-cache/npm;npm config get cache→/pkg-cache/npmcorepack --versionworks; yarn Berry resolvesnodeLinker=node-modulesandcacheFolder=/pkg-cache/yarn/cache; pnpm resolvesnode-linker=hoistedandstore-dir=/pkg-cache/pnpm/storerm -r ~/.npmasmyusersucceeds (template compatibility)