paritytech / zombienet

A cli tool to easily spawn ephemeral Polkadot/Substrate networks and perform tests against them.
https://paritytech.github.io/zombienet/
GNU General Public License v3.0
161 stars 91 forks source link

Zombienet within container #1200

Closed evilrobot-01 closed 5 months ago

evilrobot-01 commented 1 year ago

Issue Description

Attempting to bring up a network within a container using zombienet native provider, so that I can easily launch a PoC (including UI) via docker-compose with a single command.

Encountered an issue where polkadot unexpectedly fails on startup of the alice validator, but seems to work fine if I attempt manually within the container, remove database after failure and relaunch validator using zombienet generated command.

Note that I am on a mac M1, using --platform linux/amd64 and have 'Use Rosetta for x86/amd64 emulation on Apple Silicon' enabled within Docker Desktop.

Steps to reproduce the issue

Steps to reproduce the issue

  1. Build image using docker build --platform linux/amd64 -t zombienet . and the following Dockerfile and below simple config.toml:

    Dockerfile:

    FROM debian:stable as builder
    WORKDIR /build
    RUN apt update && apt install -y curl; \
      curl -sL -o zombienet https://github.com/paritytech/zombienet/releases/download/v1.3.63/zombienet-linux-x64 && chmod +x zombienet; \
      curl -sL -o polkadot https://github.com/paritytech/polkadot/releases/download/v0.9.42/polkadot && chmod +x polkadot;
    COPY ./config.toml .
    
    FROM debian:stable-slim
    COPY --from=builder /build/zombienet /build/polkadot /usr/bin/
    COPY --from=builder /build/config.toml /usr/share/config.toml
    CMD ["zombienet", "spawn", "/usr/share/config.toml", "-p", "native"]

    config.toml

    [relaychain]
    chain = "rococo-local"
    default_command = "polkadot"
    
    [[relaychain.nodes]]
    name = "alice"
    validator = true
    
    [[relaychain.nodes]]
    name = "bob"
    validator = true
  2. Run using docker run --platform linux/amd64 --rm zombienet

Describe the results you received

