Bringing back the old mechanism of removing stopped containers.
This commit is contained in:
parent
8b56c6d043
commit
9f645099df
|
@ -37,6 +37,10 @@ function getTestcontainers(): ContainerInfo[] {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function removeContainer(container: ContainerInfo) {
|
||||||
|
execSync(`docker rm ${container.ID}`)
|
||||||
|
}
|
||||||
|
|
||||||
export function getContainerByImage(image: string) {
|
export function getContainerByImage(image: string) {
|
||||||
const containers = getTestcontainers().filter(x => x.Image.startsWith(image))
|
const containers = getTestcontainers().filter(x => x.Image.startsWith(image))
|
||||||
if (containers.length > 1) {
|
if (containers.length > 1) {
|
||||||
|
@ -49,6 +53,10 @@ export function getContainerByImage(image: string) {
|
||||||
return containers[0]
|
return containers[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getContainerByName(name: string) {
|
||||||
|
return getTestcontainers().find(x => x.Names === name)
|
||||||
|
}
|
||||||
|
|
||||||
export function getContainerById(id: string) {
|
export function getContainerById(id: string) {
|
||||||
return getTestcontainers().find(x => x.ID === id)
|
return getTestcontainers().find(x => x.ID === id)
|
||||||
}
|
}
|
||||||
|
@ -147,6 +155,15 @@ export async function startContainer(container: GenericContainer) {
|
||||||
key = key.replace(/\//g, "-").replace(/:/g, "-")
|
key = key.replace(/\//g, "-").replace(/:/g, "-")
|
||||||
const name = `${key}_testcontainer`
|
const name = `${key}_testcontainer`
|
||||||
|
|
||||||
|
// If a container has died it hangs around and future attempts to start a
|
||||||
|
// container with the same name will fail. What we do here is if we find a
|
||||||
|
// matching container and it has exited, we remove it before carrying on. This
|
||||||
|
// removes the need to do this removal manually.
|
||||||
|
const existingContainer = getContainerByName(name)
|
||||||
|
if (existingContainer?.State === "exited") {
|
||||||
|
removeContainer(existingContainer)
|
||||||
|
}
|
||||||
|
|
||||||
container = container
|
container = container
|
||||||
.withReuse()
|
.withReuse()
|
||||||
.withLabels({ "com.budibase": "true" })
|
.withLabels({ "com.budibase": "true" })
|
||||||
|
|
Loading…
Reference in New Issue