-
Notifications
You must be signed in to change notification settings - Fork 96
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 localnet command #16
Merged
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
4ca6b76
chore(security): add workflow for leaked secrets monitoring
otani88 eeb45ec
Implement localnet subcommand
jpcenteno 68a67ad
Use import instead of require to get type definitons.
jpcenteno a4c8d71
Cleanup
jpcenteno 1a09eae
Point local-setup repo to our branch. Interface with docker-compose d…
jpcenteno cebc398
Merge pull request #2 from lambdaclass/feat-local-node
mationorato a8d342c
Add `localnet` subcommand to the README
jpcenteno 1acd846
Merge pull request #5 from lambdaclass/document-localnet-subcommand
mationorato 3973ee2
update docker compose from v1 to v2
mationorato d90245b
Update local-setup repo url to matter-labs main branch
mationorato 5940293
update REPO_URL and REPO_BRANCH in ts file
mationorato 4d44048
Merge branch 'upstream:main' into fix-merge-conflicts-with-matterlabs…
jpcenteno 55b145c
Update help
jpcenteno 860f415
Merge pull request #7 from lambdaclass/fix-merge-conflicts-with-matte…
jpcenteno edddec3
Update README.md
mationorato 40b8aa8
Document why repoDirectory is using XDG_STATE_HOME
jpcenteno c58b62b
Remove new bin/ files introduced from our fork
jpcenteno f2a9ecf
Fix pkg version
jpcenteno 724a224
Replace zksync 2.0 with Era for branding consistency
jpcenteno 4dd22b2
Merge branch 'address-matterlabs-review-comments'
jpcenteno fcd11b1
Merge branch 'main' into main
jpcenteno 21ea0bb
Update package lock
jpcenteno fbd18ed
Revert "Update package lock"
jpcenteno ec6a3e8
Fix messing newline at end of file
jpcenteno 04eaa91
Address CI messages
jpcenteno cb5a4ba
Export localnet help function
jpcenteno 38c14a3
Merge remote-tracking branch 'upstream/main'
jpcenteno 7ffb3ea
fix: refactor localnet module to follow new project structure
jpcenteno File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import { program } from "../setup"; | ||
import { execSync, ExecSyncOptions } from 'child_process'; | ||
import * as path from 'path'; | ||
import * as fs from 'fs'; | ||
import * as os from 'os'; | ||
|
||
const REPO_URL: string = "https://github.com/matter-labs/local-setup.git"; | ||
const REPO_BRANCH: string = "main" | ||
|
||
// --------------------------------------------------------------------------------------- | ||
// Utilities | ||
// --------------------------------------------------------------------------------------- | ||
|
||
function runSystemCommand(command: string, options?: ExecSyncOptions): string { | ||
const defaultOptions: ExecSyncOptions = { cwd: repoDirectory(), encoding: 'utf-8' }; | ||
const unifiedOptions: ExecSyncOptions = {...defaultOptions, ...options}; | ||
return execSync(command, unifiedOptions).toString(); | ||
} | ||
|
||
/** | ||
* Returns the path where the `zksync-cli/local-setup` repository, used | ||
* internally to manage localnet deployments, should be located. | ||
* | ||
* **Why follow the XDG Base Directory Specification?** | ||
* | ||
* This function follows the XDG Base Directory Specification | ||
* (https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html) | ||
* to determine the parent directory location: | ||
* | ||
* The XDG Base Directory Specification is widely accepted as a standard. | ||
* The decision to place the files under `$XDG_STATE_HOME` is based on considering the | ||
* presence or absence of this repository as part of the CLI tool's state. | ||
* | ||
* Alternative locations within the XDG Base Directory Specification were | ||
* considered and ruled out for the following reasons: | ||
* | ||
* - `$XDG_DATA_HOME` was not chosen because these files aren't user-specific | ||
* data files. | ||
* | ||
* - `$XDG_CACHE_HOME` was not chosen because these files aren't considered | ||
* non-essential cached data files. | ||
* | ||
* @returns {string} The path where the `zksync-cli/local-setup` repository should be | ||
* placed. | ||
*/ | ||
function repoDirectory(): string { | ||
// From the XDG Base Directory Specification: | ||
// `$XDG_STATE_HOME` defines the base directory relative to which user-specific state files should be stored. If `$XDG_STATE_HOME` is either not set or empty, a default equal to `$HOME/.local/state` should be used. | ||
const xdgStateHome = process.env.XDG_STATE_HOME || path.join(os.homedir(), ".local/state"); | ||
return path.join(xdgStateHome, "zksync-cli/local-setup"); | ||
} | ||
|
||
function isRepoCloned(): boolean { | ||
return fs.existsSync(repoDirectory()); | ||
} | ||
|
||
function cloneRepo() { | ||
const parentDirectory = path.join(repoDirectory(), ".."); | ||
runSystemCommand(`mkdir -p '${parentDirectory}'`, { cwd: "/" }); | ||
const options: ExecSyncOptions = { cwd: parentDirectory }; | ||
runSystemCommand(`git clone --branch '${REPO_BRANCH}' '${REPO_URL}'`, options); | ||
} | ||
|
||
function setUp() { | ||
cloneRepo(); | ||
} | ||
|
||
// --------------------------------------------------------------------------------------- | ||
// Command handling | ||
// --------------------------------------------------------------------------------------- | ||
|
||
const localnet = program | ||
.command("localnet") | ||
.description("Manage local L1 and L2 chains"); | ||
|
||
localnet | ||
.command("up") | ||
.description("Startup L1 and L2 localnets") | ||
.action(() => { | ||
if (! isRepoCloned()) { | ||
setUp(); | ||
} | ||
runSystemCommand("docker compose up --detach"); | ||
}); | ||
|
||
localnet | ||
.command("down") | ||
.description("clear L1 and L2 localnets") | ||
.action(() => { | ||
runSystemCommand("docker compose down --volumes"); | ||
}); | ||
|
||
localnet | ||
.command("start") | ||
.description("start L1 and L2 localnets") | ||
.action(() => { | ||
runSystemCommand("docker compose start"); | ||
}); | ||
|
||
localnet | ||
.command("stop") | ||
.description("stop L1 and L2 localnets") | ||
.action(() => { | ||
runSystemCommand("docker compose stop"); | ||
}); | ||
|
||
localnet | ||
.command("logs") | ||
.description("Display logs") | ||
.action(() => { | ||
const options: ExecSyncOptions = { stdio: 'inherit' }; | ||
runSystemCommand("docker-compose logs --follow", options); | ||
}); | ||
|
||
localnet | ||
.command("wallets") | ||
.description("Display rich wallet keys and addresses") | ||
.action(() => { | ||
const rawJSON = fs.readFileSync(path.join(repoDirectory(), "rich-wallets.json")).toString(); | ||
const wallets = JSON.parse(rawJSON); | ||
console.log(wallets); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