Only hold the lock during container start.
This commit is contained in:
parent
1d1ca694c8
commit
af0802df30
|
@ -4,7 +4,7 @@ import * as mongodb from "./mongodb"
|
||||||
import * as mysql from "./mysql"
|
import * as mysql from "./mysql"
|
||||||
import * as mssql from "./mssql"
|
import * as mssql from "./mssql"
|
||||||
import * as mariadb from "./mariadb"
|
import * as mariadb from "./mariadb"
|
||||||
import { GenericContainer } from "testcontainers"
|
import { GenericContainer, StartedTestContainer } from "testcontainers"
|
||||||
import { testContainerUtils } from "@budibase/backend-core/tests"
|
import { testContainerUtils } from "@budibase/backend-core/tests"
|
||||||
import lockfile from "proper-lockfile"
|
import lockfile from "proper-lockfile"
|
||||||
import path from "path"
|
import path from "path"
|
||||||
|
@ -90,24 +90,25 @@ export async function startContainer(container: GenericContainer) {
|
||||||
retries: 10,
|
retries: 10,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
let startedContainer: StartedTestContainer
|
||||||
try {
|
try {
|
||||||
const startedContainer = await container.start()
|
startedContainer = await container.start()
|
||||||
|
|
||||||
const info = testContainerUtils.getContainerById(startedContainer.getId())
|
|
||||||
if (!info) {
|
|
||||||
throw new Error("Container not found")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Some Docker runtimes, when you expose a port, will bind it to both
|
|
||||||
// 127.0.0.1 and ::1, so ipv4 and ipv6. The port spaces of ipv4 and ipv6
|
|
||||||
// addresses are not shared, and testcontainers will sometimes give you back
|
|
||||||
// the ipv6 port. There's no way to know that this has happened, and if you
|
|
||||||
// try to then connect to `localhost:port` you may attempt to bind to the v4
|
|
||||||
// address which could be unbound or even an entirely different container. For
|
|
||||||
// that reason, we don't use testcontainers' `getExposedPort` function,
|
|
||||||
// preferring instead our own method that guaranteed v4 ports.
|
|
||||||
return testContainerUtils.getExposedV4Ports(info)
|
|
||||||
} finally {
|
} finally {
|
||||||
await lockfile.unlock(lockPath)
|
await lockfile.unlock(lockPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const info = testContainerUtils.getContainerById(startedContainer.getId())
|
||||||
|
if (!info) {
|
||||||
|
throw new Error("Container not found")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Some Docker runtimes, when you expose a port, will bind it to both
|
||||||
|
// 127.0.0.1 and ::1, so ipv4 and ipv6. The port spaces of ipv4 and ipv6
|
||||||
|
// addresses are not shared, and testcontainers will sometimes give you back
|
||||||
|
// the ipv6 port. There's no way to know that this has happened, and if you
|
||||||
|
// try to then connect to `localhost:port` you may attempt to bind to the v4
|
||||||
|
// address which could be unbound or even an entirely different container. For
|
||||||
|
// that reason, we don't use testcontainers' `getExposedPort` function,
|
||||||
|
// preferring instead our own method that guaranteed v4 ports.
|
||||||
|
return testContainerUtils.getExposedV4Ports(info)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue