Attempting to fix issues where wrong port is picked for test containers, occurred a lot locally.
This commit is contained in:
parent
af2d1984f6
commit
20a8ec8600
|
@ -8,8 +8,8 @@ services:
|
|||
# Last version that supports the "fs" backend
|
||||
image: minio/minio:RELEASE.2022-10-24T18-35-07Z
|
||||
ports:
|
||||
- 9000
|
||||
- 9001
|
||||
- "9000"
|
||||
- "9001"
|
||||
environment:
|
||||
MINIO_ACCESS_KEY: ${MINIO_ACCESS_KEY}
|
||||
MINIO_SECRET_KEY: ${MINIO_SECRET_KEY}
|
||||
|
@ -28,9 +28,9 @@ services:
|
|||
- COUCHDB_PASSWORD=${COUCH_DB_PASSWORD}
|
||||
- COUCHDB_USER=${COUCH_DB_USER}
|
||||
ports:
|
||||
- 5984
|
||||
- 4369
|
||||
- 9100
|
||||
- "5984"
|
||||
- "4369"
|
||||
- "9100"
|
||||
healthcheck:
|
||||
test: ["CMD", "curl", "-f", "http://localhost:5984/_up"]
|
||||
interval: 30s
|
||||
|
@ -42,6 +42,6 @@ services:
|
|||
image: redis
|
||||
command: redis-server --requirepass ${REDIS_PASSWORD}
|
||||
ports:
|
||||
- 6379
|
||||
- "6379"
|
||||
healthcheck:
|
||||
test: ["CMD", "redis-cli", "ping"]
|
||||
test: ["CMD", "redis-cli", "ping"]
|
|
@ -1,3 +1,31 @@
|
|||
import { execSync } from "child_process"
|
||||
|
||||
let dockerPsResult: string | undefined
|
||||
|
||||
function formatDockerPsResult(serverName: string, port: number) {
|
||||
const lines = dockerPsResult?.split("\n")
|
||||
let first = true
|
||||
if (!lines) {
|
||||
return null
|
||||
}
|
||||
for (let line of lines) {
|
||||
if (first) {
|
||||
first = false
|
||||
continue
|
||||
}
|
||||
let toLookFor = serverName.split("-service")[0]
|
||||
if (!line.includes(toLookFor)) {
|
||||
continue
|
||||
}
|
||||
const regex = new RegExp(`0.0.0.0:([0-9]*)->${port}`, "g")
|
||||
const found = line.match(regex)
|
||||
if (found) {
|
||||
return found[0].split(":")[1].split("->")[0]
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
function getTestContainerSettings(
|
||||
serverName: string,
|
||||
key: string
|
||||
|
@ -14,10 +42,22 @@ function getTestContainerSettings(
|
|||
}
|
||||
|
||||
function getContainerInfo(containerName: string, port: number) {
|
||||
const assignedPort = getTestContainerSettings(
|
||||
let assignedPort = getTestContainerSettings(
|
||||
containerName.toUpperCase(),
|
||||
`PORT_${port}`
|
||||
)
|
||||
if (!dockerPsResult) {
|
||||
try {
|
||||
const outputBuffer = execSync("docker ps")
|
||||
dockerPsResult = outputBuffer.toString("utf8")
|
||||
} catch (err) {
|
||||
//no-op
|
||||
}
|
||||
}
|
||||
const possiblePort = formatDockerPsResult(containerName, port)
|
||||
if (possiblePort) {
|
||||
assignedPort = possiblePort
|
||||
}
|
||||
const host = getTestContainerSettings(containerName.toUpperCase(), "IP")
|
||||
return {
|
||||
port: assignedPort,
|
||||
|
@ -39,12 +79,15 @@ function getRedisConfig() {
|
|||
}
|
||||
|
||||
export function setupEnv(...envs: any[]) {
|
||||
const couch = getCouchConfig(),
|
||||
minio = getCouchConfig(),
|
||||
redis = getRedisConfig()
|
||||
const configs = [
|
||||
{ key: "COUCH_DB_PORT", value: getCouchConfig().port },
|
||||
{ key: "COUCH_DB_URL", value: getCouchConfig().url },
|
||||
{ key: "MINIO_PORT", value: getMinioConfig().port },
|
||||
{ key: "MINIO_URL", value: getMinioConfig().url },
|
||||
{ key: "REDIS_URL", value: getRedisConfig().url },
|
||||
{ key: "COUCH_DB_PORT", value: couch.port },
|
||||
{ key: "COUCH_DB_URL", value: couch.url },
|
||||
{ key: "MINIO_PORT", value: minio.port },
|
||||
{ key: "MINIO_URL", value: minio.url },
|
||||
{ key: "REDIS_URL", value: redis.url },
|
||||
]
|
||||
|
||||
for (const config of configs.filter(x => !!x.value)) {
|
||||
|
|
Loading…
Reference in New Issue