From b114c78d1d6c892e039217b4e7f1eb9a1d0e70dc Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Thu, 26 Oct 2023 16:31:53 +1100 Subject: [PATCH 1/5] Sort functions by usage --- hole-punch-interop/versions.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/hole-punch-interop/versions.ts b/hole-punch-interop/versions.ts index 12e588365..e2e0f8e73 100644 --- a/hole-punch-interop/versions.ts +++ b/hole-punch-interop/versions.ts @@ -15,6 +15,15 @@ export const versions: Array = [ }, ].map((v: Version) => (typeof v.containerImageID === "undefined" ? ({ ...v, containerImageID: canonicalImageIDLookup(v.id) }) : v)) +// Loads the container image id for the given version id. Expects the form of +// "-vX.Y.Z" or "vX.Y" and the image id to be in the file +// "./impl//vX.Y/image.json" or "./impl//v0.0.Z/image.json" +function canonicalImageIDLookup(id: string): string { + const imageIDJSON = fs.readFileSync(canonicalImagePath(id), "utf8") + const imageID = JSON.parse(imageIDJSON).imageID + return imageID +} + function canonicalImagePath(id: string): string { // Split by implementation and version const [impl, version] = id.split("-v") @@ -28,12 +37,3 @@ function canonicalImagePath(id: string): string { // Read the image ID from the JSON file on the filesystem return `./impl/${impl}/${versionFolder}/image.json` } - -// Loads the container image id for the given version id. Expects the form of -// "-vX.Y.Z" or "vX.Y" and the image id to be in the file -// "./impl//vX.Y/image.json" or "./impl//v0.0.Z/image.json" -function canonicalImageIDLookup(id: string): string { - const imageIDJSON = fs.readFileSync(canonicalImagePath(id), "utf8") - const imageID = JSON.parse(imageIDJSON).imageID - return imageID -} From ade3441bed4fc30086cb291d59a4609af179c155 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Thu, 26 Oct 2023 16:33:31 +1100 Subject: [PATCH 2/5] Extract helper --- hole-punch-interop/versions.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/hole-punch-interop/versions.ts b/hole-punch-interop/versions.ts index e2e0f8e73..18070d39b 100644 --- a/hole-punch-interop/versions.ts +++ b/hole-punch-interop/versions.ts @@ -19,9 +19,11 @@ export const versions: Array = [ // "-vX.Y.Z" or "vX.Y" and the image id to be in the file // "./impl//vX.Y/image.json" or "./impl//v0.0.Z/image.json" function canonicalImageIDLookup(id: string): string { - const imageIDJSON = fs.readFileSync(canonicalImagePath(id), "utf8") - const imageID = JSON.parse(imageIDJSON).imageID - return imageID + return readImageId(canonicalImagePath(id)) +} + +function readImageId(path: string) { + return JSON.parse(fs.readFileSync(path, "utf8")).imageID; } function canonicalImagePath(id: string): string { From bf8a84a876fa1b37ee37226d3634f9449ee7f42d Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Thu, 26 Oct 2023 16:34:40 +1100 Subject: [PATCH 3/5] Make functions more modular --- hole-punch-interop/versions.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/hole-punch-interop/versions.ts b/hole-punch-interop/versions.ts index 18070d39b..5c35d0ecd 100644 --- a/hole-punch-interop/versions.ts +++ b/hole-punch-interop/versions.ts @@ -13,19 +13,16 @@ export const versions: Array = [ id: "rust-v0.52", transports: ["tcp", "quic"], }, -].map((v: Version) => (typeof v.containerImageID === "undefined" ? ({ ...v, containerImageID: canonicalImageIDLookup(v.id) }) : v)) - -// Loads the container image id for the given version id. Expects the form of -// "-vX.Y.Z" or "vX.Y" and the image id to be in the file -// "./impl//vX.Y/image.json" or "./impl//v0.0.Z/image.json" -function canonicalImageIDLookup(id: string): string { - return readImageId(canonicalImagePath(id)) -} +].map((v: Version) => (typeof v.containerImageID === "undefined" ? ({ ...v, containerImageID: readImageId(canonicalImagePath(v.id)) }) : v)) function readImageId(path: string) { return JSON.parse(fs.readFileSync(path, "utf8")).imageID; } +// Finds the `image.json` for the given version id. +// +// Expects the form of "-vX.Y.Z" or "vX.Y". +// The image id must be in the file "./impl//vX.Y/image.json" or "./impl//v0.0.Z/image.json". function canonicalImagePath(id: string): string { // Split by implementation and version const [impl, version] = id.split("-v") From 9811a60bcd531e13f51766f8c6f4b8093c7616f5 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Thu, 26 Oct 2023 16:37:44 +1100 Subject: [PATCH 4/5] Update and rename `v0.52` to `master` --- hole-punch-interop/impl/rust/{v0.52 => master}/Makefile | 4 ++-- hole-punch-interop/versions.ts | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) rename hole-punch-interop/impl/rust/{v0.52 => master}/Makefile (87%) diff --git a/hole-punch-interop/impl/rust/v0.52/Makefile b/hole-punch-interop/impl/rust/master/Makefile similarity index 87% rename from hole-punch-interop/impl/rust/v0.52/Makefile rename to hole-punch-interop/impl/rust/master/Makefile index 84233ff13..4e79c39b9 100644 --- a/hole-punch-interop/impl/rust/v0.52/Makefile +++ b/hole-punch-interop/impl/rust/master/Makefile @@ -1,5 +1,5 @@ -image_name := rust-v0.52 -commitSha := 1ead41ed04ce89e50b11a078586e47d89e17d3c4 +image_name := rust-master +commitSha := 7517934a0f629309f83b69dc00eef44c44ddbc72 all: image.json diff --git a/hole-punch-interop/versions.ts b/hole-punch-interop/versions.ts index 5c35d0ecd..609dc89d2 100644 --- a/hole-punch-interop/versions.ts +++ b/hole-punch-interop/versions.ts @@ -10,12 +10,13 @@ export type Version = { export const versions: Array = [ { - id: "rust-v0.52", + id: "rust-master", transports: ["tcp", "quic"], - }, + containerImageID: readImageId("./impl/rust/master/image.json"), + } as Version, ].map((v: Version) => (typeof v.containerImageID === "undefined" ? ({ ...v, containerImageID: readImageId(canonicalImagePath(v.id)) }) : v)) -function readImageId(path: string) { +function readImageId(path: string): string { return JSON.parse(fs.readFileSync(path, "utf8")).imageID; } From 83a93203d8984964fca0a1bb0d86be233d3ba8e5 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Fri, 27 Oct 2023 17:00:58 +1100 Subject: [PATCH 5/5] Update hole-punch-interop/impl/rust/master/Makefile --- hole-punch-interop/impl/rust/master/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hole-punch-interop/impl/rust/master/Makefile b/hole-punch-interop/impl/rust/master/Makefile index 4e79c39b9..437c68a76 100644 --- a/hole-punch-interop/impl/rust/master/Makefile +++ b/hole-punch-interop/impl/rust/master/Makefile @@ -1,5 +1,5 @@ image_name := rust-master -commitSha := 7517934a0f629309f83b69dc00eef44c44ddbc72 +commitSha := 461209ab1ba6b8e2a653ca354a5aad38802a35f9 all: image.json