-
Notifications
You must be signed in to change notification settings - Fork 10
feat: add localnet scripts #620
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
Merged
Merged
Changes from all commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
aac0dfe
Copy from recall-deploy
sam701 a095609
Remove ipc ref
sam701 fcb6387
Fix ipc dir location
sam701 9efe1a8
Adjust nushell setup script
sam701 492150e
Add commit check
sam701 b2f9513
Remove onepass
sam701 a819b56
Add GH workflow
sam701 a59ae74
Remove unused workflow step
sam701 06f0a80
Fix branch name
sam701 29aa262
Disable QEMU
sam701 c0a23a8
Set PATH
sam701 45459ea
Fix image rebuild
sam701 2e1f0fc
Enable skipping of the commit match check
sam701 e337c57
Try to build without root
sam701 d33563c
Fix nu path
sam701 6b04461
Try to build an explicit image
sam701 e43f12e
Fix flags
sam701 51f623a
Fix permissions
sam701 7288485
Run anvil as local user
sam701 65c20b1
Fix reset flag
sam701 1e16c6b
Add group to docker run
sam701 247b14d
Build fendermint locally
sam701 bf2d96b
Fix local build
sam701 d445cc8
Tune multi-arch build
sam701 b93fe53
Fix script
sam701 2e1277c
Fix user ID in DIND image
sam701 c2707de
Inspect anvil state
sam701 7220908
Use a single anvil Dockerfile
sam701 328cbf8
Delete unused code
sam701 1d8a556
Fix anvil image
sam701 84f1365
Fix anvil termination
sam701 b723796
Debug 1
sam701 3c4f0b4
debug 2
sam701 8fe0b26
Enable full build
sam701 d5190ec
Test full build
sam701 deaa53d
Improve README
sam701 57618dc
Rename subcommand
sam701 d866181
Fix contract stack deployment
sam701 665065a
Fix build
sam701 7097dd2
Remove debug code
sam701 e556205
Improve docs
sam701 d16f87f
Enable running localnet after stop
sam701 70e0dd7
Make build-dind-image respect graceful-shutdown field
sam701 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 hidden or 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 hidden or 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,39 @@ | ||
| name: Build Localnet Image | ||
| on: | ||
| # Runs on non-main branches where the fendermint image must be built locally | ||
| pull_request: | ||
|
|
||
| # runs on main branch after the fendermint image has been published | ||
| workflow_call: | ||
|
|
||
| jobs: | ||
| build-localnet-image: | ||
| runs-on: self-hosted | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Login to Docker Hub | ||
| uses: docker/login-action@v3 | ||
| with: | ||
| username: ${{ secrets.DOCKER_HUB_USERNAME }} | ||
| password: ${{ secrets.DOCKER_HUB_PASSWORD }} | ||
|
|
||
| - name: Install Nushell | ||
| run: ./deployment/set-up-nu.sh | ||
|
|
||
| - name: Build Localnet Image | ||
| working-directory: ./deployment | ||
| run: | | ||
| set -eux | ||
|
|
||
| source ./.nu/activate.sh | ||
|
|
||
| if [ "${{ github.ref }}" == "refs/heads/main" ]; then | ||
| hash=$(git rev-parse --short=7 HEAD) | ||
| flags="--fendermint-image textile/fendermint:sha-$hash --push-multi-arch-tags textile/recall-localnet:sha-$hash,textile/recall-localnet:latest" | ||
| else | ||
| flags="--rebuild-fendermint-image --local-image-tag recall-localnet" | ||
| fi | ||
|
|
||
| ./localnet.nu build-docker-image $flags --node-count 2 |
This file contains hidden or 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 hidden or 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,3 @@ | ||
| /.nu/ | ||
| /localnet-data* | ||
| /testnet-data-* |
This file contains hidden or 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,12 @@ | ||
| # Localnet Scripts | ||
|
|
||
| ## Install nushell | ||
| If you do not have nushell installed, you can call `./set-up-nu.sh` that will download the required nushell version to `./.nu`. | ||
| You can add `nu` to your `PATH` with `source ./.nu/activate.sh` | ||
|
|
||
| ## Usage | ||
| You can run the localnet in two ways: | ||
| * `./localnet.nu run` - runs all localnet services on the local docker. See `./localnet.nu run -h` for details. | ||
| * `./localnet.nu run-dind` - downloads the latest `textile/recall-localnet` docker image and runs all services inside a single container. This is faster than the previous option. | ||
|
|
||
| See `./localnet.nu -h` for details. |
This file contains hidden or 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,13 @@ | ||
| FROM ubuntu:24.04 | ||
|
|
||
| RUN set -x; \ | ||
| arch=$(uname -m | sed -e s/aarch64/arm64/ -e s/x86_64/amd64/); \ | ||
| apt update && apt install -y curl && \ | ||
| curl -Lo /tmp/tt.tgz https://github.com/foundry-rs/foundry/releases/download/stable/foundry_stable_linux_${arch}.tar.gz && \ | ||
| tar xvf /tmp/tt.tgz -C /usr/bin && \ | ||
| rm /tmp/tt.tgz | ||
|
|
||
| RUN mkdir -p /workdir | ||
| WORKDIR /workdir | ||
|
|
||
| ENTRYPOINT ["anvil", "--host", "0.0.0.0", "--state", "/workdir/state"] |
This file contains hidden or 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,44 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| set -ex | ||
|
|
||
| # Setup signal handling for graceful shutdown | ||
| function cleanup() { | ||
| echo "Received termination signal. Shutting down containers..." | ||
| cd /workdir/localnet-data | ||
| for d in node-*; do | ||
| ( | ||
| cd $d/workdir | ||
| docker compose down | ||
| ) | ||
| done | ||
| docker stop localnet-anvil | ||
| docker network rm recall-localnet | ||
| pkill -TERM dockerd | ||
| exit 0 | ||
| } | ||
|
|
||
| # Register the cleanup function for these signals | ||
| trap cleanup SIGTERM SIGINT | ||
|
|
||
| nohup dockerd &> /dev/null & | ||
| DOCKERD_PID=$! | ||
| while ! docker info > /dev/null; do | ||
| sleep 1 | ||
| done | ||
|
|
||
| docker build -t anvil -f ./docker/anvil.Dockerfile ./docker | ||
| docker network create recall-localnet || true | ||
| docker run --rm --name localnet-anvil -u nobody -d --network recall-localnet -p 0.0.0.0:8545:8545 -v /workdir/localnet-data/anvil:/workdir anvil | ||
|
|
||
| cd localnet-data | ||
| for d in node-*; do | ||
| ( | ||
| cd $d/workdir | ||
| docker compose up -d | ||
| ) | ||
| done | ||
|
|
||
| # Keep container running until terminated | ||
| echo "All containers started. Waiting for termination signal..." | ||
| wait $DOCKERD_PID |
This file contains hidden or 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,17 @@ | ||
| FROM docker | ||
|
|
||
| RUN apk add bash | ||
|
|
||
| RUN mkdir -p /workdir | ||
| WORKDIR /workdir | ||
|
|
||
| COPY docker /workdir/docker | ||
| COPY localnet-data /workdir/localnet-data | ||
| RUN chown -R nobody:nobody /workdir | ||
| ENV RECALL_NODE_USER=nobody | ||
| RUN ls -la /workdir/localnet-data/anvil/ | ||
|
|
||
| # This is needed to expose DIND endpoints correctly from inside the localnet container | ||
| ENV LOCALNET_CLI_BIND_HOST=0.0.0.0 | ||
|
|
||
| ENTRYPOINT ["./docker/entrypoint-localnet.sh"] |
This file contains hidden or 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,34 @@ | ||
| # This image is used to set up a subnet. | ||
| # It contains the required ipc-cli and fendermint versions and the foundry tools. | ||
|
|
||
| ARG fendermint_image | ||
|
|
||
| FROM $fendermint_image | ||
|
|
||
| # Install foundry | ||
| RUN set -ex; \ | ||
| arch=$(uname -m | sed -e s/aarch64/arm64/ -e s/x86_64/amd64/); \ | ||
| curl -Lo /tmp/tt.tgz https://github.com/foundry-rs/foundry/releases/download/stable/foundry_stable_linux_${arch}.tar.gz && \ | ||
| tar xvf /tmp/tt.tgz -C /bin && \ | ||
| rm /tmp/tt.tgz | ||
|
|
||
|
|
||
| ARG NODE_VERSION=22.14.0 | ||
|
|
||
| # Install build tools | ||
| RUN set -ex; \ | ||
| apt update; \ | ||
| apt install -y git make python3 build-essential; \ | ||
| curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash; | ||
|
|
||
| RUN set -ex; \ | ||
| \. $HOME/.nvm/nvm.sh; \ | ||
| nvm install $NODE_VERSION; \ | ||
| nvm use v$NODE_VERSION; \ | ||
| nvm alias default v$NODE_VERSION; | ||
|
|
||
| ENV PATH="/fendermint/.nvm/versions/node/v${NODE_VERSION}/bin/:${PATH}" | ||
|
|
||
| RUN npm install -g pnpm | ||
|
|
||
| ENTRYPOINT ["/bin/bash"] |
This file contains hidden or 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,128 @@ | ||
|
|
||
| export def add-subnet-to-ipc-config [] { | ||
| open $env.state.config.ipc_config_file | | ||
| update subnets { $in | append { | ||
| id: $env.state.subnet_id | ||
| config: { | ||
| network_type: "fevm" | ||
| provider_http: $env.state.config.subnet.rpc_url | ||
| gateway_addr: "0x77aa40b105843728088c0132e43fc44348881da8" | ||
| registry_addr: "0x74539671a1d2f1c8f200826baba665179f53a1b7" | ||
| } | ||
| }} | | ||
| to toml | | ||
| save -f $env.state.config.ipc_config_file | ||
| } | ||
|
|
||
| export def write-subnet-config [dest: string, --bootstrap] { | ||
| mut cfg = { | ||
| address_network: "testnet" | ||
| parent_chain: { | ||
| chain_id: $env.state.config.parent_chain.chain_id | ||
| addresses: { | ||
| gateway: $env.state.gateway_address | ||
| registry: $env.state.registry_address | ||
| supply_source: $env.state.supply_source_address | ||
| subnet_contract: $env.state.subnet_eth_address | ||
| validator_gater: $env.state.validator_gater_address | ||
| validator_rewarder: $env.state.validator_rewarder_address | ||
| } | ||
| } | ||
| subnet: { | ||
| subnet_id: $env.state.subnet_id | ||
| chain_id: $env.state.config.subnet.chain_id | ||
| } | ||
| endpoints: { | ||
| cometbft_rpc_servers: $env.state.config.subnet.cometbft_rpc_servers | ||
| cometbft_persistent_peers: ($env.state.peers?.cometbft | default [] | uniq) | ||
| fendermint_seeds: ($env.state.peers?.fendermint | default [] | uniq) | ||
| } | ||
| } | ||
|
|
||
| if not $bootstrap { | ||
| $cfg = ($cfg | merge deep { | ||
| subnet: { | ||
| addresses: { | ||
| credit_manager: $env.state.creditManager_contract_address | ||
| bucket_manager: $env.state.bucketManager_contract_address | ||
| faucet_contract: $env.state.faucet_contract_address | ||
| blob_manager: $env.state.blobManager_contract_address | ||
| } | ||
| } | ||
| endpoints: { | ||
| evm_rpc_url: $env.state.config.subnet.rpc_url | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| $cfg | save -f $dest | ||
| } | ||
|
|
||
| export def build-setup-docker-image [] { | ||
| cd docker | ||
| docker build ...[ | ||
| --build-arg $"fendermint_image=($env.state.config.fendermint_image)" | ||
| -t $env.state.config.setup_image | ||
| -f subnet-setup.Dockerfile . | ||
| ] | ||
| } | ||
|
|
||
| export def build-fendermint-image [] { | ||
| if $env.state.config.fendermint_image == "fendermint" { | ||
| cd ../fendermint | ||
| make docker-build | ||
| } | ||
| } | ||
|
|
||
| export def set-fendermint-image [docker_compose_dir: string] { | ||
| cd $"($docker_compose_dir)/config" | ||
| let f = "node-default.toml" | ||
| open $f | update images.fendermint $env.state.config.fendermint_image | save -f $f | ||
| } | ||
|
|
||
| # Write network config suitable for recall CLI into workdir. | ||
| export def write-recall-cli-config [] { | ||
| let endpoints = match $env.state.config.network { | ||
| "localnet" => ({ | ||
| subnet_config: { | ||
| rpc_url: "http://localhost:26657" | ||
| object_api_url: "http://localhost:8001" | ||
| evm_rpc_url: "http://localhost:8645" | ||
| } | ||
| parent_network_config: { | ||
| evm_rpc_url: "http://localhost:8545" | ||
| } | ||
| }) | ||
| "testnet" => { | ||
| let base = $"($env.state.config.version).node-0.testnet.recall.network" | ||
| { | ||
| subnet_config: { | ||
| rpc_url: $"https://api.($base)" | ||
| object_api_url: $"https://objects.($base)" | ||
| evm_rpc_url: $"https://evm.($base)" | ||
| } | ||
| parent_network_config: { | ||
| evm_rpc_url: "https://api.calibration.node.glif.io" | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| let contracts = { | ||
| subnet_config: { | ||
| chain_id: $env.state.config.subnet.chain_id | ||
| subnet_id: $env.state.subnet_id | ||
| evm_gateway_address: "0x77aa40b105843728088c0132e43fc44348881da8" | ||
| evm_registry_address: "0x74539671a1d2f1c8f200826baba665179f53a1b7" | ||
| } | ||
| parent_network_config: { | ||
| evm_gateway_address: $env.state.gateway_address | ||
| evm_registry_address: $env.state.registry_address | ||
| evm_supply_source_address: $env.state.supply_source_address | ||
| } | ||
| } | ||
|
|
||
| let cfg = {} | insert $env.state.config.network ($endpoints | merge deep $contracts) | ||
|
|
||
| $cfg | save -f ($env.state.config.workdir | path join "networks.toml") | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
@sam701 we no longer need to deploy the wrapper / "manager" contracts. i just merged
ad096f2in the contracts repo, which removes them entirely.i created issues in https://github.com/recallnet/recall-docker-compose/issues/60 and https://github.com/recallnet/recall-deploy/issues/308 to account for this elsewhere. (i should have gave you a heads up wrt the IaC...sorry about that.)
Uh oh!
There was an error while loading. Please reload this page.
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.
or, i suppose we could keep your existing logic in this PR. then, create a follow up PR that updates
ipc'srecall-contractssubmodule toad096f2, and align that with the two issues mentioned in the comment above.if that makes sense to you, i created this ticket as a follow up: #621
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.
@dtbuchholz cool, thank you! The scripts in
recall-deploywill be removed once this PR is merged. I'll move your issue fromrecall-deployto this repo.