docker-compose.ts 1012 Bytes
Newer Older
1 2 3 4 5 6 7
import * as compose from 'docker-compose'
import * as shell from 'shelljs'
import * as path from 'path'

type ServiceNames = 'batch_submitter' | 'dtl' | 'l2geth' | 'relayer'

const OPS_DIRECTORY = path.join(process.cwd(), '../ops')
8 9 10 11 12 13
const DEFAULT_SERVICES: ServiceNames[] = [
  'batch_submitter',
  'dtl',
  'l2geth',
  'relayer',
]
14 15

export class DockerComposeNetwork {
16
  constructor(private readonly services: ServiceNames[] = DEFAULT_SERVICES) {}
17

18 19
  async up() {
    const out = await compose.upMany(this.services, { cwd: OPS_DIRECTORY })
20

21
    const { err, exitCode } = out
22

23 24 25 26 27 28
    if (!err || exitCode) {
      console.error(err)
      throw new Error(
        'Unexpected error when starting docker-compose network, dumping output'
      )
    }
29

30 31 32 33 34 35 36
    if (err.includes('Creating')) {
      console.info(
        '🐳 Tests required starting containers. Waiting for sequencer to ready.'
      )
      shell.exec(`${OPS_DIRECTORY}/scripts/wait-for-sequencer.sh`, {
        cwd: OPS_DIRECTORY,
      })
37
    }
38
  }
39
}