Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Basic CI script #319

Merged
merged 10 commits into from
Aug 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/mergify.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
queue_rules:
- name: default
conditions:
- check-success=all
- check-success=[all, continuous-integration/gitlab-build, continuous-integration/gitlab-lint, continuous-integration/gitlab-package, continuous-integration/gitlab-publish-docker-pr, continuous-integration/gitlab-publish-test, continuous-integration/gitlab-test, continuous-integration/gitlab-zombienet-custom-scripts-assertion, continuous-integration/gitlab-zombienet-logs-assertion, continuous-integration/gitlab-zombienet-restart-pause-resume, continuous-integration/gitlab-zombienet-system-event-assertion]
- label=automerge
- base=main
- "#changes-requested-reviews-by=0"
Expand All @@ -10,7 +10,7 @@ queue_rules:
pull_request_rules:
- name: automatic merge when CI passes on main
conditions:
- check-success=all
- check-success=[all, continuous-integration/gitlab-build, continuous-integration/gitlab-lint, continuous-integration/gitlab-package, continuous-integration/gitlab-publish-docker-pr, continuous-integration/gitlab-publish-test, continuous-integration/gitlab-test, continuous-integration/gitlab-zombienet-custom-scripts-assertion, continuous-integration/gitlab-zombienet-logs-assertion, continuous-integration/gitlab-zombienet-restart-pause-resume, continuous-integration/gitlab-zombienet-system-event-assertion]
- label=automerge
- base=main
- "#changes-requested-reviews-by=0"
Expand Down
33 changes: 33 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: ZombieNet Basic CI

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [14.x, 16.x, 17.x, 18.x]

steps:
- uses: actions/checkout@v1
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm run build
- run: npm run lint

