( _options: PrepareCacheOptions )
| 24 | * `VERCEL_VCR_DISABLE_LAYER_CACHE=1`. |
| 25 | */ |
| 26 | export async function prepareCache( |
| 27 | _options: PrepareCacheOptions |
| 28 | ): Promise<Files> { |
| 29 | if (process.env.VERCEL_VCR_DISABLE_LAYER_CACHE) { |
| 30 | debug('layer cache disabled (VERCEL_VCR_DISABLE_LAYER_CACHE)'); |
| 31 | return {}; |
| 32 | } |
| 33 | |
| 34 | // The buildah store only exists in the build container. |
| 35 | if (!isBuildContainer()) { |
| 36 | debug('skipping container layer cache (not in build container)'); |
| 37 | return {}; |
| 38 | } |
| 39 | |
| 40 | if (!existsSync(BUILDAH_GRAPH_ROOT)) { |
| 41 | debug(`no buildah store to cache at ${BUILDAH_GRAPH_ROOT}`); |
| 42 | return {}; |
| 43 | } |
| 44 | |
| 45 | const start = Date.now(); |
| 46 | const files = await glob(`${GRAPH_ROOT_REL}/**`, CACHE_ROOT); |
| 47 | const count = Object.keys(files).length; |
| 48 | info( |
| 49 | `cached container layer store: ${count} files from ${BUILDAH_GRAPH_ROOT} ` + |
| 50 | `in ${Date.now() - start}ms` |
| 51 | ); |
| 52 | return files; |
| 53 | } |
no test coverage detected