-
Notifications
You must be signed in to change notification settings - Fork 0
/
it.ts
52 lines (39 loc) · 1.84 KB
/
it.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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { spawn, spawnSync } from 'child_process'
function sleep(time: number) {
return new Promise(resolve => setTimeout(resolve, time))
}
(async () => {
process.on('SIGINT', () => {
clientStart?.kill()
serverStart?.kill()
process.exit(0)
})
console.info('\n➜ Building image from Dockerfile (verify with \`docker images\`)')
spawnSync('docker', ['build', '--tag', 'kiwibiti', 'database'], { stdio: 'inherit' })
console.info('\n➜ Stopping and removing previous container')
spawnSync('docker', ['container', 'stop', 'kiwibitc'], { stdio: 'inherit' })
spawnSync('docker', ['rm', 'kiwibitc'], { stdio: 'inherit' })
console.info('\n➜ Running container (verify with \`docker ps\`; check logs with \`docker logs -f kiwibitc\`; interact with \`docker exec -it kiwibitc psql -U postgres\`)')
spawnSync('docker', ['run', '--name', 'kiwibitc', '--env', 'POSTGRES_PASSWORD=hnzygqa2QLrRLxH4MvsOtcVVUWsYvQ7E', '-p', '5000:5432', '--detach', 'kiwibiti'], { stdio: 'inherit' })
const since = new Date().toISOString()
do {
await sleep(1_000)
} while (
!spawnSync('docker', ['logs', '--since', since, 'kiwibitc'], { stdio: 'pipe' })
.stdout
.toString()
.includes('PostgreSQL init process complete; ready for start up.')
)
console.info('\n➜ Installing root-level dependencies')
spawnSync('npm', ['i'], { stdio: 'inherit' })
process.chdir('./client')
console.info('\n➜ Installing client dependencies')
spawnSync('npm', ['i'], { stdio: 'inherit' })
console.info('\n➜ Starting client')
const clientStart = spawn('npm', ['start'], { stdio: 'inherit' })
process.chdir('../server')
console.info('\n➜ Installing server dependencies')
spawnSync('npm', ['i'], { stdio: 'inherit' })
console.info('\n➜ Starting server')
const serverStart = spawn('npm', ['start'], { stdio: 'inherit' })
})()