all:
# This dummy job depends on all the mandatory checks. It succeeds if and only if all CI checks
# are successful.
needs: [build]
runs-on: ubuntu-latest
steps:
- run: echo Success
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"scripts": {
"clean": "rm -rf ./dist/*",
"build": "tsc",
"lint": "npx prettier --write ./src",
"lint": "npx prettier --check ./src",
"lint:write": "npx prettier --write ./src",
"package": "pkg . --out-path ./bins"
},
"dependencies": {
Expand Down
26 changes: 18 additions & 8 deletions src/cmdGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ export async function genCumulusCollatorCmd(
(nodeSetup.wsPort ? nodeSetup.wsPort : RPC_WS_PORT).toString(),
"--prometheus-external",
"--prometheus-port",
(nodeSetup.prometheusPort ? nodeSetup.prometheusPort : PROMETHEUS_PORT).toString(),
(nodeSetup.prometheusPort
? nodeSetup.prometheusPort
: PROMETHEUS_PORT
).toString(),
"--rpc-cors all",
"--unsafe-rpc-external",
"--rpc-methods unsafe",
Expand Down Expand Up @@ -130,7 +133,16 @@ export async function genCumulusCollatorCmd(
// port passed as argument, we need to ensure is not a default one because it will be
// use by the parachain part.
const selectedPort = parseInt(argsFullNode[index + 1], 10);
if ([P2P_PORT, RPC_HTTP_PORT, RPC_WS_PORT, nodeSetup.p2pPort, nodeSetup.rpcPort, nodeSetup.wsPort].includes(selectedPort)) {
if (
[
P2P_PORT,
RPC_HTTP_PORT,
RPC_WS_PORT,
nodeSetup.p2pPort,
nodeSetup.rpcPort,
nodeSetup.wsPort,
].includes(selectedPort)
) {
console.log(
decorators.yellow(
`WARN: default port configured, changing to use a random free port`,
Expand Down Expand Up @@ -252,17 +264,15 @@ export async function genCmd(
if (bootnodes && bootnodes.length)
args.push("--bootnodes", bootnodes.join(" "));



// port flags logic
const portFlags = {
"--prometheus-port": nodeSetup.prometheusPort,
"--rpc-port": nodeSetup.rpcPort,
"--ws-port": nodeSetup.wsPort
}
"--ws-port": nodeSetup.wsPort,
};

for( const [k,v] of Object.entries(portFlags)) {
args.push(...[k,v.toString()]);
for (const [k, v] of Object.entries(portFlags)) {
args.push(...[k, v.toString()]);
}
args.push(...["--listen-addr", `/ip4/0.0.0.0/tcp/${nodeSetup.p2pPort}/ws`]);

Expand Down
76 changes: 45 additions & 31 deletions src/configGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,14 +331,18 @@ export async function generateNetworkSpec(
}

// TODO: move this fn to other module.
export async function generateBootnodeSpec(config: ComputedNetwork): Promise<Node> {
const ports = config.settings.provider !== "native" ? DEFAULT_PORTS :
{
p2pPort: await getRandomPort(),
wsPort: await getRandomPort(),
rpcPort: await getRandomPort(),
prometheusPort: await getRandomPort()
};
export async function generateBootnodeSpec(
config: ComputedNetwork,
): Promise<Node> {
const ports =
config.settings.provider !== "native"
? DEFAULT_PORTS
: {
p2pPort: await getRandomPort(),
wsPort: await getRandomPort(),
rpcPort: await getRandomPort(),
prometheusPort: await getRandomPort(),
};

const nodeSetup: Node = {
name: "bootnode",
Expand All @@ -358,8 +362,10 @@ export async function generateBootnodeSpec(config: ComputedNetwork): Promise<Nod
telemetryUrl: "",
overrides: [],
zombieRole: "bootnode",
imagePullPolicy: config.settings.image_pull_policy? config.settings.image_pull_policy : "Always",
...ports
imagePullPolicy: config.settings.image_pull_policy
? config.settings.image_pull_policy
: "Always",
...ports,
};

return nodeSetup;
Expand Down Expand Up @@ -429,13 +435,15 @@ async function getCollatorNodeFromConfig(
const collatorName = getUniqueName(collatorConfig.name || "collator");
const accountsForNode = await generateKeyForNode(collatorName);

const ports = networkSpec.settings.provider !== "native" ? DEFAULT_PORTS :
{
p2pPort: await getRandomPort(),
wsPort: await getRandomPort(),
rpcPort: await getRandomPort(),
prometheusPort: await getRandomPort()
};
const ports =
networkSpec.settings.provider !== "native"
? DEFAULT_PORTS
: {
p2pPort: await getRandomPort(),
wsPort: await getRandomPort(),
rpcPort: await getRandomPort(),
prometheusPort: await getRandomPort(),
};

const node: Node = {
name: collatorName,
Expand All @@ -453,8 +461,10 @@ async function getCollatorNodeFromConfig(
overrides: [],
zombieRole: cumulusBased ? "cumulus-collator" : "collator",
parachainId: para_id,
imagePullPolicy: networkSpec.settings.image_pull_policy? networkSpec.settings.image_pull_policy : "Always",
...ports
imagePullPolicy: networkSpec.settings.image_pull_policy
? networkSpec.settings.image_pull_policy
: "Always",
...ports,
};

return node;
Expand Down Expand Up @@ -506,13 +516,15 @@ async function getNodeFromConfig(

const nodeName = getUniqueName(node.name);
const accountsForNode = await generateKeyForNode(nodeName);
const ports = networkSpec.settings.provider !== "native" ? DEFAULT_PORTS :
{
p2pPort: await getRandomPort(),
wsPort: await getRandomPort(),
rpcPort: await getRandomPort(),
prometheusPort: await getRandomPort()
};
const ports =
networkSpec.settings.provider !== "native"
? DEFAULT_PORTS
: {
p2pPort: await getRandomPort(),
wsPort: await getRandomPort(),
rpcPort: await getRandomPort(),
prometheusPort: await getRandomPort(),
};

// build node Setup
const nodeSetup: Node = {
Expand All @@ -536,20 +548,22 @@ async function getNodeFromConfig(
addToBootnodes: node.add_to_bootnodes ? true : false,
resources: node.resources || networkSpec.relaychain.defaultResources,
zombieRole: "node",
imagePullPolicy: networkSpec.settings.image_pull_policy? networkSpec.settings.image_pull_policy : "Always",
...ports
imagePullPolicy: networkSpec.settings.image_pull_policy
? networkSpec.settings.image_pull_policy
: "Always",
...ports,
};

if(group) nodeSetup.group = group;
if (group) nodeSetup.group = group;
return nodeSetup;
}

function sanitizeArgs(args: string[]): string[] {
// Do NOT filter any argument to the internal full-node of the collator

let removeNext = false;
const filteredArgs = args.slice(0, args.indexOf("--")).filter(arg=> {
if(removeNext) {
const filteredArgs = args.slice(0, args.indexOf("--")).filter((arg) => {
if (removeNext) {
removeNext = false;
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const DEFAULT_PORTS = {
p2pPort: P2P_PORT,
wsPort: RPC_WS_PORT,
rpcPort: RPC_HTTP_PORT,
prometheusPort: PROMETHEUS_PORT
prometheusPort: PROMETHEUS_PORT,
};

export const DEFAULT_GLOBAL_TIMEOUT = 1200; // 20 mins
Expand Down
10 changes: 8 additions & 2 deletions src/paras.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ import { getClient } from "./providers/client";
import { Providers } from "./providers";
import { fileMap, Node, Parachain } from "./types";
import fs from "fs";
import { addAuraAuthority, addAuthority, changeGenesisConfig, clearAuthorities, specHaveSessionsKeys } from "./chain-spec";
import {
addAuraAuthority,
addAuthority,
changeGenesisConfig,
clearAuthorities,
specHaveSessionsKeys,
} from "./chain-spec";
import { getRandomPort } from "./utils/net-utils";

const debug = require("debug")("zombie::paras");
Expand Down Expand Up @@ -197,7 +203,7 @@ export async function generateParachainFiles(
p2pPort: await getRandomPort(),
wsPort: await getRandomPort(),
rpcPort: await getRandomPort(),
prometheusPort: await getRandomPort()
prometheusPort: await getRandomPort(),
};

const provider = Providers.get(client.providerName);
Expand Down
6 changes: 3 additions & 3 deletions src/providers/k8s/dynResourceDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
WAIT_UNTIL_SCRIPT_SUFIX,
RPC_HTTP_PORT,
RPC_WS_PORT,
P2P_PORT
P2P_PORT,
} from "../../constants";
import { getUniqueName } from "../../configGenerator";
import { Node } from "../../types";
Expand Down Expand Up @@ -138,7 +138,7 @@ async function make_main_container(
];

let computedCommand;
if( nodeSetup.zombieRole === "cumulus-collator" ) {
if (nodeSetup.zombieRole === "cumulus-collator") {
computedCommand = await genCumulusCollatorCmd(nodeSetup);
} else {
computedCommand = await genCmd(nodeSetup);
Expand Down Expand Up @@ -236,7 +236,7 @@ export async function createTempNodeDef(
p2pPort: await getRandomPort(),
wsPort: await getRandomPort(),
rpcPort: await getRandomPort(),
prometheusPort: await getRandomPort()
prometheusPort: await getRandomPort(),
};

return node;
Expand Down
24 changes: 17 additions & 7 deletions src/providers/native/dynResourceDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export async function genBootnodeDef(
): Promise<any> {
const client = getClient();
const name = nodeSetup.name;
const {rpcPort, wsPort, prometheusPort, p2pPort} = nodeSetup;
const { rpcPort, wsPort, prometheusPort, p2pPort } = nodeSetup;
const ports = await getPorts(rpcPort, wsPort, prometheusPort, p2pPort);

const cfgPath = `${client.tmpDir}/${name}/cfg`;
Expand Down Expand Up @@ -57,7 +57,7 @@ export async function genNodeDef(
): Promise<any> {
const client = getClient();
const name = nodeSetup.name;
const {rpcPort, wsPort, prometheusPort, p2pPort} = nodeSetup;
const { rpcPort, wsPort, prometheusPort, p2pPort } = nodeSetup;
const ports = await getPorts(rpcPort, wsPort, prometheusPort, p2pPort);
const cfgPath = `${client.tmpDir}/${name}/cfg`;
await fs.mkdir(cfgPath, { recursive: true });
Expand All @@ -66,8 +66,13 @@ export async function genNodeDef(
await fs.mkdir(dataPath, { recursive: true });

let computedCommand;
if( nodeSetup.zombieRole === "cumulus-collator" ) {
computedCommand = await genCumulusCollatorCmd(nodeSetup, cfgPath, dataPath, false);
if (nodeSetup.zombieRole === "cumulus-collator") {
computedCommand = await genCumulusCollatorCmd(
nodeSetup,
cfgPath,
dataPath,
false,
);
} else {
computedCommand = await genCmd(nodeSetup, cfgPath, dataPath, false);
}
Expand Down Expand Up @@ -97,7 +102,12 @@ export async function genNodeDef(
};
}

async function getPorts(rpc?: number, ws?:number, prometheus?:number, p2p?:number) {
async function getPorts(
rpc?: number,
ws?: number,
prometheus?: number,
p2p?: number,
) {
const ports = [
{
containerPort: PROMETHEUS_PORT,
Expand All @@ -121,7 +131,7 @@ async function getPorts(rpc?: number, ws?:number, prometheus?:number, p2p?:numbe
containerPort: P2P_PORT,
name: "p2p",
flag: "--port",
hostPort: p2p || await getRandomPort(),
hostPort: p2p || (await getRandomPort()),
},
];

Expand Down Expand Up @@ -162,7 +172,7 @@ export async function createTempNodeDef(
p2pPort: await getRandomPort(),
wsPort: await getRandomPort(),
rpcPort: await getRandomPort(),
prometheusPort: await getRandomPort()
prometheusPort: await getRandomPort(),
};

return node;
Expand Down
4 changes: 2 additions & 2 deletions src/providers/podman/dynResourceDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ async function make_main_container(
];

let computedCommand;
if( nodeSetup.zombieRole === "cumulus-collator") {
if (nodeSetup.zombieRole === "cumulus-collator") {
computedCommand = await genCumulusCollatorCmd(nodeSetup);
} else {
computedCommand = await genCmd(nodeSetup);
Expand Down Expand Up @@ -482,7 +482,7 @@ export async function createTempNodeDef(
p2pPort: await getRandomPort(),
wsPort: await getRandomPort(),
rpcPort: await getRandomPort(),
prometheusPort: await getRandomPort()
prometheusPort: await getRandomPort(),
};

return node;
Expand Down
2 changes: 1 addition & 1 deletion src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export interface Node {
rpcPort: number;
prometheusPort: number;
p2pPort: number;
imagePullPolicy?: "IfNotPresent" | "Never" | "Always"
imagePullPolicy?: "IfNotPresent" | "Never" | "Always";
}

export interface Collator {
Expand Down