1
0
Fork 0
mirror of synced 2024-10-03 10:36:59 +13:00

Re-use containers and create namespaces for each test.

This commit is contained in:
Sam Rose 2024-04-03 11:33:39 +01:00
parent 3dff4bf334
commit 8cffdeda56
No known key found for this signature in database
4 changed files with 28 additions and 1 deletions

View file

@ -91,6 +91,9 @@ jobs:
test-libraries:
runs-on: ubuntu-latest
env:
REUSE_CONTAINERS: true
CONTAINER_NAMESPACE: test-server
steps:
- name: Checkout repo
uses: actions/checkout@v4
@ -141,6 +144,8 @@ jobs:
runs-on: budi-tubby-tornado-quad-core-150gb
env:
DEBUG: testcontainers,testcontainers:exec,testcontainers:build,testcontainers:pull
REUSE_CONTAINERS: true
CONTAINER_NAMESPACE: test-server
steps:
- name: Checkout repo
uses: actions/checkout@v4

View file

@ -26,5 +26,11 @@ export default async function setup() {
couchdb = couchdb.withReuse()
}
if (process.env.CONTAINER_NAMESPACE) {
couchdb = couchdb.withLabels({
"org.testcontainers.namespace": process.env.CONTAINER_NAMESPACE,
})
}
await couchdb.start()
}

View file

@ -23,12 +23,22 @@ function getTestcontainers(): ContainerInfo[] {
// We use --format json to make sure the output is nice and machine-readable,
// and we use --no-trunc so that the command returns full container IDs so we
// can filter on them correctly.
return execSync("docker ps --format json --no-trunc")
let containers = execSync("docker ps --format json --no-trunc")
.toString()
.split("\n")
.filter(x => x.length > 0)
.map(x => JSON.parse(x) as ContainerInfo)
.filter(x => x.Labels.includes("org.testcontainers=true"))
if (process.env.CONTAINER_NAMESPACE) {
containers = containers.filter(x =>
x.Labels.includes(
`org.testcontainers.namespace=${process.env.CONTAINER_NAMESPACE}`
)
)
}
return containers
}
export function getContainerByImage(image: string) {

View file

@ -67,6 +67,12 @@ export async function rawQuery(ds: Datasource, sql: string): Promise<any> {
}
export async function startContainer(container: GenericContainer) {
if (process.env.CONTAINER_NAMESPACE) {
container = container.withLabels({
"org.testcontainers.namespace": process.env.CONTAINER_NAMESPACE,
})
}
if (process.env.REUSE_CONTAINERS) {
container = container.withReuse()
}