Skip to content

Commit

Permalink
Merge branch 'feat-all-in-one-setup-scaffold' of https://github.com/m…
Browse files Browse the repository at this point in the history
  • Loading branch information
JackHamer09 committed Sep 19, 2023
2 parents e067af7 + a6544f0 commit 3c83fc7
Show file tree
Hide file tree
Showing 14 changed files with 135 additions and 235 deletions.
17 changes: 7 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ This CLI tool simplifies the process of developing applications and interacting

## 🛠 Prerequisites

- Node.js v18.x
- NPM / Yarn
- [Node.js v18.x](https://nodejs.org/en)
- [Docker](https://www.docker.com/get-started/) (for `zksync-cli local` commands)

## 📥 Installation

Expand All @@ -37,14 +37,11 @@ You can install this program globally with `npm i -g zksync-cli` or run the comm

- `zksync-cli --version`: Returns the current version

- `zksync-cli localnet`: Manages a local zkSync Era and Ethereum L1 testnet (it requires docker running on your system). It supports a set of sub-subcommands:
- `zksync-cli localnet up`: Bootstrap L1 and L2 localnets.
- `zksync-cli localnet down`: clear L1 and L2 localnets.
- `zksync-cli localnet start`: start L1 and L2 localnets.
- `zksync-cli localnet stop`: stop L1 and L2 localnets.
- `zksync-cli localnet logs`: Display logs.
- `zksync-cli localnet help`: Display this message and quit.
- `zksync-cli localnet wallets`: Display seeded wallet keys.
- `zksync-cli local` - All-in-one tool for local zkSync development. It supports a set of sub-subcommands:
- `zksync-cli local start` - start local setup (will ask to configure if starting for the first time)
- `zksync-cli local stop` - stop currently running modules
- `zksync-cli local clean` - clean data for all modules
- `zksync-cli local config` - setup new config for local setup (select modules)

### 🔗 Supported chains

Expand Down
45 changes: 19 additions & 26 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"scripts": {
"build": "tsc -p tsconfig.build.json && copyfiles -u 4 \"src/commands/local/modules/**/!(*.ts)\" bin/commands/local/modules/",
"dev": "NODE_ENV=development ts-node --transpile-only src/index.ts",
"dev": "cross-env NODE_ENV=development ts-node --transpile-only src/index.ts",
"test": "jest",
"typecheck": "tsc -p . --noEmit",
"lint": "eslint . --ext ./src/* --fix --ignore-path .gitignore --no-error-on-unmatched-pattern --max-warnings=0",
Expand All @@ -31,9 +31,9 @@
"axios": "^1.3.4",
"chalk": "4.1.2",
"commander": "^11.0.0",
"cross-env": "^7.0.3",
"dotenv": "^16.3.1",
"ethers": "5.7.2",
"figlet": "^1.5.2",
"inquirer": "^8.1.4",
"node-machine-id": "^1.1.12",
"winston": "^3.10.0",
Expand All @@ -50,7 +50,6 @@
"@semantic-release/npm": "^8.0.3",
"@semantic-release/release-notes-generator": "^10.0.3",
"@types/dockerode": "^3.3.19",
"@types/figlet": "^1.5.6",
"@types/inquirer": "^8.0.2",
"@types/jest": "^29.5.4",
"@types/node": "^18.17.12",
Expand Down
22 changes: 11 additions & 11 deletions src/commands/local/modules/dockerized-node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,25 @@ export default class SetupModule extends Module {
justInstalled = false;

git = "https://github.com/matter-labs/local-setup.git";
composeFile = path.join(this.folder, "docker-compose.yml");
composeFile = path.join(this.dataDirPath, "docker-compose.yml");

async isInstalled() {
if (!fileOrDirExists(this.folder)) return false;
return (await composeStatus(this.composeFile, this.folder)).length ? true : false;
if (!fileOrDirExists(this.dataDirPath)) return false;
return (await composeStatus(this.composeFile, this.dataDirPath)).length ? true : false;
}

async install() {
await cloneRepo(this.git, this.folder);
await composeCreate(this.composeFile, this.folder);
await cloneRepo(this.git, this.dataDirPath);
await composeCreate(this.composeFile, this.dataDirPath);
this.justInstalled = true;
}

async isRunning() {
return (await composeStatus(this.composeFile, this.folder)).some(({ isRunning }) => isRunning);
return (await composeStatus(this.composeFile, this.dataDirPath)).some(({ isRunning }) => isRunning);
}

async start() {
await composeUp(this.composeFile, this.folder);
await composeUp(this.composeFile, this.dataDirPath);
}

async onStartCompleted() {
Expand All @@ -60,21 +60,21 @@ export default class SetupModule extends Module {
- Ethereum Node (L1):
- Chain ID: 9
- RPC URL: http://localhost:8545
- Rich accounts: ${path.join(this.folder, "rich-wallets.json")}`);
- Rich accounts: ${path.join(this.dataDirPath, "rich-wallets.json")}`);
if (this.justInstalled) {
Logger.warn(" - First start may take a while until zkSync node is actually running, please be patient...");
}
}

async stop() {
await composeStop(this.composeFile, this.folder);
await composeStop(this.composeFile, this.dataDirPath);
}

async clean() {
await composeDown(this.composeFile, this.folder);
await composeDown(this.composeFile, this.dataDirPath);
}

async restart() {
await composeRestart(this.composeFile, this.folder);
await composeRestart(this.composeFile, this.dataDirPath);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@ services:
FROM ubuntu:latest
WORKDIR /app
RUN apt-get update \
&& apt-get install -y curl \
&& apt-get install -y curl jq \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
RUN curl -o era_test_node.tar.gz -L https://github.com/matter-labs/era-test-node/releases/download/v0.1.0-alpha.3/era_test_node-v0.1.0-alpha.3-x86_64-unknown-linux-gnu.tar.gz
# Download latest linux binary from github
RUN curl -s https://api.github.com/repos/matter-labs/era-test-node/releases | \
jq -r '.[] | select(any(.assets[]; .name | contains("x86_64-unknown-linux-gnu"))) | .assets[] | select(.name | contains("x86_64-unknown-linux-gnu")) | .browser_download_url' | \
head -n 1 | xargs -I {} curl -L -o era_test_node.tar.gz {}
# Download and setup the binary
RUN tar xz -f era_test_node.tar.gz -C /usr/local/bin/
RUN chmod +x /usr/local/bin/era_test_node
EXPOSE 8011
Expand Down
14 changes: 7 additions & 7 deletions src/commands/local/modules/in-memory-node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ export default class SetupModule extends Module {
composeFile = path.join(__dirname, "docker-compose-binary.yml");

async isInstalled() {
return (await composeStatus(this.composeFile, path.dirname(this.composeFile))).length ? true : false;
return (await composeStatus(this.composeFile)).length ? true : false;
}

async install() {
await composeCreate(this.composeFile, this.folder);
await composeCreate(this.composeFile);
}

async isRunning() {
return (await composeStatus(this.composeFile, this.folder)).some(({ isRunning }) => isRunning);
return (await composeStatus(this.composeFile)).some(({ isRunning }) => isRunning);
}

async start() {
await composeUp(this.composeFile, this.folder);
await composeUp(this.composeFile);
}

async onStartCompleted() {
Expand All @@ -56,14 +56,14 @@ export default class SetupModule extends Module {
}

async stop() {
await composeStop(this.composeFile, this.folder);
await composeStop(this.composeFile);
}

async clean() {
await composeDown(this.composeFile, this.folder);
await composeDown(this.composeFile);
}

async restart() {
await composeRestart(this.composeFile, this.folder);
await composeRestart(this.composeFile);
}
}
4 changes: 2 additions & 2 deletions src/commands/local/modules/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export abstract class Module {
key: DefaultModuleFields["key"];
tags: DefaultModuleFields["tags"];

get folder() {
return getLocalPath(this.key);
get dataDirPath() {
return getLocalPath("modules", this.key);
}

abstract isInstalled(): Promise<boolean>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: '3.2'

services:
portal-dockerized-node:
portal-in-memory-node:
environment:
- NODE_TYPE=memory
build:
Expand Down
20 changes: 8 additions & 12 deletions src/commands/local/modules/portal/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default class SetupModule extends Module {
"in-memory-node": path.join(__dirname, "docker-compose-in-memory-node.yml"),
};
get composeFile() {
return this.config.modules.find((module) => module === "in-memory-node")
return this.config.modules.some((module) => module === "in-memory-node")
? this.composeFiles["in-memory-node"]
: this.composeFiles["dockerized-node"];
}
Expand All @@ -40,7 +40,7 @@ export default class SetupModule extends Module {
const composeFileKey = Object.entries(this.composeFiles).find(([, composeFilePath]) => {
return composeFilePath === this.composeFile;
})![0];
const containers = await composeStatus(this.composeFile, this.folder);
const containers = await composeStatus(this.composeFile);
for (const { name, isRunning } of containers) {
if (name.includes(composeFileKey)) {
return isRunning;
Expand All @@ -54,7 +54,7 @@ export default class SetupModule extends Module {
}

async install() {
await composeCreate(this.composeFile, this.folder);
await composeCreate(this.composeFile);
}

async isRunning() {
Expand All @@ -64,10 +64,10 @@ export default class SetupModule extends Module {
async start() {
for (const composeFilePath of Object.values(this.composeFiles)) {
if (composeFilePath !== this.composeFile) {
await composeStop(composeFilePath, this.folder);
await composeStop(composeFilePath);
}
}
await composeUp(this.composeFile, this.folder);
await composeUp(this.composeFile);
}

async onStartCompleted() {
Expand All @@ -80,18 +80,14 @@ export default class SetupModule extends Module {
}

async stop() {
await Promise.all(
Object.values(this.composeFiles).map((composeFilePath) => composeStop(composeFilePath, this.folder))
);
await Promise.all(Object.values(this.composeFiles).map((composeFilePath) => composeStop(composeFilePath)));
}

async clean() {
await Promise.all(
Object.values(this.composeFiles).map((composeFilePath) => composeDown(composeFilePath, this.folder))
);
await Promise.all(Object.values(this.composeFiles).map((composeFilePath) => composeDown(composeFilePath)));
}

async restart() {
await composeRestart(this.composeFile, this.folder);
await composeRestart(this.composeFile);
}
}
4 changes: 2 additions & 2 deletions src/commands/local/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const installModules = async (modules: Module[]) => {
Logger.debug(`Module "${module.name}" is already installed. Skipping...`);
continue;
}
Logger.info(`Installing "${module.name}"...`);
Logger.info(`\nInstalling "${module.name}"...`);
await module.install();
}
};
Expand All @@ -24,7 +24,7 @@ const startModules = async (modules: Module[]) => {
};

const triggerOnCompleted = async (modules: Module[]) => {
Logger.info("\nLocal environment is ready!");
Logger.info("\n");
for (const module of modules) {
await module.onStartCompleted();
}
Expand Down
Loading

0 comments on commit 3c83fc7

Please sign in to comment.