From 849654b78275823a44889c2bc80335c9a6910e79 Mon Sep 17 00:00:00 2001 From: galargh Date: Thu, 5 Sep 2024 17:28:57 +0200 Subject: [PATCH] fix: interact with aws only using the CLI --- hole-punch-interop/helpers/cache.ts | 25 ++++++++++--------------- transport-interop/helpers/cache.ts | 25 ++++++++++--------------- 2 files changed, 20 insertions(+), 30 deletions(-) diff --git a/hole-punch-interop/helpers/cache.ts b/hole-punch-interop/helpers/cache.ts index c88631f56..829e54436 100755 --- a/hole-punch-interop/helpers/cache.ts +++ b/hole-punch-interop/helpers/cache.ts @@ -79,10 +79,11 @@ async function loadCacheOrBuild(dir: string, ig: Ignore) { if (!AWS_BUCKET) { throw new Error("AWS_BUCKET not set") } - const res = await fetch(`https://s3.amazonaws.com/${AWS_BUCKET}/imageCache/${cacheKey}-${arch}.tar.gz`, {method: "HEAD"}) - if (res.ok) { + try { + child_process.execSync(`aws s3 ls s3://${AWS_BUCKET}/imageCache/${cacheKey}-${arch}.tar.gz`) console.log("Cache already exists") - } else { + } catch (e) { + console.log("Cache doesn't exist", e) // Read image id from image.json const imageID = JSON.parse(fs.readFileSync(path.join(dir, 'image.json')).toString()).imageID; console.log(`Pushing cache for ${dir}: ${imageID}`) @@ -102,18 +103,12 @@ async function loadCacheOrBuild(dir: string, ig: Ignore) { if (!AWS_BUCKET) { throw new Error("AWS_BUCKET not set") } - // Check if the cache exists - const res = await fetch(`https://s3.amazonaws.com/${AWS_BUCKET}/imageCache/${cacheKey}-${arch}.tar.gz`, {method: "HEAD"}) - if (res.ok) { - const dockerLoadedMsg = child_process.execSync(`curl https://s3.amazonaws.com/${AWS_BUCKET}/imageCache/${cacheKey}-${arch}.tar.gz | docker image load`).toString(); - const loadedImageId = dockerLoadedMsg.match(/Loaded image( ID)?: (.*)/)[2]; - if (loadedImageId) { - console.log(`Cache hit for ${loadedImageId}`); - fs.writeFileSync(path.join(dir, 'image.json'), JSON.stringify({imageID: loadedImageId}) + "\n"); - cacheHit = true - } - } else { - console.log("Cache not found") + const dockerLoadedMsg = child_process.execSync(`aws s3 cp https://s3.amazonaws.com/${AWS_BUCKET}/imageCache/${cacheKey}-${arch}.tar.gz - | docker image load`).toString(); + const loadedImageId = dockerLoadedMsg.match(/Loaded image( ID)?: (.*)/)[2]; + if (loadedImageId) { + console.log(`Cache hit for ${loadedImageId}`); + fs.writeFileSync(path.join(dir, 'image.json'), JSON.stringify({imageID: loadedImageId}) + "\n"); + cacheHit = true } } catch (e) { console.log("Cache not found:", e) diff --git a/transport-interop/helpers/cache.ts b/transport-interop/helpers/cache.ts index 80d284d4e..ea9297133 100755 --- a/transport-interop/helpers/cache.ts +++ b/transport-interop/helpers/cache.ts @@ -68,10 +68,11 @@ switch (modeStr) { if (!AWS_BUCKET) { throw new Error("AWS_BUCKET not set") } - const res = await fetch(`https://s3.amazonaws.com/${AWS_BUCKET}/imageCache/${cacheKey}-${arch}.tar.gz`, { method: "HEAD" }) - if (res.ok) { + try { + child_process.execSync(`aws s3 ls s3://${AWS_BUCKET}/imageCache/${cacheKey}-${arch}.tar.gz`) console.log("Cache already exists") - } else { + } catch (e) { + console.log("Cache doesn't exist", e) // Read image id from image.json const imageID = JSON.parse(fs.readFileSync(path.join(implFolder, 'image.json')).toString()).imageID; console.log(`Pushing cache for ${impl}: ${imageID}`) @@ -91,18 +92,12 @@ switch (modeStr) { if (!AWS_BUCKET) { throw new Error("AWS_BUCKET not set") } - // Check if the cache exists - const res = await fetch(`https://s3.amazonaws.com/${AWS_BUCKET}/imageCache/${cacheKey}-${arch}.tar.gz`, { method: "HEAD" }) - if (res.ok) { - const dockerLoadedMsg = child_process.execSync(`curl https://s3.amazonaws.com/${AWS_BUCKET}/imageCache/${cacheKey}-${arch}.tar.gz | docker image load`).toString(); - const loadedImageId = dockerLoadedMsg.match(/Loaded image( ID)?: (.*)/)[2]; - if (loadedImageId) { - console.log(`Cache hit for ${loadedImageId}`); - fs.writeFileSync(path.join(implFolder, 'image.json'), JSON.stringify({ imageID: loadedImageId }) + "\n"); - cacheHit = true - } - } else { - console.log("Cache not found") + const dockerLoadedMsg = child_process.execSync(`aws s3 cp https://s3.amazonaws.com/${AWS_BUCKET}/imageCache/${cacheKey}-${arch}.tar.gz - | docker image load`).toString(); + const loadedImageId = dockerLoadedMsg.match(/Loaded image( ID)?: (.*)/)[2]; + if (loadedImageId) { + console.log(`Cache hit for ${loadedImageId}`); + fs.writeFileSync(path.join(implFolder, 'image.json'), JSON.stringify({ imageID: loadedImageId }) + "\n"); + cacheHit = true } } catch (e) { console.log("Cache not found:", e)