From 63c608965147aa2e0a93c2025f5a83b2fe90b2dd Mon Sep 17 00:00:00 2001 From: Prajjwal Date: Mon, 15 Apr 2024 16:18:16 +0530 Subject: [PATCH] moves to streaming for gcs --- packages/warp-cache/package.json | 2 +- packages/warp-cache/src/cache.ts | 50 +++++++++---------- .../warp-cache/src/internal/downloadUtils.ts | 3 +- packages/warp-cache/src/test.ts | 16 +++--- 4 files changed, 36 insertions(+), 35 deletions(-) diff --git a/packages/warp-cache/package.json b/packages/warp-cache/package.json index fd5e8b96..55330def 100644 --- a/packages/warp-cache/package.json +++ b/packages/warp-cache/package.json @@ -1,6 +1,6 @@ { "name": "github-actions.warp-cache", - "version": "1.0.6", + "version": "1.1.0", "preview": true, "description": "Github action to use WarpBuild's in-house cache offering", "keywords": [ diff --git a/packages/warp-cache/src/cache.ts b/packages/warp-cache/src/cache.ts index 71cc60dd..b648cf0c 100644 --- a/packages/warp-cache/src/cache.ts +++ b/packages/warp-cache/src/cache.ts @@ -171,39 +171,39 @@ export async function restoreCache( const archiveLocation = `gs://${cacheEntry.gcs?.bucket_name}/${cacheEntry.gcs?.cache_key}` - await cacheHttpClient.downloadCache( - cacheEntry.provider, - archiveLocation, - archivePath, - cacheEntry.gcs?.short_lived_token?.access_token ?? '' - ) + // await cacheHttpClient.downloadCache( + // cacheEntry.provider, + // archiveLocation, + // archivePath, + // cacheEntry.gcs?.short_lived_token?.access_token ?? '' + // ) - if (core.isDebug()) { - await listTar(archivePath, compressionMethod) - } + // if (core.isDebug()) { + // await listTar(archivePath, compressionMethod) + // } - const archiveFileSize = utils.getArchiveFileSizeInBytes(archivePath) - core.info( - `Cache Size: ~${Math.round( - archiveFileSize / (1024 * 1024) - )} MB (${archiveFileSize} B)` - ) + // const archiveFileSize = utils.getArchiveFileSizeInBytes(archivePath) + // core.info( + // `Cache Size: ~${Math.round( + // archiveFileSize / (1024 * 1024) + // )} MB (${archiveFileSize} B)` + // ) - await extractTar(archivePath, compressionMethod) + // await extractTar(archivePath, compressionMethod) // For GCS, we do a streaming download which means that we extract the archive while we are downloading it. - // const readStream = cacheHttpClient.downloadCacheStreaming( - // 'gcs', - // archiveLocation, - // cacheEntry?.gcs?.short_lived_token?.access_token ?? '' - // ) + const readStream = cacheHttpClient.downloadCacheStreaming( + 'gcs', + archiveLocation, + cacheEntry?.gcs?.short_lived_token?.access_token ?? '' + ) - // if (!readStream) { - // return undefined - // } + if (!readStream) { + return undefined + } - // await extractStreamingTar(readStream, archivePath, compressionMethod) + await extractStreamingTar(readStream, archivePath, compressionMethod) core.info('Cache restored successfully') break } diff --git a/packages/warp-cache/src/internal/downloadUtils.ts b/packages/warp-cache/src/internal/downloadUtils.ts index f01734b3..6cebefaf 100644 --- a/packages/warp-cache/src/internal/downloadUtils.ts +++ b/packages/warp-cache/src/internal/downloadUtils.ts @@ -311,7 +311,8 @@ export async function downloadCacheMultipartGCP( const transferManager = new TransferManager(storage.bucket(bucketName)) await transferManager.downloadFileInChunks(objectName, { destination: archivePath, - chunkSizeBytes: 8 * 1024 * 1024 // 8MB chunk size + noReturnData: true, + chunkSizeBytes: 1024 * 1024 * 8 }) } catch (error) { core.debug(`Failed to download cache: ${error}`) diff --git a/packages/warp-cache/src/test.ts b/packages/warp-cache/src/test.ts index 3ae42c69..9620df75 100644 --- a/packages/warp-cache/src/test.ts +++ b/packages/warp-cache/src/test.ts @@ -31,14 +31,14 @@ process.env['GITHUB_REF'] = 'refs/heads/main' // true // ) -// restoreCache( -// ['/Users/prajjwal/Repos/warpbuild/playground/test_fs'], -// 'test-fs-local-key', -// ['test-fs'], -// {}, -// true, -// false -// ) +restoreCache( + ['/Users/prajjwal/Repos/warpbuild/playground/test_fs'], + 'test-fs-local-key', + ['test-fs'], + {}, + true, + false +) // deleteCache( // ['/Users/prajjwal/Repos/warpbuild/playground/test_fs'],