Skip to content
This repository has been archived by the owner on Jun 13, 2024. It is now read-only.

Commit

Permalink
cleanup and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
pyramation committed Apr 20, 2024
1 parent 463d6ee commit c58286a
Show file tree
Hide file tree
Showing 15 changed files with 376 additions and 30 deletions.
43 changes: 35 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,17 @@
<a href="https://github.com/cosmology-tech/starshipjs/blob/main/LICENSE"><img height="20" src="https://img.shields.io/badge/license-BSD%203--Clause%20Clear-blue.svg"></a>
</p>

Universal interchain development environment in k8s. The vision of this project is to have a single easy to use developer environment with full testing support for multichain use cases
**StarshipJS** is the JS companion to deploy and manage [Starship](https://github.com/cosmology-tech/starship), tailored specifically for Node.js and TypeScript developers. This toolkit provides a seamless, easy-to-use interface that dramatically simplifies the development, testing, and deployment of interchain applications, whether on your local machine or CI/CD environments.

Utilities for [Starship](https://github.com/cosmology-tech/starship) 🚀
Designed with simplicity and speed in mind, **StarshipJS** enables developers to quickly integrate Starship into their blockchain projects without complex orchestration.

## Features

👨🏻‍💻 **Node.js and TypeScript Focused**: Tailored specifically for JavaScript ecosystems, **StarshipJS** brings simplicity to multi-chain development for Node.js and TypeScript environments, streamlining the setup and coding processes.

🚀 **Simplified Interchain Development**: Enables the straightforward creation of applications that span multiple blockchain networks. This simplifies complex blockchain interactions, enhancing interoperability and making it easier to build sophisticated interchain solutions.

🔒 **Security-First Approach**: **StarshipJS** incorporates security best practices from the ground up. Facilitates secure coding practices and configurations, helping developers build secure blockchain applications by default, reducing the risk of vulnerabilities.

## install

Expand All @@ -30,13 +38,17 @@ npm install starshipjs @starship-ci/client
- [Install](#install)
- [Table of contents](#table-of-contents)
- [Usage](#usage)
- [Initializing the Client](#initializing-the-client)
- [Starting Port Forwarding](#setting-up-and-installing-the-chart)
- [Stopping And Cleaning up](#stopping-and-cleaning-up)
- [Configuration](#configuration)
- [Using the StarshipClient](#using-the-starshipclient)
- [Initializing the Client](#initializing-the-client)
- [Starting Port Forwarding](#setting-up-and-installing-the-chart)
- [Stopping And Cleaning up](#stopping-and-cleaning-up)
- [Developing](#developing)
- [Credits](#credits)

## Using the StarshipClient
## Usage

### Using the StarshipClient

The `StarshipClient` simplifies managing Kubernetes resources, specifically tailored for developers working in interchain environments. Below is an example showing how to instantiate the client and use it to manage a Helm deployment:

Expand All @@ -57,6 +69,21 @@ const client = new StarshipClient({
});
```

### Configuration

After initializing, you can load in your config. Assuming you have a `yaml` file:

```js
client.loadConfig();
```

If you don't have one, you can set and save a configuration directly from the client:

```js
client.setConfig(config);
client.saveConfig(config);
```

### Setting Up and Installing the Chart

After initializing, set up the environment and install the starship helm chart:
Expand All @@ -68,15 +95,15 @@ client.setup();
client.deploy();
```

## Starting Port Forwarding
### Starting Port Forwarding

For local development, you might need to forward ports from your Kubernetes pods:

```js
client.startPortForward();
```

## Stopping and Cleaning Up
### Stopping and Cleaning Up

Once done with development or testing, you can stop the port forwarding and remove the Helm chart:

Expand Down
16 changes: 16 additions & 0 deletions __output__/custom-pod-ports.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
explorer:
rest: 8080
registry:
grpc: 9090
rest: 8080
chains:
defaultPorts:
rpc: 26657
rest: 1317
exposer: 8081
faucet: 8000
osmosis:
exposer: 98988
faucet: 1000000
grpc: 909090
rest: 6767676
11 changes: 11 additions & 0 deletions __output__/default-pod-ports.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
explorer:
rest: 8080
registry:
grpc: 9090
rest: 8080
chains:
defaultPorts:
rpc: 26657
rest: 1317
exposer: 8081
faucet: 8000
43 changes: 35 additions & 8 deletions ci/client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,17 @@
<a href="https://github.com/cosmology-tech/starshipjs/blob/main/LICENSE"><img height="20" src="https://img.shields.io/badge/license-BSD%203--Clause%20Clear-blue.svg"></a>
</p>

Universal interchain development environment in k8s. The vision of this project is to have a single easy to use developer environment with full testing support for multichain use cases
**StarshipJS** is the JS companion to deploy and manage [Starship](https://github.com/cosmology-tech/starship), tailored specifically for Node.js and TypeScript developers. This toolkit provides a seamless, easy-to-use interface that dramatically simplifies the development, testing, and deployment of interchain applications, whether on your local machine or CI/CD environments.

Utilities for [Starship](https://github.com/cosmology-tech/starship) 🚀
Designed with simplicity and speed in mind, **StarshipJS** enables developers to quickly integrate Starship into their blockchain projects without complex orchestration.

## Features

👨🏻‍💻 **Node.js and TypeScript Focused**: Tailored specifically for JavaScript ecosystems, **StarshipJS** brings simplicity to multi-chain development for Node.js and TypeScript environments, streamlining the setup and coding processes.

🚀 **Simplified Interchain Development**: Enables the straightforward creation of applications that span multiple blockchain networks. This simplifies complex blockchain interactions, enhancing interoperability and making it easier to build sophisticated interchain solutions.

🔒 **Security-First Approach**: **StarshipJS** incorporates security best practices from the ground up. Facilitates secure coding practices and configurations, helping developers build secure blockchain applications by default, reducing the risk of vulnerabilities.

## install

Expand All @@ -30,13 +38,17 @@ npm install starshipjs @starship-ci/client
- [Install](#install)
- [Table of contents](#table-of-contents)
- [Usage](#usage)
- [Initializing the Client](#initializing-the-client)
- [Starting Port Forwarding](#setting-up-and-installing-the-chart)
- [Stopping And Cleaning up](#stopping-and-cleaning-up)
- [Configuration](#configuration)
- [Using the StarshipClient](#using-the-starshipclient)
- [Initializing the Client](#initializing-the-client)
- [Starting Port Forwarding](#setting-up-and-installing-the-chart)
- [Stopping And Cleaning up](#stopping-and-cleaning-up)
- [Developing](#developing)
- [Credits](#credits)

## Using the StarshipClient
## Usage

### Using the StarshipClient

The `StarshipClient` simplifies managing Kubernetes resources, specifically tailored for developers working in interchain environments. Below is an example showing how to instantiate the client and use it to manage a Helm deployment:

Expand All @@ -57,6 +69,21 @@ const client = new StarshipClient({
});
```

### Configuration

After initializing, you can load in your config. Assuming you have a `yaml` file:

```js
client.loadConfig();
```

If you don't have one, you can set and save a configuration directly from the client:

```js
client.setConfig(config);
client.saveConfig(config);
```

### Setting Up and Installing the Chart

After initializing, set up the environment and install the starship helm chart:
Expand All @@ -68,15 +95,15 @@ client.setup();
client.deploy();
```

## Starting Port Forwarding
### Starting Port Forwarding

For local development, you might need to forward ports from your Kubernetes pods:

```js
client.startPortForward();
```

## Stopping and Cleaning Up
### Stopping and Cleaning Up

Once done with development or testing, you can stop the port forwarding and remove the Helm chart:

Expand Down
65 changes: 65 additions & 0 deletions ci/client/__tests__/__snapshots__/client.config.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`StarshipClient setup 1`] = `
"Call: setConfig({"chains":[{"name":"osmosis-1","type":"osmosis","image":"pyramation/osmosis:v16.1.0","numValidators":1,"ports":{"rest":1317,"rpc":26657,"faucet":8007}},{"name":"cosmos-2","type":"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: 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.1.38
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.1.38
Log: Run "kubectl get pods" to check the status of the cluster
Call: startPortForward()
Log: Attempting to stop any existing port-forwards...
Log: Trying to stop all port-forward, if any....
ps -ef | grep -i 'kubectl port-forward' | grep -v 'grep' | awk '{print $2}'
sleep 2
Log: Starting new port forwarding...
kubectl port-forward pods/osmosis-1-genesis-0 26657:26657 > /dev/null 2>&1 &
Log: Forwarded osmosis-1: local 26657 -> target (host) 26657
kubectl port-forward pods/osmosis-1-genesis-0 1317:1317 > /dev/null 2>&1 &
Log: Forwarded osmosis-1: local 1317 -> target (host) 1317
kubectl port-forward pods/osmosis-1-genesis-0 8007:8000 > /dev/null 2>&1 &
Log: Forwarded osmosis-1: local 8007 -> target (host) 8000
kubectl port-forward pods/cosmos-2-genesis-0 26653:26657 > /dev/null 2>&1 &
Log: Forwarded cosmos-2: local 26653 -> target (host) 26657
kubectl port-forward pods/cosmos-2-genesis-0 1313:1317 > /dev/null 2>&1 &
Log: Forwarded cosmos-2: local 1313 -> target (host) 1317
kubectl port-forward pods/cosmos-2-genesis-0 8003:8000 > /dev/null 2>&1 &
Log: Forwarded cosmos-2: local 8003 -> target (host) 8000
kubectl port-forward service/registry 8081:8080 > /dev/null 2>&1 &
Log: Forwarded registry on port 8081 to target port 8080
kubectl port-forward service/registry 9091:9090 > /dev/null 2>&1 &
Log: Forwarded registry on port 9091 to target port 9090
Call: undeploy()
Log: Trying to stop all port-forward, if any....
ps -ef | grep -i 'kubectl port-forward' | grep -v 'grep' | awk '{print $2}'
sleep 2
helm delete osmojs
Call: teardown()
helm repo remove starship"
`;

exports[`StarshipClient setup 2`] = `
"helm repo add starship https://cosmology-tech.github.io/starship/
helm repo update
helm search repo starship/devnet --version v0.1.38
helm install -f ../../__fixtures__/config.yaml osmojs starship/devnet --version v0.1.38
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 &
kubectl port-forward pods/osmosis-1-genesis-0 1317:1317 > /dev/null 2>&1 &
kubectl port-forward pods/osmosis-1-genesis-0 8007:8000 > /dev/null 2>&1 &
kubectl port-forward pods/cosmos-2-genesis-0 26653:26657 > /dev/null 2>&1 &
kubectl port-forward pods/cosmos-2-genesis-0 1313:1317 > /dev/null 2>&1 &
kubectl port-forward pods/cosmos-2-genesis-0 8003:8000 > /dev/null 2>&1 &
kubectl port-forward service/registry 8081:8080 > /dev/null 2>&1 &
kubectl port-forward service/registry 9091:9090 > /dev/null 2>&1 &
ps -ef | grep -i 'kubectl port-forward' | grep -v 'grep' | awk '{print $2}'
sleep 2
helm delete osmojs
helm repo remove starship"
`;
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
exports[`StarshipClient setup 1`] = `
"Call: setConfig({"chains":[{"name":"osmosis-1","type":"osmosis","image":"pyramation/osmosis:v16.1.0","numValidators":1,"ports":{"rest":1317,"rpc":26657,"faucet":8007}},{"name":"cosmos-2","type":"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: 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
Expand Down
36 changes: 36 additions & 0 deletions ci/client/__tests__/client.config.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { join, relative } from 'path';

import { createClient, expectClient } from '../test-utils/client';
import { config, outputDir } from '../test-utils/config';

describe('StarshipClient', () => {
it('setup', () => {
const { client, ctx } = createClient();

client.dependencies.forEach(dep => dep.installed = true);

client.setConfig(config.config);
const helmFile = client.ctx.helmFile;
client.ctx.helmFile = join(outputDir, 'my-config.yaml');
client.ctx.helmFile = relative(process.cwd(), client.ctx.helmChart)
client.saveConfig();
client.ctx.helmFile = helmFile;

const portYaml = join(outputDir, 'default-pod-ports.yaml');
const relativePortYaml = relative(process.cwd(), portYaml);
client.savePodPorts(relativePortYaml);

// helm
client.setup();
client.deploy();

client.startPortForward();

client.undeploy();

// remove helm chart
client.teardown();

expectClient(ctx, -1);
});
});
7 changes: 6 additions & 1 deletion ci/client/__tests__/client.ports.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { join, relative } from 'path';
import { createClient, expectClient } from '../test-utils/client';
import { config } from '../test-utils/config';
import { config, outputDir } from '../test-utils/config';

describe('StarshipClient', () => {
it('setup', () => {
Expand All @@ -18,6 +19,10 @@ describe('StarshipClient', () => {
}
}
});
const portYaml = join(outputDir, 'custom-pod-ports.yaml');
const relativePortYaml = relative(process.cwd(), portYaml);
client.savePodPorts(relativePortYaml);


// helm
client.setup();
Expand Down
28 changes: 28 additions & 0 deletions ci/client/devnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
chains:
- name: osmosis-1
type: osmosis
image: pyramation/osmosis:v16.1.0
numValidators: 1
ports:
rest: 1317
rpc: 26657
faucet: 8007
- name: cosmos-2
type: 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
3 changes: 2 additions & 1 deletion ci/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"deepmerge": "^4.3.1",
"js-yaml": "^4.1.0",
"semver": "7.6.0",
"shelljs": "^0.8.5"
"shelljs": "^0.8.5",
"mkdirp": "3.0.1"
},
"devDependencies": {
"@types/shelljs": "^0.8.15"
Expand Down
Loading

0 comments on commit c58286a

Please sign in to comment.