-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.ts
executable file
·26 lines (21 loc) · 1.11 KB
/
test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { execSync } from 'child_process'
function dockerRun(label: string, args: string, command = '') {
const imageName = `pgeon_${label}_image`
const containerName = `pgeon_${label}_container`
execSync(`docker container rm --force ${containerName}`, { stdio: 'ignore' })
execSync(`docker image rm --force ${imageName}`, { stdio: 'ignore' })
execSync(`docker build --tag ${imageName} --file Dockerfile.${label} .`, { stdio: 'ignore' })
execSync(`docker run --rm --detach --name ${containerName} ${args} ${imageName} ${command}`, { stdio: 'ignore' })
return {
getIp: () => execSync(`docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' ${containerName}`).toString().trim(),
follow: () => execSync(`docker logs --follow ${containerName}`, { stdio: 'inherit' })
}
}
const PGPASSWORD = 'jB8tBAotpE2Z89yjYsJe6u6jNCfHnzxY'
const PGHOST = dockerRun('postgres', `--env POSTGRES_PASSWORD=${PGPASSWORD}`).getIp()
dockerRun(
'node',
`--env PGPASSWORD=${PGPASSWORD} --env PGHOST=${PGHOST}`,
`sh -c './node_modules/.bin/tsc && node out/src/pool.test.js'`
)
.follow()