Created
June 19, 2020 20:57
-
-
Save RafaelAPB/9b41fd24faf8eefbaa5cceef762d90b0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public async start(): Promise<Container> { | |
const containerNameAndTag = this.getContainerImageName(); | |
if (this.container) { | |
await this.container.stop(); | |
await this.container.remove(); | |
} | |
const docker = new Docker(); | |
await this.pullContainerImage(containerNameAndTag); | |
return new Promise<Container>((resolve, reject) => { | |
const eventEmitter: EventEmitter = docker.run( | |
containerNameAndTag, | |
[], | |
[], | |
{ | |
ExposedPorts: { | |
[`${this.rpcApiHttpPort}/tcp`]: {}, // besu RPC - HTTP | |
"8546/tcp": {}, // besu RPC - WebSocket | |
"8888/tcp": {}, // orion Client Port - HTTP | |
"8080/tcp": {}, // orion Node Port - HTTP | |
"9001/tcp": {}, // supervisord - HTTP | |
"9545/tcp": {}, // besu metrics | |
}, | |
Hostconfig: { | |
PortBindings: { | |
// [`${this.rpcApiHttpPort}/tcp`]: [{ HostPort: '8545', }], | |
// '8546/tcp': [{ HostPort: '8546', }], | |
// '8080/tcp': [{ HostPort: '8080', }], | |
// '8888/tcp': [{ HostPort: '8888', }], | |
// '9001/tcp': [{ HostPort: '9001', }], | |
// '9545/tcp': [{ HostPort: '9545', }], | |
}, | |
}, | |
}, | |
{ | |
source: this.nodeType, | |
network: this.networkType | |
}, | |
(err: any) => { | |
if (err) { | |
reject(err); | |
} | |
} | |
); | |
eventEmitter.once("start", async (container: Container) => { | |
this.container = container; | |
// once the container has started, we wait until the the besu RPC API starts listening on the designated port | |
// which we determine by continously trying to establish a socket until it actually works | |
const host: string = await this.getContainerIpAddress(); | |
try { | |
let reachable: boolean = false; | |
do { | |
reachable = await isPortReachable(this.rpcApiHttpPort, { host }); | |
await new Promise((resolve2) => setTimeout(resolve2, 100)); | |
} while (!reachable); | |
resolve(container); | |
} catch (ex) { | |
reject(ex); | |
} | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment