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

Commit

Permalink
snaps and logs
Browse files Browse the repository at this point in the history
  • Loading branch information
pyramation committed Apr 20, 2024
1 parent 33ce9a2 commit 5da3410
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 27 deletions.
6 changes: 6 additions & 0 deletions ci/utils/__tests__/__snapshots__/client.deps.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@ exports[`StarshipClient has all deps 2`] = `"something"`;

exports[`StarshipClient missing deps 1`] = `
"Call: exec(["something"])
Log⬇
xkubectl
xdocker
✓helm
✓yq
EndLog⬆
Log⬇
Please install the missing dependencies:
EndLog⬆
Log⬇
kubectl: https://kubernetes.io/docs/tasks/tools/
Expand All @@ -25,6 +30,7 @@ docker: https://docs.docker.com/get-docker/
For macOS, you may also consider Docker for Mac: https://docs.docker.com/desktop/install/mac-install/
EndLog⬆
something"
`;

Expand Down
61 changes: 61 additions & 0 deletions ci/utils/__tests__/__snapshots__/client.ports.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// 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: setPodPorts({"chains":{"osmosis":{"exposer":98988,"faucet":1000000,"grpc":909090,"rest":6767676}}})
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: install()
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 1317:6767676 > /dev/null 2>&1 &
Log: Forwarded osmosis-1: local 1317 -> target (host) 6767676
kubectl port-forward pods/osmosis-1-genesis-0 8007:1000000 > /dev/null 2>&1 &
Log: Forwarded osmosis-1: local 8007 -> target (host) 1000000
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: stop()
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 1317:6767676 > /dev/null 2>&1 &
kubectl port-forward pods/osmosis-1-genesis-0 8007:1000000 > /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"
`;
33 changes: 18 additions & 15 deletions ci/utils/__tests__/__snapshots__/client.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,35 @@ helm repo add starship https://cosmology-tech.github.io/starship/
helm repo update
helm search repo starship/devnet --version v0.1.38
Call: install()
Installing the helm chart. This is going to take a while.....
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
Run "kubectl get pods" to check the status of the cluster
Log: Run "kubectl get pods" to check the status of the cluster
Call: startPortForward()
Attempting to stop any existing port-forwards...
Trying to stop all port-forward, if any....
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
Starting new port forwarding...
Log: Starting new port forwarding...
kubectl port-forward pods/osmosis-1-genesis-0 26657:26657 > /dev/null 2>&1 &
Forwarded osmosis-1: local 26657 -> target (host) 26657
Log: Forwarded osmosis-1: local 26657 -> target (host) 26657
kubectl port-forward pods/osmosis-1-genesis-0 1317:1317 > /dev/null 2>&1 &
Forwarded osmosis-1: local 1317 -> target (host) 1317
Log: Forwarded osmosis-1: local 1317 -> target (host) 1317
kubectl port-forward pods/osmosis-1-genesis-0 8007:8000 > /dev/null 2>&1 &
Forwarded osmosis-1: local 8007 -> target (host) 8000
Log: Forwarded osmosis-1: local 8007 -> target (host) 8000
kubectl port-forward pods/cosmos-2-genesis-0 26653:26657 > /dev/null 2>&1 &
Forwarded cosmos-2: local 26653 -> target (host) 26657
Log: Forwarded cosmos-2: local 26653 -> target (host) 26657
kubectl port-forward pods/cosmos-2-genesis-0 1313:1317 > /dev/null 2>&1 &
Forwarded cosmos-2: local 1313 -> target (host) 1317
Log: Forwarded cosmos-2: local 1313 -> target (host) 1317
kubectl port-forward pods/cosmos-2-genesis-0 8003:8000 > /dev/null 2>&1 &
Forwarded cosmos-2: local 8003 -> target (host) 8000
Log: Forwarded cosmos-2: local 8003 -> target (host) 8000
kubectl port-forward service/registry 8081:8080 > /dev/null 2>&1 &
Forwarded registry on port 8081 to target port 8080
Log: Forwarded registry on port 8081 to target port 8080
kubectl port-forward service/registry 9091:9090 > /dev/null 2>&1 &
Forwarded registry on port 9091 to target port 9090
Log: Forwarded registry on port 9091 to target port 9090
Call: stop()
pkill -f port-forward
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"
Expand All @@ -54,7 +56,8 @@ 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 &
pkill -f port-forward
ps -ef | grep -i 'kubectl port-forward' | grep -v 'grep' | awk '{print $2}'
sleep 2
helm delete osmojs
helm repo remove starship"
`;
35 changes: 35 additions & 0 deletions ci/utils/__tests__/client.ports.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { createClient, expectClient } from '../test-utils/client';
import { config } from '../test-utils/config';

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

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

