1
0
Fork 0
mirror of synced 2024-07-05 22:40:39 +12:00

Make container reuse optional, disabled by default.

This commit is contained in:
Sam Rose 2024-03-27 16:40:41 +00:00
parent 3ad3f29861
commit eb33dac9b1
No known key found for this signature in database
6 changed files with 54 additions and 34 deletions

View file

@ -1,9 +1,7 @@
import { GenericContainer, Wait } from "testcontainers"
export default async function setup() {
await new GenericContainer("budibase/couchdb")
.withName("budibase-test-couchdb")
.withReuse()
let couchdb = new GenericContainer("budibase/couchdb")
.withExposedPorts(5984)
.withEnvironment({
COUCHDB_PASSWORD: "budibase",
@ -23,5 +21,10 @@ export default async function setup() {
"curl http://budibase:budibase@localhost:5984/_up"
).withStartupTimeout(20000)
)
.start()
if (process.env.REUSE_CONTAINERS) {
couchdb = couchdb.withReuse()
}
await couchdb.start()
}

View file

@ -22,16 +22,19 @@ class MariaDBWaitStrategy extends AbstractWaitStrategy {
}
export async function getDatasource(): Promise<Datasource> {
const container = await new GenericContainer("mariadb:lts")
.withName("budibase-test-mariadb")
.withReuse()
let container = new GenericContainer("mariadb:lts")
.withExposedPorts(3306)
.withEnvironment({ MARIADB_ROOT_PASSWORD: "password" })
.withWaitStrategy(new MariaDBWaitStrategy())
.start()
const host = container.getHost()
const port = container.getMappedPort(3306)
if (process.env.REUSE_CONTAINERS) {
container = container.withReuse()
}
const startedContainer = await container.start()
const host = startedContainer.getHost()
const port = startedContainer.getMappedPort(3306)
const config = {
host,

View file

@ -2,9 +2,7 @@ import { Datasource, SourceName } from "@budibase/types"
import { GenericContainer, Wait } from "testcontainers"
export async function getDatasource(): Promise<Datasource> {
const container = await new GenericContainer("mongo:7.0-jammy")
.withName("budibase-test-mongodb")
.withReuse()
let container = new GenericContainer("mongo:7.0-jammy")
.withExposedPorts(27017)
.withEnvironment({
MONGO_INITDB_ROOT_USERNAME: "mongo",
@ -15,10 +13,15 @@ export async function getDatasource(): Promise<Datasource> {
`mongosh --eval "db.version()"`
).withStartupTimeout(10000)
)
.start()
const host = container.getHost()
const port = container.getMappedPort(27017)
if (process.env.REUSE_CONTAINERS) {
container = container.withReuse()
}
const startedContainer = await container.start()
const host = startedContainer.getHost()
const port = startedContainer.getMappedPort(27017)
return {
type: "datasource",

View file

@ -4,11 +4,9 @@ import mssql from "mssql"
import { generator } from "@budibase/backend-core/tests"
export async function getDatasource(): Promise<Datasource> {
const container = await new GenericContainer(
let container = new GenericContainer(
"mcr.microsoft.com/mssql/server:2022-latest"
)
.withName("budibase-test-mssql")
.withReuse()
.withExposedPorts(1433)
.withEnvironment({
ACCEPT_EULA: "Y",
@ -24,10 +22,15 @@ export async function getDatasource(): Promise<Datasource> {
"/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P Password_123 -q 'SELECT 1'"
)
)
.start()
const host = container.getHost()
const port = container.getMappedPort(1433)
if (process.env.REUSE_CONTAINERS) {
container = container.withReuse()
}
const startedContainer = await container.start()
const host = startedContainer.getHost()
const port = startedContainer.getMappedPort(1433)
const datasource: Datasource = {
type: "datasource_plus",

View file

@ -25,15 +25,19 @@ class MySQLWaitStrategy extends AbstractWaitStrategy {
}
export async function getDatasource(): Promise<Datasource> {
const container = await new GenericContainer("mysql:8.3")
.withName("budibase-test-mysql")
.withReuse()
let container = new GenericContainer("mysql:8.3")
.withExposedPorts(3306)
.withEnvironment({ MYSQL_ROOT_PASSWORD: "password" })
.withWaitStrategy(new MySQLWaitStrategy().withStartupTimeout(10000))
.start()
const host = container.getHost()
const port = container.getMappedPort(3306)
if (process.env.REUSE_CONTAINERS) {
container = container.withReuse()
}
const startedContainer = await container.start()
const host = startedContainer.getHost()
const port = startedContainer.getMappedPort(3306)
const datasource: Datasource = {
type: "datasource_plus",

View file

@ -4,9 +4,7 @@ import pg from "pg"
import { generator } from "@budibase/backend-core/tests"
export async function getDatasource(): Promise<Datasource> {
const container = await new GenericContainer("postgres:16.1-bullseye")
.withName("budibase-test-postgres")
.withReuse()
let container = new GenericContainer("postgres:16.1-bullseye")
.withExposedPorts(5432)
.withEnvironment({ POSTGRES_PASSWORD: "password" })
.withWaitStrategy(
@ -14,9 +12,15 @@ export async function getDatasource(): Promise<Datasource> {
"pg_isready -h localhost -p 5432"
).withStartupTimeout(10000)
)
.start()
const host = container.getHost()
const port = container.getMappedPort(5432)
if (process.env.REUSE_CONTAINERS) {
container = container.withReuse()
}
const startedContainer = await container.start()
const host = startedContainer.getHost()
const port = startedContainer.getMappedPort(5432)
const datasource: Datasource = {
type: "datasource_plus",