Skip to content

Commit

Permalink
feature: add scripts to args for install (#479)
Browse files Browse the repository at this point in the history
* add scripts to args for install

* use deploy underlying debug with extra args

* Update clients/js/packages/client/src/client.ts
  • Loading branch information
Anmol1696 authored Jun 13, 2024
1 parent b68a5d1 commit 6a82750
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 16 deletions.
41 changes: 25 additions & 16 deletions clients/js/packages/client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as os from 'os';
import { dirname, resolve } from 'path';
import * as shell from 'shelljs';

import { Chain, StarshipConfig } from './config';
import { Chain, Script, StarshipConfig } from './config';
import { Ports } from './config';
import { dependencies as defaultDependencies, Dependency } from "./deps";
import { readAndParsePackageJson } from './package';
Expand All @@ -20,7 +20,6 @@ export interface StarshipContext {
helmChart?: string;
helmVersion?: string;
helmNamespace?: string;
kindCluster?: string;
verbose?: boolean;
curdir?: string;
};
Expand Down Expand Up @@ -204,6 +203,7 @@ export class StarshipClient implements StarshipClientI {
const args = [];
if (this.ctx.helmNamespace) {
args.push('--namespace', this.ctx.helmNamespace);
args.push('--create-namespace');
}
return args;
}
Expand Down Expand Up @@ -258,11 +258,11 @@ export class StarshipClient implements StarshipClientI {
}
}

public deploy(): void {
public deploy(options: string[] = []): void {
this.ensureFileExists(this.ctx.helmFile);
this.log("Installing the helm chart. This is going to take a while.....");

this.exec([
const cmd: string[] = [
'helm',
'install',
'-f',
Expand All @@ -272,23 +272,32 @@ export class StarshipClient implements StarshipClientI {
'--version',
this.ctx.helmVersion,
...this.getArgs(),
]);
...options,
];

// Determine the data directory of the config file
const datadir = resolve(dirname(this.ctx.helmFile!));

// Iterate through each chain to add script arguments
this.config.chains.forEach((chain, chainIndex) => {
if (chain.scripts) {
Object.keys(chain.scripts).forEach(scriptKey => {
const script = chain.scripts?.[scriptKey as keyof Chain['scripts']];
if (script && script.file) {
const scriptPath = resolve(datadir, script.file);
cmd.push(`--set-file chains[${chainIndex}].scripts.${scriptKey}.data=${scriptPath}`);
}
});
}
});

this.exec(cmd);
this.log("Run \"starship get-pods\" to check the status of the cluster");
}

public debug(): void {
this.ensureFileExists(this.ctx.helmFile);
this.exec([
'helm',
'install',
'--dry-run',
'--debug',
'-f',
this.ctx.helmFile,
this.ctx.helmName,
this.ctx.helmChart,
...this.getArgs(),,
]);
this.deploy(['--dry-run', '--debug']);
}

public deleteHelm(): void {
Expand Down
18 changes: 18 additions & 0 deletions clients/js/packages/client/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,27 @@ export interface Chain {
};
faucet?: FaucetConfig;
ports?: Ports;
scripts?: {
createGenesis?: Script;
updateGenesis?: Script;
updateConfig?: Script;
createValidator?: Script;
transferTokens?: Script;
buildChain?: Script;
ibcConnection?: Script;
};
ics?: {
enabled: boolean;
image?: string;
};
resources?: Resources;
}

export interface Script {
file?: string;
data?: string;
};

export interface Relayer {
name: string;
type: string;
Expand Down

0 comments on commit 6a82750

Please sign in to comment.