You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
👋 @belgattitude, posting a question here in case you have insights around the "Linking dependencies" phase of yarn install. I've gone through tons of GH issues + docs, and don't have a good sense of how this works.
I have a monorepo with about 70 packages in it. A cold yarn install takes about 5 minutes on CI, and the bulk of that time is spent in "Linking dependencies" (3 minutes).
I'm attempting to build a Docker image to run my GitHub Actions jobs in, which contains a prewarmed cache of:
all node_modules folders in the monorepo
the NPM global cache folder
the .yarn/install-state.gz
We commit the .yarn/cache folder with the package .zip files as part of Yarn zero-installs, so I don't need to cache those, as they'll be there when I git clone the monorepo in CI.
The problem
My issue is that when I restore these caches in the Docker image when running GitHub Actions CI, the yarn install process relinks the dependencies, which means any libraries that have to compile against C libraries get rebuilt.
I get output like this, and the Linking dependencies phase takes around 3 minutes to run every time:
➤ YN0008: │ @datadog/native-appsec@npm:3.2.0 must be rebuilt because its dependency tree changed
➤ YN0008: │ @datadog/native-metrics@npm:2.0.0 must be rebuilt because its dependency tree changed
➤ YN0008: │ @datadog/pprof@npm:3.1.0 must be rebuilt because its dependency tree changed
➤ YN0008: │ protobufjs@npm:7.2.4 must be rebuilt because its dependency tree changed
➤ YN0008: │ sharp@npm:0.32.6 must be rebuilt because its dependency tree changed
➤ YN0008: │ core-js@npm:3.22.5 must be rebuilt because its dependency tree changed
➤ YN0008: │ core-js-pure@npm:3.22.5 must be rebuilt because its dependency tree changed
➤ YN0008: │ nodemon@npm:2.0.16 must be rebuilt because its dependency tree changed
➤ YN0008: │ esbuild@npm:0.19.2 must be rebuilt because its dependency tree changed
My expectation
The Linking dependencies phase should be instant, because we restored cache.
My questions
Is it possible to avoid recompiling these libraries?
Am I missing some obvious flags or cache folders here?
My docker setup
My main scheme for setting up the Docker images is to:
copy the git repo over
run yarn install
save off all the artifacts
# Copy the whole git repo over and yarn install, it's the easiest way to generate all the node_modules/etc folders.
COPY . ./
RUN yarn install --immutable --inline-builds
# Recursively tar up the node_modules directory
RUN fd -0 -t d node_modules | tar --zstd -cf /build-artifacts/node_modules_archive.tar.zst --null -T -
# Copy over the yarn install state
RUN cp .yarn/install-state.gz /build-artifacts/yarn-install-state.gz
# Copy over the NPM global cache folder
RUN cd $(npm config get cache) && tar --zstd -cf /build-artifacts/npm_global_cache.tar.zst *
My composite yarn install action
Taking some inspiration from your composite action, this just grabs all the cache artifacts and tries to untar them back into place:
name: "fast monorepo yarn install"description: | Our base CI image contains prebaked npm + yarn + node_modules caches inside an artifacts directory. This shared action will: - Set up all the caches from the artifacts directory - Run `yarn install --immutable` to resolve any drift This action _will_ get slower over time as we add more packages to yarn, so rebuilding the base CI image every so often to resolve package drift is advised.runs:
using: compositesteps:
- name: Find the NPM global cache directoryid: npm-configshell: bashrun: | echo "NPM_GLOBAL_CACHE_FOLDER=$(npm config get cache)" >> $GITHUB_OUTPUT
- name: Move yarn install state into placeshell: bashrun: | mv /build-artifacts/yarn-install-state.gz .yarn/install-state.gz
- name: Unpack npm global cacheshell: bashrun: | mkdir -p "${{ steps.npm-config.outputs.NPM_GLOBAL_CACHE_FOLDER }}" tar xf /build-artifacts/npm_global_cache.tar.zst -C "${{ steps.npm-config.outputs.NPM_GLOBAL_CACHE_FOLDER }}"
- name: Unpack recursive node_modules cache directly into the monoreposhell: bashrun: | tar xf /build-artifacts/node_modules_archive.tar.zst -C .
- name: Run yarn installshell: bashrun: | yarn install --immutable --inline-buildsenv:
# Use local cache folder to keep downloaded archivesYARN_ENABLE_GLOBAL_CACHE: "false"# Reduce node_modules sizeYARN_NM_MODE: "hardlinks-local"# Ensure we're using the local repo's cacheYARN_CACHE_FOLDER: ".yarn/cache"
Anyways, if you have any quick insights about this, I'd be super curious to hear them!
The text was updated successfully, but these errors were encountered:
dbalatero
changed the title
question: How to prevent Linking dependencies
question: How to prevent yarn's Linking dependencies always running in CI
Feb 8, 2024
This makes me think that somehow, lockFileChecksum is different between when I make the Docker image, and when I actually run the GitHub Action in CI inside the Docker image.
👋 @belgattitude, posting a question here in case you have insights around the "Linking dependencies" phase of
yarn install
. I've gone through tons of GH issues + docs, and don't have a good sense of how this works.I have a monorepo with about 70 packages in it. A cold
yarn install
takes about 5 minutes on CI, and the bulk of that time is spent in "Linking dependencies" (3 minutes).I'm attempting to build a Docker image to run my GitHub Actions jobs in, which contains a prewarmed cache of:
node_modules
folders in the monorepo.yarn/install-state.gz
We commit the
.yarn/cache
folder with the package.zip
files as part of Yarn zero-installs, so I don't need to cache those, as they'll be there when Igit clone
the monorepo in CI.The problem
My issue is that when I restore these caches in the Docker image when running GitHub Actions CI, the
yarn install
process relinks the dependencies, which means any libraries that have to compile against C libraries get rebuilt.I get output like this, and the
Linking dependencies
phase takes around 3 minutes to run every time:My expectation
The
Linking dependencies
phase should be instant, because we restored cache.My questions
My docker setup
My main scheme for setting up the Docker images is to:
yarn install
My composite yarn install action
Taking some inspiration from your composite action, this just grabs all the cache artifacts and tries to
untar
them back into place:Anyways, if you have any quick insights about this, I'd be super curious to hear them!
The text was updated successfully, but these errors were encountered: