Skip to content

Commit

Permalink
feature: combine config starship (#475)
Browse files Browse the repository at this point in the history
* add name and version to the config file, set --config to point to helmFile instead of settings for starship

* update help txt

* update test fixtures

* update all snapshots
  • Loading branch information
Anmol1696 committed Jun 21, 2024
1 parent fb278c8 commit 7111966
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 31 deletions.
3 changes: 3 additions & 0 deletions clients/js/__fixtures__/config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
name: starship
version: v0.2.3

chains:
- id: osmosis-1
name: osmosis
Expand Down
3 changes: 3 additions & 0 deletions clients/js/__fixtures__/local-config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
name: starship
version: v0.2.3

chains:
- id: osmosis-1
name: osmosis
Expand Down
2 changes: 0 additions & 2 deletions clients/js/__fixtures__/starship-context-config.yaml

This file was deleted.

21 changes: 13 additions & 8 deletions clients/js/packages/cli/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -89,19 +89,24 @@ Commands:
version, -v Display the version of the Starship Client.
Configuration File:
--config <path> Specify the path to the JSON configuration file containing all settings.
--config <path> 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 <path> Specify the path to the Helm file, the actual config file. Required.
--helmName <name> Specify the Helm release name, default: starship.
--helmVersion <ver> Specify the version of the Helm chart, default: v0.2.0.
Will overide config file settings for name.
--helmVersion <ver> 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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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...
Expand Down Expand Up @@ -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 &
Expand Down
Original file line number Diff line number Diff line change
@@ -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...
Expand Down Expand Up @@ -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 &
Expand Down
Original file line number Diff line number Diff line change
@@ -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...
Expand Down Expand Up @@ -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 &
Expand Down
43 changes: 37 additions & 6 deletions clients/js/packages/client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ export interface StarshipContext {
};

export const defaultStarshipContext: Partial<StarshipContext> = {
helmName: 'starship',
helmName: '',
helmRepo: 'starship',
helmRepoUrl: 'https://cosmology-tech.github.io/starship/',
helmChart: 'starship/devnet',
helmVersion: 'v0.2.4',
helmNamespace: '',
helmVersion: '',
};

export interface PodPorts {
Expand All @@ -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: {
Expand Down Expand Up @@ -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 {
Expand All @@ -222,6 +226,7 @@ export class StarshipClient implements StarshipClientI {

public setConfig(config: StarshipConfig): void {
this.config = config;
this.overrideNameAndVersion();
}

public setContext(ctx: StarshipContext): void {
Expand All @@ -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) {
Expand Down Expand Up @@ -287,7 +318,7 @@ export class StarshipClient implements StarshipClientI {
'repo',
this.ctx.helmChart,
'--version',
this.ctx.helmVersion
this.config.version
]);
}

Expand All @@ -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,
];
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions clients/js/packages/client/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ export interface Images {
}

export interface StarshipConfig {
name: string,
version: string,
chains: Chain[];
relayers?: Relayer[];
explorer?: Explorer;
Expand Down
6 changes: 6 additions & 0 deletions starship/charts/devnet/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
"title": "Generated schema for Root",
"type": "object",
"properties": {
"name": {
"type": "string"
},
"version": {
"type": "string"
},
"resources": {
"type": "object",
"properties": {
Expand Down

0 comments on commit 7111966

Please sign in to comment.