Skip to content

feat(spin-node): --detach for persistent local devnets + --dockerWithSudo for genesis - #181

Merged
ch4r10t33r merged 3 commits into
blockblaz:mainfrom
lambdaclass:feat/spin-node-detach
Jul 21, 2026
Merged

feat(spin-node): --detach for persistent local devnets + --dockerWithSudo for genesis#181
ch4r10t33r merged 3 commits into
blockblaz:mainfrom
lambdaclass:feat/spin-node-detach

Conversation

@MegaRedHand

Copy link
Copy Markdown
Contributor

Summary

Two quality-of-life additions for running local (docker-mode) devnets, aimed at long-lived devnets on remote hosts:

  • --detach (spin-node.sh, parse-env.sh): start a local devnet that keeps running after the script exits.
  • --dockerWithSudo (generate-genesis.sh, set-up.sh): let genesis generation work on hosts where the docker socket needs root.

--detach

By default the local docker path runs each node as docker run --rm ... & and installs a trap cleanup that kill -9s the containers when the script exits. That's correct for the interactive / timeout-wrapper workflow, but means you can't leave a devnet running on a server.

With --detach:

default --detach
run command docker run --rm (foreground &) docker run -d --restart unless-stopped
on script exit trap cleanup kills nodes nodes keep running
tail wait on pids prints a summary + stop hint, returns

Foreground behavior is unchanged when the flag is absent (Chesterton's fence: the trap/wait/--rm path is preserved for the timeout wrapper and interactive use).

Stopping a detached devnet uses the existing --stop path:

NETWORK_DIR=<dir> ./spin-node.sh --node all --stop

--dockerWithSudo

On hosts where the invoking user is not in the docker group, generate-genesis.sh's docker calls (hash-sig-cli keygen and eth-beacon-genesis) fail. --dockerWithSudo routes those two docker invocations through sudo docker. set-up.sh forwards the flag through when it drives the generator.

Both docker runs keep --user "$UID:$GID" so files written by a sudo'd container are still owned by the invoking user, not root.

Testing

  • Local mode with and without --detach (foreground path unchanged; detached path leaves containers up and --stop tears them down).
  • --dockerWithSudo genesis generation on a host where docker requires root.

Local docker mode ran each node in the foreground and tore the devnet down on exit (SIGINT/SIGTERM trap -> kill -9, plus --rm), so it never survived spin-node.sh returning. The opt-in --detach flag runs nodes with 'docker run -d --restart unless-stopped' and skips the wait/cleanup, leaving the devnet running once the script ends.

The existing --stop already tears these down (docker rm -f overrides the restart policy); the detach summary now points at it for discoverability.
…needs root

generate-genesis.sh called docker directly for hash-sig keygen and PK's genesis tool, so on hosts where the docker socket requires root (user not in the docker group) 'spin-node.sh --generateGenesis' failed at keygen with permission denied. Add a --dockerWithSudo flag that sudo-prefixes those docker calls (via $DOCKER_CMD), and forward it from set-up.sh when spin-node.sh receives --dockerWithSudo.
Copilot AI review requested due to automatic review settings July 21, 2026 16:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds two flags to improve running long-lived local (docker-mode) devnets: --detach to leave node containers running after spin-node.sh exits, and --dockerWithSudo to allow genesis generation on hosts where Docker requires root access.

Changes:

  • Add --detach support to run local docker nodes via docker run -d --restart unless-stopped and skip the trap/wait cleanup path.
  • Add --dockerWithSudo support for genesis generation by routing Docker invocations through sudo docker.
  • Forward --dockerWithSudo from set-up.sh into generate-genesis.sh, and surface detachNodes in env parsing/debug output.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
spin-node.sh Adds detached docker-run mode and alters end-of-script behavior to skip trap/wait/cleanup when detached.
set-up.sh Forwards --dockerWithSudo to the genesis generator.
parse-env.sh Parses --detach and prints detachNodes in the env summary output.
generate-genesis.sh Implements --dockerWithSudo via a DOCKER_CMD wrapper for docker pull/run operations.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread spin-node.sh
Comment thread spin-node.sh Outdated
…s sudo-aware

Address PR review:
- Fail fast if --detach is used with a binary node. --detach relies on
  docker's --restart unless-stopped to outlive the script; a binary has no
  supervisor, so it would run in the foreground (or die on exit). Guard it
  right after the client cmd is sourced (earliest point node_setup is known).
- Make the detached-mode hints honor --dockerWithSudo: prefix docker logs/rm
  with sudo and forward --dockerWithSudo to the suggested --stop command, so
  copy-pasted hints work on hosts where the docker socket needs root.
Copilot AI review requested due to automatic review settings July 21, 2026 16:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

Comment thread generate-genesis.sh
Comment thread generate-genesis.sh

@ch4r10t33r ch4r10t33r left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ch4r10t33r
ch4r10t33r merged commit 0c229a6 into blockblaz:main Jul 21, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants