Do build plugins utilizing caching work on deploy previews?

Site: https://rhythm-storybook.netlify.app/
Deploy Preview: https://5efcf9e840acdd00081536cd--rhythm-storybook.netlify.app/

I wrote a custom build plugin that makes use of caching. No matter what I try, I can’t get the cache to persist across builds. I’m doing all this in a PR on the respective site repo, so perhaps there’s something non-obvious about how caching works with Deploy Previews versus regular deploys? I have the plugin logging during the build that it doesn’t find any cached files at the beginning. It successfully caches files at the end. But when I run another Deploy Preview on this PR, it says there’s nothing in the cache when the build starts.

Below is the build output (buckle up, it’s pretty long). In it you can see that the caching plugin finds no files at the beginning and it successfully stores cache files at the end.

5:02:32 PM: Build ready to start
5:02:34 PM: build-image version: 9d79ad851d6eff3969322d6e5b1df3d597650c41
5:02:34 PM: build-image tag: v3.3.19
5:02:34 PM: buildbot version: a18bb8977e4573e865387a20170d78af34188321
5:02:34 PM: Fetching cached dependencies
5:02:34 PM: Starting to download cache of 718.8MB
5:02:59 PM: Finished downloading cache in 25.453552085s
5:02:59 PM: Starting to extract cache
5:03:41 PM: Finished extracting cache in 41.512211824s
5:03:41 PM: Finished fetching cache in 1m7.147723159s
5:03:41 PM: Starting to prepare the repo for build
5:03:42 PM: Preparing Git Reference pull/977/head
5:03:45 PM: Different build command detected, going to use the one specified in the Netlify configuration file: './.config/netlify.sh' versus '.config/netlify.sh' in the Netlify UI
5:03:45 PM: Starting build script
5:03:45 PM: Installing dependencies
5:03:45 PM: Python version set to 2.7
5:03:46 PM: Started restoring cached node version
5:03:49 PM: Finished restoring cached node version
5:03:49 PM: Attempting node version '12.14.1' from .node-version
5:03:50 PM: v12.14.1 is already installed.
5:03:51 PM: Now using node v12.14.1 (npm v6.13.4)
5:03:51 PM: Started restoring cached build plugins
5:03:51 PM: Finished restoring cached build plugins
5:03:51 PM: Attempting ruby version 2.3.6, read from environment
5:03:52 PM: Started restoring cached ruby version
5:03:52 PM: Finished restoring cached ruby version
5:03:54 PM: Using ruby version 2.3.6
5:03:55 PM: Successfully installed bundler-2.1.4
5:03:55 PM: 1 gem installed
5:03:55 PM: Using PHP version 5.6
5:03:55 PM: 5.2 is already installed.
5:03:55 PM: Using Swift version 5.2
5:03:55 PM: Started restoring cached node modules
5:03:55 PM: Finished restoring cached node modules
5:03:55 PM: Started restoring cached go cache
5:03:57 PM: Finished restoring cached go cache
5:03:57 PM: Installing Go version 1.10
5:03:57 PM: unset GOOS;
5:03:57 PM: unset GOARCH;
5:03:57 PM: export GOROOT='/opt/buildhome/.gimme_cache/versions/go1.10.linux.amd64';
5:03:57 PM: export PATH="/opt/buildhome/.gimme_cache/versions/go1.10.linux.amd64/bin:${PATH}";
5:03:57 PM: go version >&2;
5:03:57 PM: export GIMME_ENV='/opt/buildhome/.gimme_cache/env/go1.10.linux.amd64.env';
5:03:57 PM: go version go1.10 linux/amd64
5:03:57 PM: Installing missing commands
5:03:57 PM: Verify run directory
5:03:59 PM: ​
5:03:59 PM: ┌─────────────────────────────┐
5:03:59 PM: │        Netlify Build        │
5:03:59 PM: └─────────────────────────────┘
5:03:59 PM: ​
5:03:59 PM: ❯ Version
5:03:59 PM:   @netlify/build 2.0.25
5:03:59 PM: ​
5:03:59 PM: ❯ Flags
5:03:59 PM:   deployId: 5efcf9e840acdd00081536cd
5:03:59 PM:   mode: buildbot
5:03:59 PM: ​
5:03:59 PM: ❯ Current directory
5:03:59 PM:   /opt/build/repo
5:03:59 PM: ​
5:03:59 PM: ❯ Config file
5:03:59 PM:   /opt/build/repo/netlify.toml
5:03:59 PM: ​
5:03:59 PM: ❯ Context
5:03:59 PM:   deploy-preview
5:03:59 PM: ​
5:03:59 PM: ❯ Loading plugins
5:03:59 PM:    - ./.config/netlify/netlify-plugin-repo-cache@0.0.0 from netlify.toml
5:03:59 PM: ​
5:03:59 PM: ┌────────────────────────────────────────────────────────────────────────┐
5:03:59 PM: │ 1. onPreBuild command from ./.config/netlify/netlify-plugin-repo-cache │
5:03:59 PM: └────────────────────────────────────────────────────────────────────────┘
5:03:59 PM: ​
5:03:59 PM: Cached files []
5:03:59 PM: No repo caches found. Building fresh.
5:03:59 PM: ​
5:03:59 PM: (./.config/netlify/netlify-plugin-repo-cache onPreBuild completed in 236ms)
5:03:59 PM: ​
5:03:59 PM: ┌────────────────────────────────────┐
5:03:59 PM: │ 2. build.command from netlify.toml │
5:03:59 PM: └────────────────────────────────────┘
5:03:59 PM: ​
5:03:59 PM: $ ./.config/netlify.sh