client.setConfig(config.config);
client.setPodPorts({
chains: {
osmosis: {
exposer: 98988,
faucet: 1000000,
grpc: 909090,
rest: 6767676
}
}
});

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

client.startPortForward();

client.stop();

// remove helm chart
client.teardown();

expectClient(ctx, -1);
});
});
29 changes: 18 additions & 11 deletions ci/utils/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { readFileSync } from 'fs';
import { dependencies as defaultDependencies, Dependency } from "./deps";
import { readAndParsePackageJson } from './package';
import { Ports } from './config';
import deepmerge from 'deepmerge';

export interface StarshipContext {
helmName: string;
helmFile: string;
Expand All @@ -20,10 +22,10 @@ export interface StarshipContext {
};

export interface PodPorts {
registry: Ports,
explorer: Ports,
chains: {
defaultPorts: Ports,
registry?: Ports,
explorer?: Ports,
chains?: {
defaultPorts?: Ports,
[chainName: string]: Ports
}
}
Expand Down Expand Up @@ -122,7 +124,7 @@ export class StarshipClient implements StarshipClientI{
if (dep.name === 'docker' && platform === 'darwin') {
messages.push(chalk.gray("For macOS, you may also consider Docker for Mac: ") + chalk.white.bold(dep.macUrl));
} else if (dep.name === 'docker') {
messages.push(chalk.gray("For advanced Docker usage and installation on other platforms, see: ") + chalk.white.bold("https://docs.docker.com/engine/install/"));
messages.push(chalk.gray("For advanced Docker usage and installation on other platforms, see: ") + chalk.white.bold(dep.url));
}

messages.push('\n'); // Adding a newline for separation between dependencies
Expand Down Expand Up @@ -151,6 +153,10 @@ export class StarshipClient implements StarshipClientI{
this.config = config;
}

public setPodPorts(ports: PodPorts): void {
this.podPorts = deepmerge(defaultPorts, ports);
}

// TODO do we need this here?
public test(): void {
this.exec([
Expand All @@ -164,7 +170,7 @@ export class StarshipClient implements StarshipClientI{
}

public stop(): void {
this.stopForward();
this.stopPortForward();
this.deleteHelm();
}

Expand Down Expand Up @@ -283,7 +289,8 @@ export class StarshipClient implements StarshipClientI{
this.log("Starting new port forwarding...");

this.config.chains.forEach(chain => {
const chainPodPorts = this.podPorts.chains[chain.name] || this.podPorts.chains.defaultPorts;
// TODO Talk to Anmol about chain.name and chain.type, seems to be opposite of intuition using chainReg as concept
const chainPodPorts = this.podPorts.chains[chain.type] || this.podPorts.chains.defaultPorts;

if (chain.ports.rpc) this.forwardPort(chain, chain.ports.rpc, chainPodPorts.rpc);
if (chain.ports.rest) this.forwardPort(chain, chain.ports.rest, chainPodPorts.rest);
Expand All @@ -301,11 +308,11 @@ export class StarshipClient implements StarshipClientI{
}
}

public stopForward(): void {
this.exec(['pkill', '-f', 'port-forward']);
}

// TODO review with Anmol, which stopForward is better...
// public stopForward(): void {
// this.exec(['pkill', '-f', 'port-forward']);
// }

public stopPortForward(): void {
this.log(chalk.green("Trying to stop all port-forward, if any...."));
const result = this.exec([
Expand Down
7 changes: 6 additions & 1 deletion ci/utils/test-utils/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ export const createClient = () => {
// Overriding the log method
// @ts-ignore
proxiedClient.log = (cmd: string) => {
ctx.logs.push(strip(cmd));
const str = strip(cmd);
if (/\n/.test(str)) {
ctx.logs.push('Log⬇\n' + str + '\nEndLog⬆');
} else {
ctx.logs.push('Log: ' + str);
}
};

return {
Expand Down

0 comments on commit 5da3410

Please sign in to comment.