1
0
Fork 0
mirror of synced 2024-10-04 03:54:37 +13:00

Merge pull request #13914 from Budibase/lock-container-start

Lock starting containers.
This commit is contained in:
Sam Rose 2024-06-11 18:03:01 +01:00 committed by GitHub
commit 9f642e2939
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 60 additions and 6 deletions

2
.gitignore vendored
View file

@ -8,6 +8,8 @@ bb-airgapped.tar.gz
packages/server/build/oldClientVersions/**/* packages/server/build/oldClientVersions/**/*
packages/builder/src/components/deploy/clientVersions.json packages/builder/src/components/deploy/clientVersions.json
packages/server/src/integrations/tests/utils/*.lock
# Logs # Logs
logs logs
*.log *.log

View file

@ -860,8 +860,10 @@
"json", "json",
"internal", "internal",
"barcodeqr", "barcodeqr",
"signature_single",
"bigint", "bigint",
"bb_reference" "bb_reference",
"bb_reference_single"
], ],
"description": "Defines the type of the column, most explain themselves, a link column is a relationship." "description": "Defines the type of the column, most explain themselves, a link column is a relationship."
}, },
@ -1067,8 +1069,10 @@
"json", "json",
"internal", "internal",
"barcodeqr", "barcodeqr",
"signature_single",
"bigint", "bigint",
"bb_reference" "bb_reference",
"bb_reference_single"
], ],
"description": "Defines the type of the column, most explain themselves, a link column is a relationship." "description": "Defines the type of the column, most explain themselves, a link column is a relationship."
}, },
@ -1285,8 +1289,10 @@
"json", "json",
"internal", "internal",
"barcodeqr", "barcodeqr",
"signature_single",
"bigint", "bigint",
"bb_reference" "bb_reference",
"bb_reference_single"
], ],
"description": "Defines the type of the column, most explain themselves, a link column is a relationship." "description": "Defines the type of the column, most explain themselves, a link column is a relationship."
}, },

View file

@ -782,8 +782,10 @@ components:
- json - json
- internal - internal
- barcodeqr - barcodeqr
- signature_single
- bigint - bigint
- bb_reference - bb_reference
- bb_reference_single
description: Defines the type of the column, most explain themselves, a link description: Defines the type of the column, most explain themselves, a link
column is a relationship. column is a relationship.
constraints: constraints:
@ -948,8 +950,10 @@ components:
- json - json
- internal - internal
- barcodeqr - barcodeqr
- signature_single
- bigint - bigint
- bb_reference - bb_reference
- bb_reference_single
description: Defines the type of the column, most explain themselves, a link description: Defines the type of the column, most explain themselves, a link
column is a relationship. column is a relationship.
constraints: constraints:
@ -1121,8 +1125,10 @@ components:
- json - json
- internal - internal
- barcodeqr - barcodeqr
- signature_single
- bigint - bigint
- bb_reference - bb_reference
- bb_reference_single
description: Defines the type of the column, most explain themselves, a link description: Defines the type of the column, most explain themselves, a link
column is a relationship. column is a relationship.
constraints: constraints:

View file

@ -4,8 +4,9 @@ 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 cloneDeep from "lodash/cloneDeep"
export type DatasourceProvider = () => Promise<Datasource> export type DatasourceProvider = () => Promise<Datasource>
@ -65,9 +66,39 @@ export async function rawQuery(ds: Datasource, sql: string): Promise<any> {
} }
export async function startContainer(container: GenericContainer) { export async function startContainer(container: GenericContainer) {
container = container.withReuse().withLabels({ "com.budibase": "true" }) const imageName = (container as any).imageName.string as string
const key = imageName.replaceAll("/", "-").replaceAll(":", "-")
const startedContainer = await container.start() container = container
.withReuse()
.withLabels({ "com.budibase": "true" })
.withName(key)
let startedContainer: StartedTestContainer | undefined = undefined
let lastError = undefined
for (let i = 0; i < 10; i++) {
try {
// container.start() is not an idempotent operation, calling `start`
// modifies the internal state of a GenericContainer instance such that
// the hash it uses to determine reuse changes. We need to clone the
// container before calling start to ensure that we're using the same
// reuse hash every time.
const containerCopy = cloneDeep(container)
startedContainer = await containerCopy.start()
lastError = undefined
break
} catch (e: any) {
lastError = e
await new Promise(resolve => setTimeout(resolve, 1000))
}
}
if (!startedContainer) {
if (lastError) {
throw lastError
}
throw new Error(`failed to start container: ${imageName}`)
}
const info = testContainerUtils.getContainerById(startedContainer.getId()) const info = testContainerUtils.getContainerById(startedContainer.getId())
if (!info) { if (!info) {

View file

@ -29,6 +29,9 @@ export async function getDatasource(): Promise<Datasource> {
} }
const port = (await ports).find(x => x.container === 1433)?.host const port = (await ports).find(x => x.container === 1433)?.host
if (!port) {
throw new Error("SQL Server port not found")
}
const datasource: Datasource = { const datasource: Datasource = {
type: "datasource_plus", type: "datasource_plus",

View file

@ -38,6 +38,9 @@ export async function getDatasource(): Promise<Datasource> {
} }
const port = (await ports).find(x => x.container === 3306)?.host const port = (await ports).find(x => x.container === 3306)?.host
if (!port) {
throw new Error("MySQL port not found")
}
const datasource: Datasource = { const datasource: Datasource = {
type: "datasource_plus", type: "datasource_plus",

View file

@ -21,6 +21,9 @@ export async function getDatasource(): Promise<Datasource> {
} }
const port = (await ports).find(x => x.container === 5432)?.host const port = (await ports).find(x => x.container === 5432)?.host
if (!port) {
throw new Error("Postgres port not found")
}
const datasource: Datasource = { const datasource: Datasource = {
type: "datasource_plus", type: "datasource_plus",