... OMITTED SO I CAN CREATE THE TOPIC

5:14:28 PM: (build.command completed in 10m 29.3s)
5:14:28 PM: ​
5:14:28 PM: ┌─────────────────────────────────────────────────────────────────────────┐
5:14:28 PM: │ 3. onPostBuild command from ./.config/netlify/netlify-plugin-repo-cache │
5:14:28 PM: └─────────────────────────────────────────────────────────────────────────┘
5:14:28 PM: ​
5:14:28 PM: [ 'node_modules/.cache', 'common/temp' ]
5:14:28 PM: [
5:14:28 PM:   [ 'storybook', 'terser-webpack-plugin' ],
5:14:28 PM:   [
5:14:28 PM:     '.npmrc',
5:14:28 PM:     'current-variant.json',
5:14:28 PM:     'install-run',
5:14:28 PM:     'last-install.flag',
5:14:28 PM:     'node_modules',
5:14:28 PM:     'package.json',
5:14:28 PM:     'pnpm-local',
5:14:28 PM:     'pnpm-store',
5:14:28 PM:     'pnpmfile.js',
5:14:28 PM:     'projects',
5:14:28 PM:     'rush#1523.lock',
5:14:28 PM:     'rush-link.json',
5:14:28 PM:     'shrinkwrap-preinstall.yaml',
5:14:28 PM:     'shrinkwrap.yaml'
5:14:28 PM:   ]
5:14:28 PM: ]
5:15:25 PM: Cached files [
5:15:25 PM:   '/opt/build/repo/common',
5:15:25 PM:   '/opt/build/repo/node_modules',
5:15:25 PM:   '/opt/build/repo/node_modules/.cache',
5:15:25 PM:   '/opt/build/repo/common/temp'
5:15:25 PM: ]
5:15:25 PM: Stored repo caches to speed up future builds.
5:15:25 PM: ​
5:15:25 PM: (./.config/netlify/netlify-plugin-repo-cache onPostBuild completed in 56.5s)
5:15:25 PM: ​
5:15:25 PM: ┌─────────────────────────────┐
5:15:25 PM: │   Netlify Build Complete    │
5:15:25 PM: └─────────────────────────────┘
5:15:25 PM: ​
5:15:25 PM: (Netlify Build completed in 11m 26.4s)
5:15:25 PM: Caching artifacts
5:15:25 PM: Started saving node modules
5:15:25 PM: Finished saving node modules
5:15:25 PM: Started saving build plugins
5:15:25 PM: Finished saving build plugins
5:15:25 PM: Started saving pip cache
5:15:25 PM: Finished saving pip cache
5:15:25 PM: Started saving emacs cask dependencies
5:15:25 PM: Finished saving emacs cask dependencies
5:15:25 PM: Started saving maven dependencies
5:15:25 PM: Finished saving maven dependencies
5:15:25 PM: Started saving boot dependencies
5:15:25 PM: Finished saving boot dependencies
5:15:25 PM: Started saving go dependencies
5:15:27 PM: Finished saving go dependencies
5:15:27 PM: Build script success
5:15:27 PM: Starting to deploy site from 'storybook-static'
5:15:27 PM: Creating deploy tree 
5:15:28 PM: Creating deploy upload records
5:15:28 PM: 7 new files to upload
5:15:28 PM: 0 new functions to upload
5:15:30 PM: Starting post processing
5:15:30 PM: Post processing done
5:15:30 PM: Site is live
5:21:13 PM: Finished processing build request in 18m39.39000808s
1 Like

Any thoughts on this?

You may want to check out how other cachers are doing it :slight_smile: