chore: improve Docker network config reliability

This commit is contained in:
Danish Arora 2025-01-20 17:32:49 +05:30
parent 18c6d3b792
commit e8f5171d93
No known key found for this signature in database
GPG Key ID: 1C6EF37CDAE1426E
3 changed files with 33 additions and 10 deletions

View File

@ -107,6 +107,7 @@ export default class Dockerode {
const container = await this.docker.createContainer({
Image: this.IMAGE_NAME,
HostConfig: {
NetworkMode: NETWORK_NAME,
AutoRemove: true,
PortBindings: {
[`${restPort}/tcp`]: [{ HostPort: restPort.toString() }],
@ -116,6 +117,8 @@ export default class Dockerode {
[`${discv5UdpPort}/udp`]: [{ HostPort: discv5UdpPort.toString() }]
})
},
Dns: ["8.8.8.8"],
Links: [],
Mounts: args.rlnRelayEthClientAddress
? [
{
@ -135,18 +138,19 @@ export default class Dockerode {
[`${discv5UdpPort}/udp`]: {}
})
},
Cmd: argsArrayWithIP
});
await container.start();
await Dockerode.network.connect({
Container: container.id,
EndpointConfig: {
IPAMConfig: {
IPv4Address: this.containerIp
Cmd: argsArrayWithIP,
NetworkingConfig: {
EndpointsConfig: {
[NETWORK_NAME]: {
IPAMConfig: {
IPv4Address: this.containerIp
}
}
}
}
});
await container.start();
const logStream = fs.createWriteStream(logPath);
container.logs(

View File

@ -431,3 +431,20 @@ interface RpcInfoResponse {
listenAddresses: string[];
enrUri?: string;
}
export async function verifyServiceNodesConnected(
nodes: ServiceNode[]
): Promise<void> {
for (const node of nodes) {
const peers = await node.peers();
log.info(`Service node ${node.containerName} peers:`, peers.length);
log.info(`Service node ${node.containerName} peers:`, peers);
if (nodes.length > 1 && peers.length === 0) {
log.error(`Service node ${node.containerName} has no peers connected`);
throw new Error(
`Service node ${node.containerName} has no peers connected`
);
}
}
}

View File

@ -36,7 +36,9 @@ export async function runMultipleNodes(
withoutFilter
);
await verifyServiceNodesConnected(serviceNodes.nodes);
if (numServiceNodes > 1) {
await verifyServiceNodesConnected(serviceNodes.nodes);
}
const wakuOptions: ProtocolCreateOptions = {
staticNoiseKey: NOISE_KEY_1,