mirror of
https://github.com/datahaven-xyz/datahaven
synced 2026-05-24 09:50:01 +00:00
### New Features
1. Add the `deploy` command to our CLI.
1. Conditionally deploys kurtosis eth network if we're in `stagenet`
environment.
2. Deploys DH nodes.
3. Deploys contracts (all of them). In `mainnet` and `testnet` it
shouldn't deploy EL contracts, but for now that's not implemented.
4. Configures parameters, validators and relayers in the same way as
`launch`.
5. Currently, it only deploys `beefy` and `beacon` relayers, `execution`
and `solochain` relayers are pending for a subsequent PR.
2. Add `waitFor` utility function that receives a lambda.
### Refactors
1. Several common functionalities used both by the `launch` and `deploy`
command have been moved to the `cli/handlers/common` directory, from
where both commands use them. These include
1. Checks for installed dependencies.
2. Common constants.
3. The `LaunchedNetwork` class has been moved to this directory.
4. DataHaven nodes common functions.
5. Kurtosis common functions.
6. Relayer common functions.
7. Kubernetes functions (although only used by `deploy`, it seemed
fitting to have it here still).
8. Remove CLI questions and separator prints from `deploy-contracts.ts`
and `set-datahaven-parameters.ts` scripts. These things should be in the
`cli/launch` folder, which consumes the functions in these scripts.
9. Remove `setParametersFromCollection` from `utils` folder and put it
in `cli`.
10. Create base snowbridge relayer configs for `local` and `stagenet` as
two separate directories.
### Fixes
1. Sets the default time of the `deploy` command to 6s as Lodestar is
slower than Lighthouse.
2. In `runShellCommandWithLogger` only print `stderr` if the command
fails.
### Additional Minor Changes
1. K8s secret key names changed from `dh-beefy-relay-eth-key` to
`dh-beefy-relay-ethereum-key` and `dh-beacon-relay-sub-key` to
`dh-beacon-relay-substrate-key`, for simplicity in the deployment
script.
11. Update suggested configs for `.vscode` configs.
---------
Co-authored-by: Steve Degosserie <723552+stiiifff@users.noreply.github.com>
134 lines
3.5 KiB
TypeScript
134 lines
3.5 KiB
TypeScript
import { $ } from "bun";
|
|
import { z } from "zod";
|
|
import { logger } from "./logger";
|
|
|
|
export interface ServiceMapping {
|
|
service: string;
|
|
containerPattern: string;
|
|
internalPort: number;
|
|
protocol: string;
|
|
}
|
|
|
|
export interface ServiceInfo {
|
|
service: string;
|
|
port: string;
|
|
url: string;
|
|
}
|
|
|
|
export type KurtosisServiceInfo = {
|
|
name: string;
|
|
portType: string;
|
|
portNumber: number;
|
|
};
|
|
|
|
export const standardKurtosisServices = [
|
|
"el-1-reth-lodestar",
|
|
"el-2-reth-lodestar",
|
|
"vc-1-reth-lodestar",
|
|
"vc-2-reth-lodestar",
|
|
"dora"
|
|
];
|
|
|
|
export const StandardServiceMappings: ServiceMapping[] = [
|
|
{
|
|
service: "reth-1-rpc",
|
|
containerPattern: "el-1-reth-lodestar",
|
|
internalPort: 8545,
|
|
protocol: "tcp"
|
|
},
|
|
{
|
|
service: "reth-2-rpc",
|
|
containerPattern: "el-2-reth-lodestar",
|
|
internalPort: 8545,
|
|
protocol: "tcp"
|
|
},
|
|
{
|
|
service: "blockscout-backend",
|
|
containerPattern: "blockscout--",
|
|
internalPort: 4000,
|
|
protocol: "tcp"
|
|
},
|
|
{
|
|
service: "dora",
|
|
containerPattern: "dora--",
|
|
internalPort: 8080,
|
|
protocol: "tcp"
|
|
}
|
|
];
|
|
|
|
const portDetailSchema = z.object({
|
|
number: z.number(),
|
|
transport: z.number(), // Consider z.literal(0) | z.literal(2) if these are the only values
|
|
maybe_application_protocol: z.string().optional()
|
|
});
|
|
|
|
const portsListSchema = z.record(z.string(), portDetailSchema);
|
|
|
|
const serviceSchema = z.object({
|
|
image: z.string(),
|
|
ports: portsListSchema,
|
|
public_ports: portsListSchema,
|
|
files: z.record(z.string(), z.array(z.string())).optional(),
|
|
entrypoint: z.array(z.string()).optional(),
|
|
cmd: z.array(z.string()),
|
|
env_vars: z.record(z.string(), z.string()).optional(),
|
|
labels: z.record(z.string(), z.string()).optional(),
|
|
tini_enabled: z.boolean()
|
|
});
|
|
|
|
export type KurtosisService = z.infer<typeof serviceSchema>;
|
|
|
|
export const getServiceFromKurtosis = async (
|
|
service: string,
|
|
enclave: string
|
|
): Promise<KurtosisService> => {
|
|
logger.debug("Getting service from kurtosis", service);
|
|
|
|
const command = `kurtosis service inspect ${enclave} ${service} -o json`;
|
|
logger.debug(`Running command: ${command}`);
|
|
|
|
const { stdout, stderr, exitCode } = await $`sh -c ${command}`.nothrow().quiet();
|
|
if (exitCode !== 0) {
|
|
throw Error(`Failed to get port for ${service}: ${stderr.toString()}`);
|
|
}
|
|
|
|
const output = stdout.toString();
|
|
logger.trace(output);
|
|
|
|
return serviceSchema.parse(JSON.parse(output));
|
|
};
|
|
|
|
export const getPortFromKurtosis = async (
|
|
service: string,
|
|
portName: string,
|
|
enclave: string
|
|
): Promise<number> => {
|
|
logger.debug("Getting port for service", service, portName);
|
|
|
|
const command = `kurtosis service inspect ${enclave} ${service} -o json`;
|
|
logger.debug(`Running command: ${command}`);
|
|
|
|
const { stdout, stderr, exitCode } = await $`sh -c ${command}`.nothrow().quiet();
|
|
if (exitCode !== 0) {
|
|
throw Error(`Failed to get port for ${service} ${portName}: ${stderr.toString()}`);
|
|
}
|
|
|
|
const output = stdout.toString();
|
|
logger.debug(output);
|
|
|
|
const parsed = serviceSchema.parse(JSON.parse(output));
|
|
|
|
return parsed.public_ports[portName].number;
|
|
};
|
|
|
|
export const getServicesFromKurtosis = async (
|
|
enclaveName: string
|
|
): Promise<Record<string, KurtosisService>> => {
|
|
const promises = standardKurtosisServices.map(async (serviceName) => {
|
|
const serviceData = await getServiceFromKurtosis(serviceName, enclaveName);
|
|
return { [serviceName]: serviceData };
|
|
});
|
|
|
|
const results = await Promise.all(promises);
|
|
return results.reduce((acc, current) => ({ ...acc, ...current }), {});
|
|
};
|