2024-03-22 18:34:50 +01:00
|
|
|
import { GenericContainer, Wait } from "testcontainers"
|
2024-04-03 13:11:28 +02:00
|
|
|
import path from "path"
|
2024-04-03 13:06:49 +02:00
|
|
|
import lockfile from "proper-lockfile"
|
2024-03-22 18:34:50 +01:00
|
|
|
|
|
|
|
export default async function setup() {
|
2024-04-03 13:11:28 +02:00
|
|
|
const lockPath = path.resolve(__dirname, "globalSetup.ts")
|
2024-04-03 13:06:49 +02:00
|
|
|
if (process.env.REUSE_CONTAINERS) {
|
|
|
|
// If you run multiple tests at the same time, it's possible for the CouchDB
|
|
|
|
// shared container to get started multiple times despite having an
|
|
|
|
// identical reuse hash. To avoid that, we do a filesystem-based lock so
|
|
|
|
// that only one globalSetup.ts is running at a time.
|
2024-04-03 13:11:28 +02:00
|
|
|
lockfile.lockSync(lockPath)
|
2024-04-03 13:06:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
let couchdb = new GenericContainer("budibase/couchdb")
|
|
|
|
.withExposedPorts(5984)
|
|
|
|
.withEnvironment({
|
|
|
|
COUCHDB_PASSWORD: "budibase",
|
|
|
|
COUCHDB_USER: "budibase",
|
|
|
|
})
|
|
|
|
.withCopyContentToContainer([
|
|
|
|
{
|
|
|
|
content: `
|
2024-03-26 10:58:40 +01:00
|
|
|
[log]
|
|
|
|
level = warn
|
|
|
|
`,
|
2024-04-03 13:06:49 +02:00
|
|
|
target: "/opt/couchdb/etc/local.d/test-couchdb.ini",
|
|
|
|
},
|
|
|
|
])
|
|
|
|
.withWaitStrategy(
|
|
|
|
Wait.forSuccessfulCommand(
|
|
|
|
"curl http://budibase:budibase@localhost:5984/_up"
|
|
|
|
).withStartupTimeout(20000)
|
|
|
|
)
|
2024-03-27 17:40:41 +01:00
|
|
|
|
2024-04-03 13:06:49 +02:00
|
|
|
if (process.env.REUSE_CONTAINERS) {
|
|
|
|
couchdb = couchdb.withReuse()
|
|
|
|
}
|
2024-03-27 17:40:41 +01:00
|
|
|
|
2024-04-03 13:06:49 +02:00
|
|
|
if (process.env.CONTAINER_NAMESPACE) {
|
|
|
|
couchdb = couchdb.withLabels({
|
|
|
|
"org.testcontainers.namespace": process.env.CONTAINER_NAMESPACE,
|
|
|
|
})
|
|
|
|
}
|
2024-04-03 12:33:39 +02:00
|
|
|
|
2024-04-03 13:06:49 +02:00
|
|
|
await couchdb.start()
|
|
|
|
} finally {
|
|
|
|
if (process.env.REUSE_CONTAINERS) {
|
2024-04-03 13:11:28 +02:00
|
|
|
lockfile.unlockSync(lockPath)
|
2024-04-03 13:06:49 +02:00
|
|
|
}
|
|
|
|
}
|
2024-03-22 18:34:50 +01:00
|
|
|
}
|