Less error-prone way of defining image IDs and other quality of life improvements (#208)

* Make canonicalImageIDLookup default

* Fix browser containerImageID
This commit is contained in:
Marco Munizaga 2023-06-29 12:52:13 -07:00 committed by GitHub
parent 42179a6721
commit fd719f534e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 70 additions and 61 deletions

View File

@ -8,10 +8,16 @@ function buildExtraEnv(timeoutOverride: { [key: string]: number }, test1ID: stri
return maxTimeout > 0 ? { "test_timeout_seconds": maxTimeout.toString(10) } : {} return maxTimeout > 0 ? { "test_timeout_seconds": maxTimeout.toString(10) } : {}
} }
export async function buildTestSpecs(versions: Array<Version>): Promise<Array<ComposeSpecification>> { export async function buildTestSpecs(versions: Array<Version>, nameFilter: string | null): Promise<Array<ComposeSpecification>> {
const containerImages: { [key: string]: string } = {} const containerImages: { [key: string]: () => string } = {}
const timeoutOverride: { [key: string]: number } = {} const timeoutOverride: { [key: string]: number } = {}
versions.forEach(v => containerImages[v.id] = v.containerImageID) versions.forEach(v => containerImages[v.id] = () => {
if (typeof v.containerImageID === "string") {
return v.containerImageID
}
return v.containerImageID(v.id)
})
versions.forEach(v => { versions.forEach(v => {
if (v.timeoutSecs) { if (v.timeoutSecs) {
timeoutOverride[v.id] = v.timeoutSecs timeoutOverride[v.id] = v.timeoutSecs
@ -111,7 +117,7 @@ export async function buildTestSpecs(versions: Array<Version>): Promise<Array<Co
muxer: test.muxer, muxer: test.muxer,
security: test.sec, security: test.sec,
extraEnv: buildExtraEnv(timeoutOverride, test.id1, test.id2) extraEnv: buildExtraEnv(timeoutOverride, test.id1, test.id2)
}) }, nameFilter)
)).concat( )).concat(
quicQueryResults quicQueryResults
.concat(quicV1QueryResults) .concat(quicV1QueryResults)
@ -124,17 +130,21 @@ export async function buildTestSpecs(versions: Array<Version>): Promise<Array<Co
listenerID: test.id2, listenerID: test.id2,
transport: test.transport, transport: test.transport,
extraEnv: buildExtraEnv(timeoutOverride, test.id1, test.id2) extraEnv: buildExtraEnv(timeoutOverride, test.id1, test.id2)
}))) }, nameFilter)))
.filter((spec): spec is ComposeSpecification => spec !== null)
return testSpecs return testSpecs
} }
function buildSpec(containerImages: { [key: string]: string }, { name, dialerID, listenerID, transport, muxer, security, extraEnv }: { name: string, dialerID: string, listenerID: string, transport: string, muxer?: string, security?: string, extraEnv?: { [key: string]: string } }): ComposeSpecification { function buildSpec(containerImages: { [key: string]: () => string }, { name, dialerID, listenerID, transport, muxer, security, extraEnv }: { name: string, dialerID: string, listenerID: string, transport: string, muxer?: string, security?: string, extraEnv?: { [key: string]: string } }, nameFilter: string | null): ComposeSpecification | null {
if (nameFilter && !name.includes(nameFilter)) {
return null
}
return { return {
name, name,
services: { services: {
dialer: { dialer: {
image: containerImages[dialerID], image: containerImages[dialerID](),
depends_on: ["redis"], depends_on: ["redis"],
environment: { environment: {
version: dialerID, version: dialerID,
@ -150,7 +160,7 @@ function buildSpec(containerImages: { [key: string]: string }, { name, dialerID,
// Add init process to be PID 1 to proxy signals. Rust doesn't // Add init process to be PID 1 to proxy signals. Rust doesn't
// handle SIGINT without this // handle SIGINT without this
init: true, init: true,
image: containerImages[listenerID], image: containerImages[listenerID](),
depends_on: ["redis"], depends_on: ["redis"],
environment: { environment: {
version: listenerID, version: listenerID,

View File

@ -55,12 +55,12 @@ import path from "path";
extraVersions.push(JSON.parse(contents.toString())) extraVersions.push(JSON.parse(contents.toString()))
} }
let testSpecs = await buildTestSpecs(versions.concat(extraVersions))
const nameFilter = argv["name-filter"] let nameFilter: string | null = argv["name-filter"]
if (nameFilter !== "") { if (nameFilter === "") {
testSpecs = testSpecs.filter((testSpec) => testSpec.name?.includes(nameFilter)) nameFilter = null
} }
let testSpecs = await buildTestSpecs(versions.concat(extraVersions), nameFilter)
if (argv["emit-only"]) { if (argv["emit-only"]) {

View File

@ -1,30 +1,11 @@
import gov028 from "./impl/go/v0.28/image.json" import fs from "fs"
import gov027 from "./impl/go/v0.27/image.json" import path from "path"
import gov026 from "./impl/go/v0.26/image.json"
import gov025 from "./impl/go/v0.25/image.json"
import gov024 from "./impl/go/v0.24/image.json"
import gov023 from "./impl/go/v0.23/image.json"
import gov022 from "./impl/go/v0.22/image.json"
import rustv049 from "./impl/rust/v0.49/image.json"
import rustv050 from "./impl/rust/v0.50/image.json"
import rustv051 from "./impl/rust/v0.51/image.json"
import rustv052 from "./impl/rust/v0.52/image.json"
import jsV041 from "./impl/js/v0.41/node-image.json"
import jsV042 from "./impl/js/v0.42/node-image.json"
import jsV044 from "./impl/js/v0.44/node-image.json"
import jsV045 from "./impl/js/v0.45/image.json"
import nimv10 from "./impl/nim/v1.0/image.json"
import chromiumJsV041 from "./impl/js/v0.41/chromium-image.json"
import chromiumJsV042 from "./impl/js/v0.42/chromium-image.json"
import chromiumJsV044 from "./impl/js/v0.44/chromium-image.json"
import chromiumJsV045 from "./impl/js/v0.45/chromium-image.json"
import firefoxJsV045 from "./impl/js/v0.45/firefox-image.json"
import zigv001 from "./impl/zig/v0.0.1/image.json"
import javav001 from "./impl/java/v0.0.1/image.json"
export type Version = { export type Version = {
id: string, id: string,
containerImageID: string, // This can be the image ID, or a function that takes the version ID and returns the image ID.
// By default it uses the canonicalImageIDLookup.
containerImageID?: string | ((id: string) => string),
// If defined, this will increase the timeout for tests using this version // If defined, this will increase the timeout for tests using this version
timeoutSecs?: number, timeoutSecs?: number,
transports: Array<(string | { name: string, onlyDial: boolean })>, transports: Array<(string | { name: string, onlyDial: boolean })>,
@ -32,166 +13,184 @@ export type Version = {
muxers: string[] muxers: string[]
} }
function canonicalImagePath(id: string): string {
// Split by implementation and version
const [impl, version] = id.split("-v")
// Drop the patch version
const [major, minor, patch] = version.split(".")
let versionFolder = `v${major}.${minor}`
if (major === "0" && minor === "0") {
// We're still in the 0.0.x phase, so we use the patch version
versionFolder = `v0.0.${patch}`
}
// 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
// "<impl>-vX.Y.Z" or "<impl>vX.Y" and the image id to be in the file
// "./impl/<impl>/vX.Y/image.json" or "./impl/<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
}
// Loads the container image id for the given browser version id. Expects the
// form of "<browser>-<impl>-vX.Y.Z" or "<impl>vX.Y" and the image id to be in the file
// "./impl/<impl>/vX.Y/<browser>-image.json" or "./impl/<impl>/v0.0.Z/<browser>-image.json"
function browserImageIDLookup(id: string): string {
const [browser, ...rest] = id.split("-")
const parentDir = path.dirname(canonicalImagePath(rest.join("-")))
// Read the image ID from the JSON file on the filesystem
const imageIDJSON = fs.readFileSync(path.join(parentDir, `${browser}-image.json`), "utf8")
const imageID = JSON.parse(imageIDJSON).imageID
return imageID
}
export const versions: Array<Version> = [ export const versions: Array<Version> = [
{ {
id: "rust-v0.49.0", id: "rust-v0.49.0",
containerImageID: rustv049.imageID,
transports: ["ws", "tcp"], transports: ["ws", "tcp"],
secureChannels: ["noise"], secureChannels: ["noise"],
muxers: ["mplex", "yamux"], muxers: ["mplex", "yamux"],
}, },
{ {
id: "rust-v0.50.0", id: "rust-v0.50.0",
containerImageID: rustv050.imageID,
transports: ["ws", "tcp", "quic-v1"], transports: ["ws", "tcp", "quic-v1"],
secureChannels: ["tls", "noise"], secureChannels: ["tls", "noise"],
muxers: ["mplex", "yamux"], muxers: ["mplex", "yamux"],
}, },
{ {
id: "rust-v0.51.0", id: "rust-v0.51.0",
containerImageID: rustv051.imageID,
transports: ["ws", "tcp", "quic-v1", "webrtc-direct"], transports: ["ws", "tcp", "quic-v1", "webrtc-direct"],
secureChannels: ["tls", "noise"], secureChannels: ["tls", "noise"],
muxers: ["mplex", "yamux"], muxers: ["mplex", "yamux"],
}, },
{ {
id: "rust-v0.52.0", id: "rust-v0.52.0",
containerImageID: rustv052.imageID,
transports: ["ws", "tcp", "quic-v1", "webrtc-direct"], transports: ["ws", "tcp", "quic-v1", "webrtc-direct"],
secureChannels: ["tls", "noise"], secureChannels: ["tls", "noise"],
muxers: ["mplex", "yamux"], muxers: ["mplex", "yamux"],
}, },
{ {
id: "js-v0.41.0", id: "js-v0.41.0",
containerImageID: jsV041.imageID,
transports: ["tcp", "ws"], transports: ["tcp", "ws"],
secureChannels: ["noise"], secureChannels: ["noise"],
muxers: ["mplex", "yamux"], muxers: ["mplex", "yamux"],
}, },
{ {
id: "js-v0.42.0", id: "js-v0.42.0",
containerImageID: jsV042.imageID,
transports: ["tcp", "ws", { name: "wss", onlyDial: true }], transports: ["tcp", "ws", { name: "wss", onlyDial: true }],
secureChannels: ["noise"], secureChannels: ["noise"],
muxers: ["mplex", "yamux"], muxers: ["mplex", "yamux"],
}, },
{ {
id: "js-v0.44.0", id: "js-v0.44.0",
containerImageID: jsV044.imageID,
transports: ["tcp", "ws", { name: "wss", onlyDial: true }], transports: ["tcp", "ws", { name: "wss", onlyDial: true }],
secureChannels: ["noise"], secureChannels: ["noise"],
muxers: ["mplex", "yamux"], muxers: ["mplex", "yamux"],
}, },
{ {
id: "js-v0.45.0", id: "js-v0.45.0",
containerImageID: jsV045.imageID,
transports: ["tcp", "ws", { name: "wss", onlyDial: true }], transports: ["tcp", "ws", { name: "wss", onlyDial: true }],
secureChannels: ["noise"], secureChannels: ["noise"],
muxers: ["mplex", "yamux"], muxers: ["mplex", "yamux"],
}, },
{ {
id: "chromium-js-v0.41.0", id: "chromium-js-v0.41.0",
containerImageID: chromiumJsV041.imageID, containerImageID: browserImageIDLookup,
transports: [{ name: "webtransport", onlyDial: true }], transports: [{ name: "webtransport", onlyDial: true }],
secureChannels: [], secureChannels: [],
muxers: [] muxers: []
}, },
{ {
id: "chromium-js-v0.42.0", id: "chromium-js-v0.42.0",
containerImageID: chromiumJsV042.imageID, containerImageID: browserImageIDLookup,
transports: [{ name: "webtransport", onlyDial: true }, { name: "wss", onlyDial: true }], transports: [{ name: "webtransport", onlyDial: true }, { name: "wss", onlyDial: true }],
secureChannels: ["noise"], secureChannels: ["noise"],
muxers: ["mplex", "yamux"] muxers: ["mplex", "yamux"]
}, },
{ {
id: "chromium-js-v0.44.0", id: "chromium-js-v0.44.0",
containerImageID: chromiumJsV044.imageID, containerImageID: browserImageIDLookup,
transports: [{ name: "webtransport", onlyDial: true }, { name: "wss", onlyDial: true }, { name: "webrtc-direct", onlyDial: true }], transports: [{ name: "webtransport", onlyDial: true }, { name: "wss", onlyDial: true }, { name: "webrtc-direct", onlyDial: true }],
secureChannels: ["noise"], secureChannels: ["noise"],
muxers: ["mplex", "yamux"], muxers: ["mplex", "yamux"],
}, },
{ {
id: "chromium-js-v0.45.0", id: "chromium-js-v0.45.0",
containerImageID: chromiumJsV045.imageID, containerImageID: browserImageIDLookup,
transports: [{ name: "webtransport", onlyDial: true }, { name: "wss", onlyDial: true }, { name: "webrtc-direct", onlyDial: true }, "webrtc"], transports: [{ name: "webtransport", onlyDial: true }, { name: "wss", onlyDial: true }, { name: "webrtc-direct", onlyDial: true }, "webrtc"],
secureChannels: ["noise"], secureChannels: ["noise"],
muxers: ["mplex", "yamux"], muxers: ["mplex", "yamux"],
}, },
{ {
id: "firefox-js-v0.45.0", id: "firefox-js-v0.45.0",
containerImageID: firefoxJsV045.imageID, containerImageID: browserImageIDLookup,
transports: [{ name: "wss", onlyDial: true }, { name: "webrtc-direct", onlyDial: true }, "webrtc"], transports: [{ name: "wss", onlyDial: true }, { name: "webrtc-direct", onlyDial: true }, "webrtc"],
secureChannels: ["noise"], secureChannels: ["noise"],
muxers: ["mplex", "yamux"], muxers: ["mplex", "yamux"],
}, },
{ {
id: "go-v0.28.0", id: "go-v0.28.0",
containerImageID: gov028.imageID,
transports: ["tcp", "ws", "quic", "quic-v1", "webtransport"], transports: ["tcp", "ws", "quic", "quic-v1", "webtransport"],
secureChannels: ["tls", "noise"], secureChannels: ["tls", "noise"],
muxers: ["mplex", "yamux"], muxers: ["mplex", "yamux"],
}, },
{ {
id: "go-v0.27.6", id: "go-v0.27.6",
containerImageID: gov027.imageID,
transports: ["tcp", "ws", "quic", "quic-v1", "webtransport"], transports: ["tcp", "ws", "quic", "quic-v1", "webtransport"],
secureChannels: ["tls", "noise"], secureChannels: ["tls", "noise"],
muxers: ["mplex", "yamux"], muxers: ["mplex", "yamux"],
}, },
{ {
id: "go-v0.26.4", id: "go-v0.26.4",
containerImageID: gov026.imageID,
transports: ["tcp", "ws", "quic", "quic-v1", "webtransport"], transports: ["tcp", "ws", "quic", "quic-v1", "webtransport"],
secureChannels: ["tls", "noise"], secureChannels: ["tls", "noise"],
muxers: ["mplex", "yamux"], muxers: ["mplex", "yamux"],
}, },
{ {
id: "go-v0.25.1", id: "go-v0.25.1",
containerImageID: gov025.imageID,
transports: ["tcp", "ws", "quic", "quic-v1", "webtransport"], transports: ["tcp", "ws", "quic", "quic-v1", "webtransport"],
secureChannels: ["tls", "noise"], secureChannels: ["tls", "noise"],
muxers: ["mplex", "yamux"], muxers: ["mplex", "yamux"],
}, },
{ {
id: "go-v0.24.2", id: "go-v0.24.2",
containerImageID: gov024.imageID,
transports: ["tcp", "ws", "quic", "quic-v1", "webtransport", "wss"], transports: ["tcp", "ws", "quic", "quic-v1", "webtransport", "wss"],
secureChannels: ["tls", "noise"], secureChannels: ["tls", "noise"],
muxers: ["mplex", "yamux"], muxers: ["mplex", "yamux"],
}, },
{ {
id: "go-v0.23.4", id: "go-v0.23.4",
containerImageID: gov023.imageID,
transports: ["tcp", "ws", "quic"], transports: ["tcp", "ws", "quic"],
secureChannels: ["tls", "noise"], secureChannels: ["tls", "noise"],
muxers: ["mplex", "yamux"], muxers: ["mplex", "yamux"],
}, },
{ {
id: "go-v0.22.0", id: "go-v0.22.0",
containerImageID: gov022.imageID,
transports: ["tcp", "ws", "quic"], transports: ["tcp", "ws", "quic"],
secureChannels: ["tls", "noise"], secureChannels: ["tls", "noise"],
muxers: ["mplex", "yamux"], muxers: ["mplex", "yamux"],
}, },
{ {
id: "nim-v1.0", id: "nim-v1.0",
containerImageID: nimv10.imageID,
transports: ["tcp", "ws"], transports: ["tcp", "ws"],
secureChannels: ["noise"], secureChannels: ["noise"],
muxers: ["mplex", "yamux"], muxers: ["mplex", "yamux"],
}, },
{ {
id: "zig-v0.0.1", id: "zig-v0.0.1",
containerImageID: zigv001.imageID,
transports: ["quic-v1"], transports: ["quic-v1"],
secureChannels: [], secureChannels: [],
muxers: [], muxers: [],
}, },
{ {
id: "java-v0.0.1", id: "java-v0.0.1",
containerImageID: javav001.imageID,
transports: ["tcp"], transports: ["tcp"],
secureChannels: ["tls", "noise"], secureChannels: ["tls", "noise"],
muxers: ["mplex", "yamux"], muxers: ["mplex", "yamux"],
}, },
] ].map((v: Version) => (typeof v.containerImageID === "undefined" ? ({ ...v, containerImageID: canonicalImageIDLookup }) : v))