Merge pull request #13914 from Budibase/lock-container-start
Lock starting containers.
This commit is contained in:
commit
9f642e2939
|
@ -8,6 +8,8 @@ bb-airgapped.tar.gz
|
|||
packages/server/build/oldClientVersions/**/*
|
||||
packages/builder/src/components/deploy/clientVersions.json
|
||||
|
||||
packages/server/src/integrations/tests/utils/*.lock
|
||||
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
|
|
|
@ -860,8 +860,10 @@
|
|||
"json",
|
||||
"internal",
|
||||
"barcodeqr",
|
||||
"signature_single",
|
||||
"bigint",
|
||||
"bb_reference"
|
||||
"bb_reference",
|
||||
"bb_reference_single"
|
||||
],
|
||||
"description": "Defines the type of the column, most explain themselves, a link column is a relationship."
|
||||
},
|
||||
|
@ -1067,8 +1069,10 @@
|
|||
"json",
|
||||
"internal",
|
||||
"barcodeqr",
|
||||
"signature_single",
|
||||
"bigint",
|
||||
"bb_reference"
|
||||
"bb_reference",
|
||||
"bb_reference_single"
|
||||
],
|
||||
"description": "Defines the type of the column, most explain themselves, a link column is a relationship."
|
||||
},
|
||||
|
@ -1285,8 +1289,10 @@
|
|||
"json",
|
||||
"internal",
|
||||
"barcodeqr",
|
||||
"signature_single",
|
||||
"bigint",
|
||||
"bb_reference"
|
||||
"bb_reference",
|
||||
"bb_reference_single"
|
||||
],
|
||||
"description": "Defines the type of the column, most explain themselves, a link column is a relationship."
|
||||
},
|
||||
|
|
|
@ -782,8 +782,10 @@ components:
|
|||
- json
|
||||
- internal
|
||||
- barcodeqr
|
||||
- signature_single
|
||||
- bigint
|
||||
- bb_reference
|
||||
- bb_reference_single
|
||||
description: Defines the type of the column, most explain themselves, a link
|
||||
column is a relationship.
|
||||
constraints:
|
||||
|
@ -948,8 +950,10 @@ components:
|
|||
- json
|
||||
- internal
|
||||
- barcodeqr
|
||||
- signature_single
|
||||
- bigint
|
||||
- bb_reference
|
||||
- bb_reference_single
|
||||
description: Defines the type of the column, most explain themselves, a link
|
||||
column is a relationship.
|
||||
constraints:
|
||||
|
@ -1121,8 +1125,10 @@ components:
|
|||
- json
|
||||
- internal
|
||||
- barcodeqr
|
||||
- signature_single
|
||||
- bigint
|
||||
- bb_reference
|
||||
- bb_reference_single
|
||||
description: Defines the type of the column, most explain themselves, a link
|
||||
column is a relationship.
|
||||
constraints:
|
||||
|
|
|
@ -4,8 +4,9 @@ import * as mongodb from "./mongodb"
|
|||
import * as mysql from "./mysql"
|
||||
import * as mssql from "./mssql"
|
||||
import * as mariadb from "./mariadb"
|
||||
import { GenericContainer } from "testcontainers"
|
||||
import { GenericContainer, StartedTestContainer } from "testcontainers"
|
||||
import { testContainerUtils } from "@budibase/backend-core/tests"
|
||||
import cloneDeep from "lodash/cloneDeep"
|
||||
|
||||
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) {
|
||||
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())
|
||||
if (!info) {
|
||||
|
|
|
@ -29,6 +29,9 @@ export async function getDatasource(): Promise<Datasource> {
|
|||
}
|
||||
|
||||
const port = (await ports).find(x => x.container === 1433)?.host
|
||||
if (!port) {
|
||||
throw new Error("SQL Server port not found")
|
||||
}
|
||||
|
||||
const datasource: Datasource = {
|
||||
type: "datasource_plus",
|
||||
|
|
|
@ -38,6 +38,9 @@ export async function getDatasource(): Promise<Datasource> {
|
|||
}
|
||||
|
||||
const port = (await ports).find(x => x.container === 3306)?.host
|
||||
if (!port) {
|
||||
throw new Error("MySQL port not found")
|
||||
}
|
||||
|
||||
const datasource: Datasource = {
|
||||
type: "datasource_plus",
|
||||
|
|
|
@ -21,6 +21,9 @@ export async function getDatasource(): Promise<Datasource> {
|
|||
}
|
||||
|
||||
const port = (await ports).find(x => x.container === 5432)?.host
|
||||
if (!port) {
|
||||
throw new Error("Postgres port not found")
|
||||
}
|
||||
|
||||
const datasource: Datasource = {
|
||||
type: "datasource_plus",
|
||||
|
|
Loading…
Reference in New Issue