mirror of
https://github.com/datahaven-xyz/datahaven
synced 2026-05-24 09:50:01 +00:00
WARNING: This PR changes the kurtosis package to use the one from upstream, not our fork, as it was not working at the moment. This should be changed when fixed. In this PR: 1. Turn `launch-kurtosis` script into a CLI, which parses parameters and can interactively run multiple steps. 2. Separate steps of such CLI into their own scripts. 1. New script created `launch-kurtosis`, which detects if an enclave is running and prompts to relaunch it if it is. 2. New script created `deploy-contracts` to deploy all contracts. It can optionally verify them as well. 3. Each step can be interactively opted in/out, or choose whether to run it via CLI params. 4. The CLI offers a help command as well. 5. Cleanup logs of CLI. Logs of internal commands ran can be printed with LOG_LEVEL=debug. In case of error, they are always printed out.
125 lines
3.3 KiB
TypeScript
125 lines
3.3 KiB
TypeScript
import Docker from "dockerode";
|
|
import invariant from "tiny-invariant";
|
|
import { logger } from "utils";
|
|
|
|
interface ServiceMapping {
|
|
service: string;
|
|
containerPattern: string;
|
|
internalPort: number;
|
|
protocol: string;
|
|
}
|
|
|
|
interface ServiceInfo {
|
|
service: string;
|
|
port: string;
|
|
url: string;
|
|
}
|
|
|
|
const serviceMappings: ServiceMapping[] = [
|
|
{
|
|
service: "reth-1-rpc",
|
|
containerPattern: "el-1-reth-lighthouse",
|
|
internalPort: 8545,
|
|
protocol: "tcp"
|
|
},
|
|
{
|
|
service: "reth-2-rpc",
|
|
containerPattern: "el-2-reth-lighthouse",
|
|
internalPort: 8545,
|
|
protocol: "tcp"
|
|
},
|
|
{
|
|
service: "blockscout-backend",
|
|
containerPattern: "blockscout--",
|
|
internalPort: 4000,
|
|
protocol: "tcp"
|
|
},
|
|
{
|
|
service: "dora",
|
|
containerPattern: "dora--",
|
|
internalPort: 8080,
|
|
protocol: "tcp"
|
|
}
|
|
];
|
|
|
|
export const getServicesFromDocker = async (): Promise<ServiceInfo[]> => {
|
|
const docker = new Docker();
|
|
|
|
const containers = await docker.listContainers();
|
|
|
|
const services: ServiceInfo[] = [];
|
|
|
|
for (const mapping of serviceMappings) {
|
|
try {
|
|
const container = containers.find((container) =>
|
|
container.Names.some((name) => name.includes(mapping.containerPattern))
|
|
);
|
|
|
|
if (!container) {
|
|
logger.warn(`Container with pattern "${mapping.containerPattern}" not found.`);
|
|
services.push({
|
|
service: mapping.service,
|
|
port: "Not found",
|
|
url: "N/A"
|
|
});
|
|
continue;
|
|
}
|
|
|
|
const portMappings = container.Ports.filter(
|
|
(port) => port.PrivatePort === mapping.internalPort && port.Type === mapping.protocol
|
|
);
|
|
|
|
let selectedMapping = portMappings.find((port) => port.IP === "0.0.0.0" || port.IP === ":::");
|
|
|
|
if (!selectedMapping && portMappings.length > 0) {
|
|
selectedMapping = portMappings[0];
|
|
}
|
|
|
|
if (!selectedMapping || !selectedMapping.PublicPort) {
|
|
logger.warn(
|
|
`Port mapping not found for ${mapping.service} (${mapping.internalPort}/${mapping.protocol}).`
|
|
);
|
|
services.push({
|
|
service: mapping.service,
|
|
port: "Not found",
|
|
url: "N/A"
|
|
});
|
|
continue;
|
|
}
|
|
|
|
services.push({
|
|
service: mapping.service,
|
|
port: selectedMapping.PublicPort.toString(),
|
|
url: `http://127.0.0.1:${selectedMapping.PublicPort}`
|
|
});
|
|
} catch (error) {
|
|
logger.error(`Error getting info for ${mapping.service}:`, error);
|
|
services.push({
|
|
service: mapping.service,
|
|
port: "Error",
|
|
url: "N/A"
|
|
});
|
|
}
|
|
}
|
|
|
|
return services;
|
|
};
|
|
|
|
export const getPublicPort = async (
|
|
containerName: string,
|
|
internalPort: number
|
|
): Promise<number> => {
|
|
const docker = new Docker();
|
|
const containers = await docker.listContainers();
|
|
const container = containers.find((container) =>
|
|
container.Names.some((name) => name.includes(containerName))
|
|
);
|
|
invariant(container, `❌ container ${container} cannot be found in running container list`);
|
|
|
|
const portMappings = container.Ports.find(
|
|
(port) => port.PrivatePort === internalPort && port.Type === "tcp"
|
|
);
|
|
logger.debug(`Port mappings for ${containerName}:${internalPort}`, portMappings);
|
|
invariant(portMappings, `❌ port mapping not found for ${containerName}:${internalPort}`);
|
|
return portMappings.PublicPort;
|
|
};
|