The following error is output:

  Error:           Error

  undefined

  Node'              │ /tmp/zombie-445003331d9876e792d0f7ba490c8041_-1-k818q3gHtLKv/logs
  s logs:[0[39m
  m             

The last successful log entry is 2023-07-24 10:23:54 ⛓ Native runtime: rococo-9420 (parity-rococo-v2.0-0.tx21.au0)

Further troubleshooting:

2023-07-24 10:32:41 ⛓  Native runtime: rococo-9420 (parity-rococo-v2.0-0.tx21.au0)    
2023-07-24 10:32:44 🔨 Initializing Genesis block/state (state: 0x2477…362b, header-hash: 0xbe93…bf53)    
2023-07-24 10:32:44 👴 Loading GRANDPA authority set from genesis on what appears to be first startup.    
2023-07-24 10:32:45 👶 Creating empty BABE epoch changes on what appears to be first startup.    
2023-07-24 10:32:45 🏷  Local node identity is: 12D3KooWQCkBm1BYtkHpocxCwMgR8yjitEeHGx8spzcDLGt2gkBm    
2023-07-24 10:32:45 💻 Operating system: linux    
2023-07-24 10:32:45 💻 CPU architecture: x86_64    
2023-07-24 10:32:45 💻 Target environment: gnu    
2023-07-24 10:32:45 💻 Memory: 32058MB    
2023-07-24 10:32:45 💻 Kernel: 5.15.49-linuxkit-pr    
2023-07-24 10:32:45 💻 Linux distribution: Debian GNU/Linux 12 (bookworm)    
2023-07-24 10:32:45 💻 Virtual machine: no    
2023-07-24 10:32:45 📦 Highest known block at #0    
2023-07-24 10:32:45 〽️ Prometheus exporter started at 0.0.0.0:40953    
2023-07-24 10:32:45 Running JSON-RPC HTTP server: addr=0.0.0.0:42423, allowed origins=["*"]    
2023-07-24 10:32:45 Running JSON-RPC WS server: addr=0.0.0.0:45503, allowed origins=["*"]    
2023-07-24 10:32:45 🏁 CPU score: 602.24 MiBs    
2023-07-24 10:32:45 🏁 Memory score: 15.80 GiBs    
2023-07-24 10:32:45 🏁 Disk score (seq. writes): 1.36 GiBs    
2023-07-24 10:32:45 🏁 Disk score (rand. writes): 443.49 MiBs    
2023-07-24 10:32:45 ⚠️  The hardware does not meet the minimal requirements for role 'Authority' find out more at:
https://wiki.polkadot.network/docs/maintain-guides-how-to-validate-polkadot#reference-hardware    
2023-07-24 10:32:45 Starting with an empty approval vote DB.
2023-07-24 10:32:45 👶 Starting BABE Authorship worker    
2023-07-24 10:32:50 💤 Idle (0 peers), best: #0 (0xbe93…bf53), finalized #0 (0xbe93…bf53), ⬇ 0 ⬆ 0    
2023-07-24 10:32:55 💤 Idle (0 peers), best: #0 (0xbe93…bf53), finalized #0 (0xbe93…bf53), ⬇ 0 ⬆ 0    

Describe the results you expected

The validator nodes to be launched as normal, with output logs as shown when run manually.

Zombienet version

v1.3.63

Provider

Native

Provider version

## For binaries
polkadot 0.9.42 downloaded from https://github.com/paritytech/polkadot/releases/download/v0.9.42/polkadot

Upstream Latest Release

Yes

Additional environment details

Mac M1: 13.4.1 Docker Desktop: 4.21.1

Additional information

I expect that this may be an unsupported case, but it would be useful to have this working so that one can easily bring up a full environment, with UI with something simple like docker-compose.

Screenshots

No response

dzmitry-lahoda commented 1 year ago

I run ZN in container well via nix. If you know nix you can find here https://github.com/ComposableFi/composable codespace and docker tools build, we publish devnet-picasso with zombienet on docker hub too.

Arm works sure (we have CI to check).

So we use nix built binaries.

rvalle commented 1 year ago

@evilrobot-01 I find your approach very good, simple and elegant.

I am going to try to use it for my project to. @dzmitry-lahoda I dont understand what nix adds to make this work, do you have any idea?

rvalle commented 1 year ago

@evilrobot-01 I can reproduce your problem.

While trying to debug it I accidentally made it work with the following Dockerfile:

FROM node:18

RUN curl -sL -o polkadot https://github.com/paritytech/polkadot/releases/download/v0.9.42/polkadot \
  && chmod +x polkadot \
  && mv polkadot /usr/local/bin;

RUN npm install -g @zombienet/cli

RUN useradd -m zombienet
USER zombienet

WORKDIR /home/zombienet
COPY ./config.toml .

CMD ["zombienet", "spawn", "/home/zombienet/config.toml", "-p", "native"]

I have no idea what the issue was, but it could be that the debian slim is too slim and something required by the stack is missing or that the pkg tool used to distribute zombienet as a binary is docker unfriendly (perhaps init related issue?).

I have no idea, however, using zombienet from NPM is good for me.

does it work for you also?

dzmitry-lahoda commented 1 year ago

we run devnet in many places

      buildDevnetImage = { name, devNet, container-tools }:
        pkgs.dockerTools.buildImage {
          inherit name;
          tag = "latest";
          copyToRoot = pkgs.buildEnv {
            name = "image-root";
            paths = [ devNet pkgs.glibc.bin ] ++ container-tools;
            pathsToLink = [ "/bin" ];
          };
          config = {
            Entrypoint =
              [ "${pkgs.lib.getBin devNet}/bin/${pkgs.lib.getName devNet}" ];
            Env = [ "USER=actions-runner" ];
          };

          runAsRoot = ''
            #!${pkgs.runtimeShell}
            ${pkgs.dockerTools.shadowSetup}
            # so we add 2 potential runners, CI and Codespace just for convenience
            mkdir --parents /usr/bin /home/actions-runner /tmp/composable-devnet /home/vscode
            chown 777 /tmp 
            chown 777 /tmp/composable-devnet
            chown 777 /home/actions-runner
            chown 777 /home/vscode
            groupadd --system actions-runner
            useradd --system --gid actions-runner --groups root actions-runner
          '';
        };

there is fix (so it is overshoots by making more changes because we run more than just zombie)

rvalle commented 1 year ago

@evilrobot-01 I ended adjusting a bit the Dockerfile,

ARG POLKADOT_VERSION=latest
ARG PARACHAIN_VERSION=latest

FROM parity/polkadot:$POLKADOT_VERSION as relaybuilder
FROM parity/polkadot-parachain:$PARACHAIN_VERSION as parabuilder
FROM node:18

ENV DEBIAN_FRONTEND=noninteractive

COPY --from=relaybuilder /usr/bin/polkadot /usr/local/bin
COPY --from=parabuilder /usr/local/bin/polkadot-parachain /usr/local/bin

RUN apt update \
    && apt install -y multitail \
    && rm -rf /var/lib/apt/lists/*

RUN npm install -g @zombienet/cli
COPY ./zombietail /usr/local/bin

RUN useradd -m zombienet
USER zombienet
WORKDIR /home/zombienet
RUN mkdir /home/zombienet/data

COPY ./config.toml .

VOLUME /home/zombienet/data

CMD ["zombienet", "spawn", "/home/zombienet/config.toml", "-p", "native", "-d","/home/zombienet/data", "-f"]

I will be using this as base for our DINFRA project zombienet

dzmitry-lahoda commented 1 year ago

may be closed?

pepoviola commented 5 months ago

Hi :wave, I want to close this one here and please check the new version of zombienet if you want to use podman/docker since we have a better support there.

Thx!