Skip to content

Commit

Permalink
feat(cli): allow deploying JSON RPC relay for different nodes (#578)
Browse files Browse the repository at this point in the history
Signed-off-by: Lenin Mehedy <lenin.mehedy@swirldslabs.com>
  • Loading branch information
leninmehedy authored Nov 28, 2023
1 parent d9c04f2 commit 8b398fd
Show file tree
Hide file tree
Showing 22 changed files with 488 additions and 175 deletions.
16 changes: 14 additions & 2 deletions fullstack-network-manager/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions fullstack-network-manager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"dependencies": {
"adm-zip": "^0.5.10",
"chalk": "^5.3.0",
"dotenv": "^16.3.1",
"esm": "^3.2.25",
"figlet": "^1.6.0",
"got": "^13.0.0",
Expand Down
17 changes: 17 additions & 0 deletions fullstack-network-manager/src/commands/base.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
'use strict'
import { MissingArgumentError } from '../core/errors.mjs'
import * as core from '../core/index.mjs'
import chalk from 'chalk'
import { ShellRunner } from '../core/shell_runner.mjs'
import * as flags from './flags.mjs'

export class BaseCommand extends ShellRunner {
async checkDep (cmd) {
Expand Down Expand Up @@ -71,6 +73,21 @@ export class BaseCommand extends ShellRunner {
return true
}

async prepareChartPath (config, chartRepo, chartName) {
if (!config) throw new MissingArgumentError('config is required')
if (!chartRepo) throw new MissingArgumentError('chart repo name is required')
if (!chartName) throw new MissingArgumentError('chart name is required')

const chartDir = this.configManager.flagValue(config, flags.chartDirectory)
if (chartDir) {
const chartPath = `${chartDir}/${chartName}`
await this.helm.dependency('update', chartPath)
return chartPath
}

return `${chartRepo}/${chartName}`
}

constructor (opts) {
if (!opts || !opts.logger) throw new Error('An instance of core/Logger is required')
if (!opts || !opts.kind) throw new Error('An instance of core/Kind is required')
Expand Down
83 changes: 49 additions & 34 deletions fullstack-network-manager/src/commands/chart.mjs
Original file line number Diff line number Diff line change
@@ -1,49 +1,49 @@
import chalk from 'chalk'
import { FullstackTestingError } from '../core/errors.mjs'
import { BaseCommand } from './base.mjs'
import * as flags from './flags.mjs'
import * as paths from 'path'
import { constants } from '../core/index.mjs'

export class ChartCommand extends BaseCommand {
prepareValuesArg (argv, config) {
const { valuesFile, mirrorNode, hederaExplorer } = argv

prepareValuesFiles (valuesFile) {
let valuesArg = ''
const chartDir = this.configManager.flagValue(config, flags.chartDirectory)
if (chartDir) {
valuesArg = `-f ${chartDir}/fullstack-deployment/values.yaml`
}

if (valuesFile) {
valuesArg += `--values ${valuesFile}`
const valuesFiles = valuesFile.split(',')
valuesFiles.forEach(vf => {
const vfp = paths.resolve(vf)
valuesArg += ` --values ${vfp}`
})
}

valuesArg += ` --set hedera-mirror-node.enabled=${mirrorNode} --set hedera-explorer.enabled=${hederaExplorer}`

return valuesArg
}

async prepareChartPath (config) {
prepareValuesArg (config) {
const valuesFile = this.configManager.flagValue(config, flags.valuesFile)
const deployMirrorNode = this.configManager.flagValue(config, flags.deployMirrorNode)
const deployHederaExplorer = this.configManager.flagValue(config, flags.deployHederaExplorer)

let valuesArg = ''
const chartDir = this.configManager.flagValue(config, flags.chartDirectory)
let chartPath = 'full-stack-testing/fullstack-deployment'
if (chartDir) {
chartPath = `${chartDir}/fullstack-deployment`
await this.helm.dependency('update', chartPath)
valuesArg = `-f ${chartDir}/fullstack-deployment/values.yaml`
}

return chartPath
}
valuesArg += this.prepareValuesFiles(valuesFile)

async install (argv) {
try {
const namespace = argv.namespace
valuesArg += ` --set hedera-mirror-node.enabled=${deployMirrorNode} --set hedera-explorer.enabled=${deployHederaExplorer}`

const config = await this.configManager.setupConfig(argv)
const valuesArg = this.prepareValuesArg(argv, config)
const chartPath = await this.prepareChartPath(config)
return valuesArg
}

await this.chartManager.install(namespace, constants.FST_CHART_DEPLOYMENT_NAME, chartPath, config.version, valuesArg)
async installFSTChart (config) {
try {
const namespace = this.configManager.flagValue(config, flags.namespace)
const valuesArg = this.prepareValuesArg(config)
const chartPath = await this.prepareChartPath(config, constants.CHART_FST_REPO_NAME, constants.CHART_FST_DEPLOYMENT_NAME)

this.logger.showList('charts', await this.chartManager.getInstalledCharts(namespace))
await this.chartManager.install(namespace, constants.CHART_FST_DEPLOYMENT_NAME, chartPath, config.version, valuesArg)

this.logger.showUser(chalk.cyan('> waiting for network-node pods to be active (first deployment takes ~10m) ...'))
await this.kubectl.wait('pod',
Expand All @@ -52,7 +52,19 @@ export class ChartCommand extends BaseCommand {
'--timeout=900s'
)
this.logger.showUser(chalk.green('OK'), 'network-node pods are running')
} catch (e) {
throw new FullstackTestingError(`failed install '${constants.CHART_FST_DEPLOYMENT_NAME}' chart`, e)
}
}

async install (argv) {
try {
const config = await this.configManager.setupConfig(argv)
const namespace = this.configManager.flagValue(config, flags.namespace)

await this.installFSTChart(config)

this.logger.showList('Deployed Charts', await this.chartManager.getInstalledCharts(namespace))
return true
} catch (e) {
this.logger.showUserError(e)
Expand All @@ -64,7 +76,7 @@ export class ChartCommand extends BaseCommand {
async uninstall (argv) {
const namespace = argv.namespace

return await this.chartManager.uninstall(namespace, constants.FST_CHART_DEPLOYMENT_NAME)
return await this.chartManager.uninstall(namespace, constants.CHART_FST_DEPLOYMENT_NAME)
}

async upgrade (argv) {
Expand All @@ -74,7 +86,7 @@ export class ChartCommand extends BaseCommand {
const valuesArg = this.prepareValuesArg(argv, config)
const chartPath = await this.prepareChartPath(config)

return await this.chartManager.upgrade(namespace, constants.FST_CHART_DEPLOYMENT_NAME, chartPath, valuesArg)
return await this.chartManager.upgrade(namespace, constants.CHART_FST_DEPLOYMENT_NAME, chartPath, valuesArg)
}

static getCommandDefinition (chartCmd) {
Expand All @@ -86,13 +98,16 @@ export class ChartCommand extends BaseCommand {
.command({
command: 'install',
desc: 'Install FST network deployment chart',
builder: y => flags.setCommandFlags(y,
flags.namespace,
flags.deployMirrorNode,
flags.deployHederaExplorer,
flags.valuesFile,
flags.chartDirectory
),
builder: y => {
flags.setCommandFlags(y,
flags.namespace,
flags.deployMirrorNode,
flags.deployHederaExplorer,
flags.deployJsonRpcRelay,
flags.valuesFile,
flags.chartDirectory
)
},
handler: argv => {
chartCmd.logger.debug("==== Running 'chart install' ===")
chartCmd.logger.debug(argv)
Expand Down
4 changes: 2 additions & 2 deletions fullstack-network-manager/src/commands/cluster.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export class ClusterCommand extends BaseCommand {
const valuesArg = this.prepareValuesArg(config, argv.prometheusStack, argv.minio, argv.envoyGateway,
argv.certManager, argv.certManagerCrds)
this.logger.showUser(chalk.cyan('> setting up cluster:'), chalk.yellow(`${chartPath}`, chalk.yellow(valuesArg)))
await this.chartManager.install(namespace, constants.FST_CHART_SETUP_NAME, chartPath, config.version, valuesArg)
await this.chartManager.install(namespace, constants.CHART_FST_SETUP_NAME, chartPath, config.version, valuesArg)
await this.showInstalledChartList(namespace)

return true
Expand All @@ -203,7 +203,7 @@ export class ClusterCommand extends BaseCommand {
const valuesArg = this.prepareValuesArg(config, argv.prometheusStack, argv.minio, argv.envoyGateway,
argv.certManager, argv.certManagerCrds)
this.logger.showUser(chalk.cyan('> resetting cluster:'), chalk.yellow(`${chartPath}`, chalk.yellow(valuesArg)))
await this.chartManager.uninstall(namespace, constants.FST_CHART_SETUP_NAME, chartPath, config.version, valuesArg)
await this.chartManager.uninstall(namespace, constants.CHART_FST_SETUP_NAME, chartPath, config.version, valuesArg)

await this.showInstalledChartList(namespace)

Expand Down
66 changes: 60 additions & 6 deletions fullstack-network-manager/src/commands/flags.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const deployHederaExplorer = {
export const valuesFile = {
name: 'values-file',
definition: {
describe: 'Helm chart values file [ to override defaults ]',
describe: 'Comma separated chart values files',
default: '',
alias: 'f',
type: 'string'
Expand Down Expand Up @@ -112,10 +112,20 @@ export const deployCertManagerCRDs = {
}
}

export const platformReleaseTag = {
export const deployJsonRpcRelay = {
name: 'json-rpc-relay',
definition: {
describe: 'Deploy JSON RPC Relay',
default: false,
alias: 'j',
type: 'boolean'
}
}

export const releaseTag = {
name: 'release-tag',
definition: {
describe: 'Platform release tag (e.g. v0.42.4, fetch build-<tag>.zip from https://builds.hedera.com)',
describe: 'Release tag to be used (e.g. v0.42.5)',
default: '',
alias: 't',
type: 'string'
Expand All @@ -125,7 +135,7 @@ export const platformReleaseTag = {
export const platformReleaseDir = {
name: 'release-dir',
definition: {
describe: 'Platform release cache dir (containing release directories named as v<major>.<minor>. e.g. v0.42)',
describe: 'Platform release cache (containing release directories named as v<major>.<minor>. e.g. v0.42)',
default: core.constants.FST_CACHE_DIR,
alias: 'd',
type: 'string'
Expand Down Expand Up @@ -162,19 +172,63 @@ export const chartDirectory = {
}
}

export const replicaCount = {
name: 'replica-count',
definition: {
describe: 'Replica count',
default: 1,
alias: '',
type: 'number'
}
}

export const chainId = {
name: 'chain-id',
definition: {
describe: 'Chain ID',
default: '298', // Ref: https://github.com/hashgraph/hedera-json-rpc-relay#configuration
type: 'string'
}
}

// Ref: https://github.com/hashgraph/hedera-json-rpc-relay/blob/main/docs/configuration.md
export const operatorId = {
name: 'operator-id',
definition: {
describe: 'Operator ID',
default: '0.0.2',
type: 'string'
}
}

// Ref: https://github.com/hashgraph/hedera-json-rpc-relay/blob/main/docs/configuration.md
export const operatorKey = {
name: 'operator-key',
definition: {
describe: 'Operator Key',
default: '302e020100300506032b65700422042091132178e72057a1d7528025956fe39b0b847f200ab59b2fdd367017f3087137',
type: 'string'
}
}

export const allFlags = [
clusterName,
namespace,
deployMirrorNode,
deployHederaExplorer,
deployJsonRpcRelay,
valuesFile,
deployPrometheusStack,
deployMinio,
deployEnvoyGateway,
deployCertManagerCRDs,
platformReleaseTag,
releaseTag,
platformReleaseDir,
nodeIDs,
force,
chartDirectory
chartDirectory,
replicaCount,
chainId,
operatorId,
operatorKey
]
5 changes: 4 additions & 1 deletion fullstack-network-manager/src/commands/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ClusterCommand } from './cluster.mjs'
import { InitCommand } from './init.mjs'
import { ChartCommand } from './chart.mjs'
import { NodeCommand } from './node.mjs'
import { RelayCommand } from './relay.mjs'

/*
* Return a list of Yargs command builder to be exposed through CLI
Expand All @@ -12,12 +13,14 @@ function Initialize (opts) {
const clusterCmd = new ClusterCommand(opts)
const chartCmd = new ChartCommand(opts)
const nodeCmd = new NodeCommand(opts)
const relayCmd = new RelayCommand(opts)

return [
InitCommand.getCommandDefinition(initCmd),
ClusterCommand.getCommandDefinition(clusterCmd),
ChartCommand.getCommandDefinition(chartCmd),
NodeCommand.getCommandDefinition(nodeCmd)
NodeCommand.getCommandDefinition(nodeCmd),
RelayCommand.getCommandDefinition(relayCmd)
]
}

Expand Down
2 changes: 1 addition & 1 deletion fullstack-network-manager/src/commands/init.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class InitCommand extends BaseCommand {
this.logger.showUser(chalk.green('OK: All required dependencies are found: %s'), chalk.yellow(deps))

const repoURLs = await this.chartManager.setup()
this.logger.showUser(chalk.green('OK: Chart repositories are initialized'), chalk.yellow(repoURLs))
this.logger.showList('Chart Repository', repoURLs)

return status
} catch (e) {
Expand Down
Loading

0 comments on commit 8b398fd

Please sign in to comment.