diff --git a/clients/js/__fixtures__/config.yaml b/clients/js/__fixtures__/config.yaml index 2ff154ed..e388ff41 100644 --- a/clients/js/__fixtures__/config.yaml +++ b/clients/js/__fixtures__/config.yaml @@ -1,3 +1,6 @@ +name: starship +version: v0.2.3 + chains: - id: osmosis-1 name: osmosis diff --git a/clients/js/__fixtures__/local-config.yaml b/clients/js/__fixtures__/local-config.yaml index d7239a0c..eb7358b0 100644 --- a/clients/js/__fixtures__/local-config.yaml +++ b/clients/js/__fixtures__/local-config.yaml @@ -1,3 +1,6 @@ +name: starship +version: v0.2.3 + chains: - id: osmosis-1 name: osmosis diff --git a/clients/js/__fixtures__/starship-context-config.yaml b/clients/js/__fixtures__/starship-context-config.yaml deleted file mode 100644 index fb22b92a..00000000 --- a/clients/js/__fixtures__/starship-context-config.yaml +++ /dev/null @@ -1,2 +0,0 @@ -helmFile: ./config.yaml -helmVersion: v0.2.3 diff --git a/clients/js/packages/cli/src/utils.ts b/clients/js/packages/cli/src/utils.ts index a43b2ddc..d9151b34 100644 --- a/clients/js/packages/cli/src/utils.ts +++ b/clients/js/packages/cli/src/utils.ts @@ -48,7 +48,7 @@ export const loadConfig = (argv: any): Config => { let starship: StarshipConfig = {} as StarshipConfig; if (argv.config) { - context = deepmerge(defaultStarshipContext, loadYaml(argv.config)) as StarshipContext + context.helmFile = argv.config; } console.log("context", context); @@ -89,19 +89,24 @@ Commands: version, -v Display the version of the Starship Client. Configuration File: - --config Specify the path to the JSON configuration file containing all settings. + --config Specify the path to the configuration file containing the actual config file. Required. Command-line options will override settings from this file if both are provided. Command-line Options: - --helmFile Specify the path to the Helm file, the actual config file. Required. --helmName Specify the Helm release name, default: starship. - --helmVersion Specify the version of the Helm chart, default: v0.2.0. + Will overide config file settings for name. + --helmVersion Specify the version of the Helm chart, default: v0.2.3. + Will overide config file settings for version. Examples: - $ starship setup - $ starship deploy --helmFile ./config/helm.yaml --helmName my-release - $ starship start-ports --config ./config/settings.json - $ starship stop --config ./config/settings.json + $ starship start --config ./config/two-chain.yaml + $ starship stop --config ./config/two-chain.yaml + +If you want to run the deployment step by step + $ starship deploy --config ./config/two-chain.yaml + $ starship start-ports --config ./config/two-chain.yaml + $ starship stop-ports --config ./config/two-chain.yaml + $ starship stop --config ./config/two-chain.yaml Additional Help: $ starship help Display this help information. diff --git a/clients/js/packages/client/__tests__/__snapshots__/client.config.test.ts.snap b/clients/js/packages/client/__tests__/__snapshots__/client.config.test.ts.snap index 42a3a548..d5ee5415 100644 --- a/clients/js/packages/client/__tests__/__snapshots__/client.config.test.ts.snap +++ b/clients/js/packages/client/__tests__/__snapshots__/client.config.test.ts.snap @@ -1,16 +1,17 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`StarshipClient setup 1`] = ` -"Call: setConfig({"chains":[{"id":"osmosis-1","name":"osmosis","image":"pyramation/osmosis:v16.1.0","numValidators":1,"ports":{"rest":1317,"rpc":26657,"faucet":8007}},{"id":"cosmos-2","name":"cosmos","numValidators":1,"ports":{"rest":1313,"rpc":26653,"faucet":8003}}],"relayers":[{"name":"osmos-cosmos","type":"hermes","replicas":1,"chains":["osmosis-1","cosmos-2"]}],"registry":{"enabled":true,"ports":{"rest":8081,"grpc":9091}}}) +"Call: setConfig({"name":"starship","version":"v0.2.3","chains":[{"id":"osmosis-1","name":"osmosis","image":"pyramation/osmosis:v16.1.0","numValidators":1,"ports":{"rest":1317,"rpc":26657,"faucet":8007}},{"id":"cosmos-2","name":"cosmos","numValidators":1,"ports":{"rest":1313,"rpc":26653,"faucet":8003}}],"relayers":[{"name":"osmos-cosmos","type":"hermes","replicas":1,"chains":["osmosis-1","cosmos-2"]}],"registry":{"enabled":true,"ports":{"rest":8081,"grpc":9091}}}) +Log: config again: [object Object] Call: saveConfig() Call: savePodPorts("../../__output__/default-pod-ports.yaml") Call: setup() helm repo add starship https://cosmology-tech.github.io/starship/ helm repo update -helm search repo starship/devnet --version v0.2.4 +helm search repo starship/devnet --version v0.2.3 Call: deploy() Log: Installing the helm chart. This is going to take a while..... -helm install -f ../../__fixtures__/config.yaml osmojs starship/devnet --version v0.2.4 +helm install -f ../../__fixtures__/config.yaml osmojs starship/devnet --version v0.2.3 Log: Run "starship get-pods" to check the status of the cluster Call: startPortForward() Log: Attempting to stop any existing port-forwards... @@ -44,8 +45,8 @@ helm delete osmojs" exports[`StarshipClient setup 2`] = ` "helm repo add starship https://cosmology-tech.github.io/starship/ helm repo update -helm search repo starship/devnet --version v0.2.4 -helm install -f ../../__fixtures__/config.yaml osmojs starship/devnet --version v0.2.4 +helm search repo starship/devnet --version v0.2.3 +helm install -f ../../__fixtures__/config.yaml osmojs starship/devnet --version v0.2.3 ps -ef | grep -i 'kubectl port-forward' | grep -v 'grep' | awk '{print $2}' sleep 2 kubectl port-forward pods/osmosis-1-genesis-0 26657:26657 > /dev/null 2>&1 & diff --git a/clients/js/packages/client/__tests__/__snapshots__/client.ports.test.ts.snap b/clients/js/packages/client/__tests__/__snapshots__/client.ports.test.ts.snap index 88773a66..aed92e67 100644 --- a/clients/js/packages/client/__tests__/__snapshots__/client.ports.test.ts.snap +++ b/clients/js/packages/client/__tests__/__snapshots__/client.ports.test.ts.snap @@ -1,16 +1,17 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`StarshipClient setup 1`] = ` -"Call: setConfig({"chains":[{"id":"osmosis-1","name":"osmosis","image":"pyramation/osmosis:v16.1.0","numValidators":1,"ports":{"rest":1317,"rpc":26657,"faucet":8007}},{"id":"cosmos-2","name":"cosmos","numValidators":1,"ports":{"rest":1313,"rpc":26653,"faucet":8003}}],"relayers":[{"name":"osmos-cosmos","type":"hermes","replicas":1,"chains":["osmosis-1","cosmos-2"]}],"registry":{"enabled":true,"ports":{"rest":8081,"grpc":9091}}}) +"Call: setConfig({"name":"starship","version":"v0.2.3","chains":[{"id":"osmosis-1","name":"osmosis","image":"pyramation/osmosis:v16.1.0","numValidators":1,"ports":{"rest":1317,"rpc":26657,"faucet":8007}},{"id":"cosmos-2","name":"cosmos","numValidators":1,"ports":{"rest":1313,"rpc":26653,"faucet":8003}}],"relayers":[{"name":"osmos-cosmos","type":"hermes","replicas":1,"chains":["osmosis-1","cosmos-2"]}],"registry":{"enabled":true,"ports":{"rest":8081,"grpc":9091}}}) +Log: config again: [object Object] Call: setPodPorts({"chains":{"osmosis":{"exposer":98988,"faucet":1000000,"grpc":909090,"rest":6767676}}}) Call: savePodPorts("../../__output__/custom-pod-ports.yaml") Call: setup() helm repo add starship https://cosmology-tech.github.io/starship/ helm repo update -helm search repo starship/devnet --version v0.2.4 +helm search repo starship/devnet --version v0.2.3 Call: deploy() Log: Installing the helm chart. This is going to take a while..... -helm install -f ../../__fixtures__/config.yaml osmojs starship/devnet --version v0.2.4 +helm install -f ../../__fixtures__/config.yaml osmojs starship/devnet --version v0.2.3 Log: Run "starship get-pods" to check the status of the cluster Call: startPortForward() Log: Attempting to stop any existing port-forwards... @@ -42,8 +43,8 @@ helm delete osmojs" exports[`StarshipClient setup 2`] = ` "helm repo add starship https://cosmology-tech.github.io/starship/ helm repo update -helm search repo starship/devnet --version v0.2.4 -helm install -f ../../__fixtures__/config.yaml osmojs starship/devnet --version v0.2.4 +helm search repo starship/devnet --version v0.2.3 +helm install -f ../../__fixtures__/config.yaml osmojs starship/devnet --version v0.2.3 ps -ef | grep -i 'kubectl port-forward' | grep -v 'grep' | awk '{print $2}' sleep 2 kubectl port-forward pods/osmosis-1-genesis-0 1317:6767676 > /dev/null 2>&1 & diff --git a/clients/js/packages/client/__tests__/__snapshots__/client.test.ts.snap b/clients/js/packages/client/__tests__/__snapshots__/client.test.ts.snap index 989bd460..9e314eca 100644 --- a/clients/js/packages/client/__tests__/__snapshots__/client.test.ts.snap +++ b/clients/js/packages/client/__tests__/__snapshots__/client.test.ts.snap @@ -1,14 +1,15 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`StarshipClient setup 1`] = ` -"Call: setConfig({"chains":[{"id":"osmosis-1","name":"osmosis","image":"pyramation/osmosis:v16.1.0","numValidators":1,"ports":{"rest":1317,"rpc":26657,"faucet":8007}},{"id":"cosmos-2","name":"cosmos","numValidators":1,"ports":{"rest":1313,"rpc":26653,"faucet":8003}}],"relayers":[{"name":"osmos-cosmos","type":"hermes","replicas":1,"chains":["osmosis-1","cosmos-2"]}],"registry":{"enabled":true,"ports":{"rest":8081,"grpc":9091}}}) +"Call: setConfig({"name":"starship","version":"v0.2.3","chains":[{"id":"osmosis-1","name":"osmosis","image":"pyramation/osmosis:v16.1.0","numValidators":1,"ports":{"rest":1317,"rpc":26657,"faucet":8007}},{"id":"cosmos-2","name":"cosmos","numValidators":1,"ports":{"rest":1313,"rpc":26653,"faucet":8003}}],"relayers":[{"name":"osmos-cosmos","type":"hermes","replicas":1,"chains":["osmosis-1","cosmos-2"]}],"registry":{"enabled":true,"ports":{"rest":8081,"grpc":9091}}}) +Log: config again: [object Object] Call: setup() helm repo add starship https://cosmology-tech.github.io/starship/ helm repo update -helm search repo starship/devnet --version v0.2.4 +helm search repo starship/devnet --version v0.2.3 Call: deploy() Log: Installing the helm chart. This is going to take a while..... -helm install -f ../../__fixtures__/config.yaml osmojs starship/devnet --version v0.2.4 +helm install -f ../../__fixtures__/config.yaml osmojs starship/devnet --version v0.2.3 Log: Run "starship get-pods" to check the status of the cluster Call: startPortForward() Log: Attempting to stop any existing port-forwards... @@ -42,8 +43,8 @@ helm delete osmojs" exports[`StarshipClient setup 2`] = ` "helm repo add starship https://cosmology-tech.github.io/starship/ helm repo update -helm search repo starship/devnet --version v0.2.4 -helm install -f ../../__fixtures__/config.yaml osmojs starship/devnet --version v0.2.4 +helm search repo starship/devnet --version v0.2.3 +helm install -f ../../__fixtures__/config.yaml osmojs starship/devnet --version v0.2.3 ps -ef | grep -i 'kubectl port-forward' | grep -v 'grep' | awk '{print $2}' sleep 2 kubectl port-forward pods/osmosis-1-genesis-0 26657:26657 > /dev/null 2>&1 & diff --git a/clients/js/packages/client/src/client.ts b/clients/js/packages/client/src/client.ts index f72d511f..0e019527 100644 --- a/clients/js/packages/client/src/client.ts +++ b/clients/js/packages/client/src/client.ts @@ -25,12 +25,12 @@ export interface StarshipContext { }; export const defaultStarshipContext: Partial = { - helmName: 'starship', + helmName: '', helmRepo: 'starship', helmRepoUrl: 'https://cosmology-tech.github.io/starship/', helmChart: 'starship/devnet', - helmVersion: 'v0.2.4', helmNamespace: '', + helmVersion: '', }; export interface PodPorts { @@ -46,6 +46,9 @@ export interface PodPorts { }, } +const defaultName: string = "starship" +const defaultVersion: string = "v0.2.4" + // TODO talk to Anmol about moving these into yaml, if not already possible? const defaultPorts: PodPorts = { explorer: { @@ -205,6 +208,7 @@ export class StarshipClient implements StarshipClientI { public loadConfig(): void { this.ensureFileExists(this.ctx.helmFile); this.config = this.loadYaml(this.ctx.helmFile) as StarshipConfig; + this.overrideNameAndVersion(); } public saveConfig(): void { @@ -222,6 +226,7 @@ export class StarshipClient implements StarshipClientI { public setConfig(config: StarshipConfig): void { this.config = config; + this.overrideNameAndVersion(); } public setContext(ctx: StarshipContext): void { @@ -232,6 +237,32 @@ export class StarshipClient implements StarshipClientI { this.podPorts = deepmerge(defaultPorts, ports); } + private overrideNameAndVersion(): void { + if (!this.config) { + throw new Error('no config!'); + } + + // Override config name and version if provided in context + if (this.ctx.helmName) { + this.config.name = this.ctx.helmName; + } + if (this.ctx.helmVersion) { + this.config.version = this.ctx.helmVersion; + } + + // Use default name and version if not provided + if (!this.config.name) { + this.log(chalk.yellow("No name specified, using default name: " + defaultName)); + this.config.name = defaultName; + } + if (!this.config.version) { + this.log(chalk.yellow("No version specified, using default version: " + defaultVersion)); + this.config.version = defaultVersion; + } + + this.log('config again: ' + this.config); + } + public getArgs(): string[] { const args = []; if (this.ctx.helmNamespace) { @@ -287,7 +318,7 @@ export class StarshipClient implements StarshipClientI { 'repo', this.ctx.helmChart, '--version', - this.ctx.helmVersion + this.config.version ]); } @@ -307,10 +338,10 @@ export class StarshipClient implements StarshipClientI { 'install', '-f', this.ctx.helmFile, - this.ctx.helmName, + this.config.name, this.ctx.helmChart, '--version', - this.ctx.helmVersion, + this.config.version, ...this.getDeployArgs(), ...options, ]; @@ -341,7 +372,7 @@ export class StarshipClient implements StarshipClientI { } public deleteHelm(): void { - this.exec(['helm', 'delete', this.ctx.helmName]); + this.exec(['helm', 'delete', this.config.name]); } public getPods(): void { diff --git a/clients/js/packages/client/src/config.ts b/clients/js/packages/client/src/config.ts index 50c7a99c..9ea3e3f7 100644 --- a/clients/js/packages/client/src/config.ts +++ b/clients/js/packages/client/src/config.ts @@ -145,6 +145,8 @@ export interface Images { } export interface StarshipConfig { + name: string, + version: string, chains: Chain[]; relayers?: Relayer[]; explorer?: Explorer; diff --git a/starship/charts/devnet/values.schema.json b/starship/charts/devnet/values.schema.json index 081fe4b7..6e25797b 100644 --- a/starship/charts/devnet/values.schema.json +++ b/starship/charts/devnet/values.schema.json @@ -3,6 +3,12 @@ "title": "Generated schema for Root", "type": "object", "properties": { + "name": { + "type": "string" + }, + "version": { + "type": "string" + }, "resources": { "type": "object", "properties": {