Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add options for custom tags #526

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ Available commands:
--async to enable or disable asynchronous creation of accounts.
--b or --blocklist to enable or disable account blocklisting. Depending on how many private keys are blocklisted, this will affect the generated on startup accounts.
--enable-debug Enable or disable debugging of the local node [boolean] [default: false]
--network-tag Select custom network node tag [string] [defaults: predefined selected configuration]
--mirror-tag Select custom mirror node tag [string] [defaults: predefined selected configuration]
--relay-tag Select custom hedera-json-rpc relay tag [string] [defaults: predefined selected configuration]
--workdir Path to the working directory for local node [string] [default: "[USER APP DATA]/hedera-local"]
stop - Stops the local hedera network and delete all the existing data.
restart - Restart the local hedera network.
Expand Down
66 changes: 64 additions & 2 deletions src/services/CLIService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ export class CLIService implements IService{
CLIService.userComposeDirOption(yargs);
CLIService.blocklistingOption(yargs);
CLIService.enableDebugOption(yargs);
CLIService.selectNetworkTag(yargs);
CLIService.selectMirrorTag(yargs);
CLIService.selectRelayTag(yargs);
}

/**
Expand Down Expand Up @@ -152,8 +155,10 @@ export class CLIService implements IService{
const verbose = CLIService.resolveVerboseLevel(argv.verbose as string);
const timestamp = argv.timestamp as string;
const enableDebug = argv.enableDebug as boolean;
const networkTag = argv.networkTag as string;
const mirrorTag = argv.mirrorTag as string;
const relayTag = argv.relayTag as string;
const workDir = FileSystemUtils.parseWorkDir(argv.workdir as string);

const currentArgv: CLIOptions = {
accounts,
async,
Expand All @@ -172,6 +177,9 @@ export class CLIService implements IService{
verbose,
timestamp,
enableDebug,
networkTag,
mirrorTag,
relayTag,
workDir,
};

Expand Down Expand Up @@ -522,7 +530,61 @@ export class CLIService implements IService{
describe: 'Enable or disable debugging of the local node',
demandOption: false,
default: false
});
});
}

/**
* Adds the 'network-tag' option to the command line arguments.
* This option is a string that enables usage of custom network tag.
* It is not required and defaults to predefined configuration.
*
* @param {yargs.Argv<{}>} yargs - The yargs instance to which the option is added.
* @private
* @static
*/
private static selectNetworkTag(yargs: Argv<{}>): void {
yargs.option('network-tag', {
type: 'string',
describe: 'Select custom network node tag',
demandOption: false,
default: ''
});
}

/**
* Adds the 'mirror-tag' option to the command line arguments.
* This option is a string that enables usage of custom mirror-node tag.
* It is not required and defaults to predefined configuration.
*
* @param {yargs.Argv<{}>} yargs - The yargs instance to which the option is added.
* @private
* @static
*/
private static selectMirrorTag(yargs: Argv<{}>): void {
yargs.option('mirror-tag', {
type: 'string',
describe: 'Select custom mirror-node tag',
demandOption: false,
default: ''
});
}

/**
* Adds the 'mirror-tag' option to the command line arguments.
* This option is a string that enables usage of custom mirror-node tag.
* It is not required and defaults to predefined configuration.
*
* @param {yargs.Argv<{}>} yargs - The yargs instance to which the option is added.
* @private
* @static
*/
private static selectRelayTag(yargs: Argv<{}>): void {
yargs.option('relay-tag', {
type: 'string',
describe: 'Select custom hedera-json-rpc relay tag',
demandOption: false,
default: ''
});
}

/**
Expand Down
14 changes: 12 additions & 2 deletions src/state/InitState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,18 @@ export class InitState implements IState{
*/
private configureEnvVariables(imageTagConfiguration: Array<Configuration>, envConfiguration: Array<Configuration> | undefined): void {
imageTagConfiguration.forEach(variable => {
process.env[variable.key] = variable.value;
this.logger.trace(`Environment variable ${variable.key} will be set to ${variable.value}.`, this.stateName);
const node = variable.key;
let tag = variable.value;
if (this.cliOptions.networkTag && (node === "NETWORK_NODE_IMAGE_TAG" || node === "HAVEGED_IMAGE_TAG")) {
tag = this.cliOptions.networkTag;
} else if(this.cliOptions.mirrorTag && node === "MIRROR_IMAGE_TAG") {
tag = this.cliOptions.mirrorTag;
} else if(this.cliOptions.relayTag && node === "RELAY_IMAGE_TAG") {
tag = this.cliOptions.relayTag;
}

this.logger.trace(`Environment variable ${node} will be set to ${tag}.`, this.stateName);
process.env[node] = tag;
});

if (!envConfiguration) {
Expand Down
3 changes: 3 additions & 0 deletions src/types/CLIOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,8 @@ export interface CLIOptions {
verbose: number,
timestamp: string,
enableDebug: boolean,
networkTag: string,
mirrorTag: string,
relayTag: string,
workDir: string,
}
Loading