Skip to content

feat(node): install Corepack and centralize package-manager caches - #303

Open
vladfrangu wants to merge 3 commits into
masterfrom
feat/corepack-pkg-cache
Open

feat(node): install Corepack and centralize package-manager caches#303
vladfrangu wants to merge 3 commits into
masterfrom
feat/corepack-pkg-cache

Conversation

@vladfrangu

Copy link
Copy Markdown
Member

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/npm
    • YARN_CACHE_FOLDER / YARN_GLOBAL_FOLDER=/pkg-cache/yarn
    • PNPM_CONFIG_STORE_DIR=/pkg-cache/pnpm/store, PNPM_CONFIG_CACHE_DIR=/pkg-cache/pnpm/cache

    The tree is pre-created and world-writable (777), so whatever user the Actor runs as can populate it — and rm -rf /pkg-cache at the end of a build to reclaim space, since it only ever holds throwaway cache data.

  • Symlink the default npm cache dirs (/root/.npm and /home/myuser/.npm) to /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.

  • Force node_modules-style installs for the alternative package managers: PNPM_CONFIG_NODE_LINKER=hoisted (no symlinked store layout) and YARN_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=cache on /pkg-cache, tmpfs mounts), and Corepack makes yarn/pnpm first-class without users hacking it into their Dockerfiles.

Verification

Built apify/actor-node:24 locally from this branch and checked inside the image:

  • /root/.npm and /home/myuser/.npm/pkg-cache/npm; npm config get cache/pkg-cache/npm
  • corepack --version works; yarn Berry resolves nodeLinker=node-modules and cacheFolder=/pkg-cache/yarn/cache; pnpm resolves node-linker=hoisted and store-dir=/pkg-cache/pnpm/store
  • rm -r ~/.npm as myuser succeeds (template compatibility)

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.
@github-actions github-actions Bot added this to the 146th sprint - Tooling team milestone Aug 4, 2026
@github-actions github-actions Bot added the t-tooling Issues with this label are in the ownership of the tooling team. label Aug 4, 2026
@vladfrangu vladfrangu added the adhoc Ad-hoc unplanned task added during the sprint. label Aug 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

adhoc Ad-hoc unplanned task added during the sprint. t-tooling Issues with this label are in the ownership of the tooling team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants