From 3197e932424cb391a3d9906211bb43103bf7de7f Mon Sep 17 00:00:00 2001 From: Victor Yves Crispim Date: Wed, 1 Nov 2023 15:21:21 -0300 Subject: [PATCH 1/2] feat: add files to support manual tests As cartesi-rollups-node gets built and new services are added, it becomes increasingly cumbersome to set up an environment to test it. The added docker-compose file is meant to simplify the process of manual testing for the time being --- .gitignore | 1 + build/docker-compose.yml | 177 +++++++++++++++++++++++++++++++++++++++ build/machine.Dockerfile | 30 +++++++ 3 files changed, 208 insertions(+) create mode 100644 build/docker-compose.yml create mode 100644 build/machine.Dockerfile diff --git a/.gitignore b/.gitignore index 613c6cdd5..f22a3ae7c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .vscode .env .DS_Store +build/deployments **/.idea/ diff --git a/build/docker-compose.yml b/build/docker-compose.yml new file mode 100644 index 000000000..a8ca443e5 --- /dev/null +++ b/build/docker-compose.yml @@ -0,0 +1,177 @@ +version: "3.9" + +name: rollups-node +services: + rollups-node: + build: + context: .. + dockerfile: build/Dockerfile + tags: + - "cartesi/rollups-node:devel" + entrypoint: ["cartesi-rollups-node", "validator"] + ports: + - "4000:4000" + depends_on: + hardhat: + condition: service_healthy + deployer: + condition: service_completed_successfully + hardhat_set_interval: + condition: service_completed_successfully + server_manager: + condition: service_healthy + database: + condition: service_healthy + redis: + condition: service_healthy + environment: + RUST_LOG: info + CARTESI_LOG_LEVEL: info + POSTGRES_ENDPOINT: postgres://postgres:password@database:5432/postgres + + #GraphQL Server + GRAPHQL_HEALTHCHECK_PORT: 8082 + GRAPHQL_HOST: "0.0.0.0" + GRAPHQL_PORT: "4000" + + #Indexer + INDEXER_HEALTHCHECK_PORT: 8083 + DAPP_CONTRACT_ADDRESS_FILE: /deployments/localhost/dapp.json + REDIS_ENDPOINT: redis://redis:6379 + CHAIN_ID: 31337 + + volumes: + - machine:/var/opt/cartesi/machine-snapshots + - blockchain-data:/opt/cartesi/share/deployments:ro + - ./deployments:/deployments:ro + + hardhat: + image: cartesi/rollups-hardhat:1.0.0 + command: + [ + "node", + "--network", + "hardhat", + "--export", + "/opt/cartesi/share/deployments/localhost.json", + ] + init: true + ports: + - "8545:8545" + healthcheck: + test: + ["CMD", "test", "-f", "/opt/cartesi/share/deployments/localhost.json"] + interval: 30s + timeout: 30s + retries: 5 + volumes: + - blockchain-data:/opt/cartesi/share/deployments + - ./deployments:/app/rollups/deployments + + deployer: + image: cartesi/rollups-cli:1.0.0 + restart: on-failure + depends_on: + hardhat: + condition: service_healthy + server_manager: + condition: service_healthy + command: + [ + "create", + "--rpc", + "http://hardhat:8545", + "--deploymentFile", + "/opt/cartesi/share/deployments/localhost.json", + "--mnemonic", + "test test test test test test test test test test test junk", + "--templateHashFile", + "/var/opt/cartesi/machine-snapshots/0_0/hash", + "--outputFile", + "/deployments/localhost/dapp.json", + ] + volumes: + - blockchain-data:/opt/cartesi/share/deployments:ro + - machine:/var/opt/cartesi/machine-snapshots:ro + - ./deployments:/deployments + + hardhat_stop_automine: + image: curlimages/curl:7.84.0 + restart: on-failure + depends_on: + hardhat: + condition: service_healthy + deployer: + condition: service_completed_successfully + command: + [ + "--data", + '{"id":1337,"jsonrpc":"2.0","method":"evm_setAutomine","params":[false]}', + "http://hardhat:8545", + ] + + hardhat_set_interval: + image: curlimages/curl:7.84.0 + restart: on-failure + depends_on: + hardhat: + condition: service_healthy + hardhat_stop_automine: + condition: service_completed_successfully + command: + [ + "--data", + '{"id":1337,"jsonrpc":"2.0","method":"evm_setIntervalMining","params":[5000]}', + "http://hardhat:8545", + ] + + server_manager: + build: + context: .. + dockerfile: build/machine.Dockerfile + restart: always + ports: + - "5001:5001" + healthcheck: + test: ["CMD-SHELL", 'bash -c ''echo "" > /dev/tcp/127.0.0.1/5001;'''] + interval: 10s + timeout: 5s + retries: 5 + volumes: + - machine:/var/opt/cartesi/machine-snapshots + environment: + - SERVER_MANAGER_LOG_LEVEL=warning + - REMOTE_CARTESI_MACHINE_LOG_LEVEL=info + + database: + image: postgres:13-alpine + ports: + - 5432:5432 + healthcheck: + test: ["CMD-SHELL", "pg_isready -U postgres || exit 1"] + interval: 10s + timeout: 5s + retries: 5 + environment: + - POSTGRES_PASSWORD=password + volumes: + - database-data:/var/lib/postgresql/data + + redis: + image: redis:6-alpine + ports: + - 6379:6379 + restart: always + healthcheck: + test: ["CMD", "redis-cli", "ping"] + interval: 10s + timeout: 5s + retries: 5 + volumes: + - redis-data:/data + +volumes: + blockchain-data: {} + machine: {} + database-data: {} + redis-data: {} diff --git a/build/machine.Dockerfile b/build/machine.Dockerfile new file mode 100644 index 000000000..221811764 --- /dev/null +++ b/build/machine.Dockerfile @@ -0,0 +1,30 @@ +# (c) Cartesi and individual authors (see AUTHORS) +# SPDX-License-Identifier: Apache-2.0 (see LICENSE) + +FROM cartesi/server-manager:0.8.2 as build-server-stage + +USER root + +# Install system dependencies +RUN apt update && \ + apt install -y wget + +# Download rootfs, linux and rom +ENV IMAGES_PATH /usr/share/cartesi-machine/images +RUN wget -O ${IMAGES_PATH}/rootfs.ext2 https://github.com/cartesi/image-rootfs/releases/download/v0.18.0/rootfs-v0.18.0.ext2 && \ + wget -O ${IMAGES_PATH}/linux.bin https://github.com/cartesi/image-kernel/releases/download/v0.17.0/linux-5.15.63-ctsi-2-v0.17.0.bin && \ + wget -O ${IMAGES_PATH}/rom.bin https://github.com/cartesi/machine-emulator-rom/releases/download/v0.17.0/rom-v0.17.0.bin + +# Generate machine with echo and store it +ENV SNAPSHOT_DIR=/tmp/dapp-bin +RUN cartesi-machine \ + --ram-length=128Mi \ + --rollup \ + --store=$SNAPSHOT_DIR \ + -- "ioctl-echo-loop --vouchers=1 --notices=1 --reports=1 --verbose=1" + +FROM cartesi/server-manager:0.8.2 as server-stage + +WORKDIR /opt/cartesi/bin +COPY --from=build-server-stage --chown=cartesi:cartesi /tmp/dapp-bin /var/opt/cartesi/machine-snapshots/0_0 +RUN ln -s /var/opt/cartesi/machine-snapshots/0_0 /var/opt/cartesi/machine-snapshots/latest From 01ca3da4d2691c703a4617881e305de69286b6aa Mon Sep 17 00:00:00 2001 From: Francisco Moura Date: Sun, 19 Nov 2023 12:01:40 -0300 Subject: [PATCH 2/2] Add node run infrastructure --- .gitignore | 1 + build/devnet/deploy-rollups-anvil.sh | 33 ++++ build/devnet/devnet.Dockerfile | 38 ++++ build/devnet/entrypoint.sh | 3 + build/devnet/eth_isready | 4 + build/docker-bake.hcl | 12 ++ devnet/README.md | 26 +++ devnet/docker-compose.yml | 270 +++++++++++++++++++++++++++ 8 files changed, 387 insertions(+) create mode 100755 build/devnet/deploy-rollups-anvil.sh create mode 100644 build/devnet/devnet.Dockerfile create mode 100755 build/devnet/entrypoint.sh create mode 100644 build/devnet/eth_isready create mode 100644 devnet/README.md create mode 100644 devnet/docker-compose.yml diff --git a/.gitignore b/.gitignore index f22a3ae7c..b8fc43913 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ .DS_Store build/deployments **/.idea/ +build/devnet/anvil_state.json diff --git a/build/devnet/deploy-rollups-anvil.sh b/build/devnet/deploy-rollups-anvil.sh new file mode 100755 index 000000000..c0c224eef --- /dev/null +++ b/build/devnet/deploy-rollups-anvil.sh @@ -0,0 +1,33 @@ +#!/bin/bash + + +# Run Anvil in the background +cmd="anvil --host 0.0.0.0 --dump-state anvil_state.json" +eval "${cmd}" &>/dev/null & disown; + + +# Check Anvil is ready +retries=0 +max_retries=50 +while [ $retries -lt $max_retries ]; do + + ready=$(curl -X POST -s -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","id":"1","method":"net_listening","params":[]}' http://127.0.0.1:8545 | jq '.result') + + if [ "$ready" == "true" ]; then + echo "Anvil is ready" + break + else + sleep 3 + fi +done + + +# Deploy contracts with Foundry +### DEPLOY CONTRACTS HERE ### + +# TEMP : To help debug +# read -n 1 -s -r -p "Press any key to continue" + +sleep 3 +#Kill Anvil ( just exit ) +exit 0 \ No newline at end of file diff --git a/build/devnet/devnet.Dockerfile b/build/devnet/devnet.Dockerfile new file mode 100644 index 000000000..0ad9a37be --- /dev/null +++ b/build/devnet/devnet.Dockerfile @@ -0,0 +1,38 @@ +# syntax=docker.io/docker/dockerfile:1.4 +FROM debian:bookworm-20230814-slim as devnet-base + +# install curl and jq (for healthcheck support) +RUN < /dev/tcp/127.0.0.1/50051;'"] + interval: 10s + timeout: 5s + retries: 5 + depends_on: + anvil: + condition: service_healthy + environment: + RUST_LOG: info + SF_GENESIS_BLOCK: 0x1 + SF_SAFETY_MARGIN: 1 + BH_HTTP_ENDPOINT: http://anvil:8545 + BH_WS_ENDPOINT: ws://anvil:8545 + BH_BLOCK_TIMEOUT: 8 + + advance_runner: + build: + context: .. + dockerfile: build/Dockerfile + tags: + - "cartesi/rollups-node:devel" + command: cartesi-rollups-advance-runner + restart: always + healthcheck: + test: [ "CMD", "curl", "--fail", "localhost:8080/healthz" ] + interval: 10s + timeout: 5s + retries: 5 + depends_on: + redis: + condition: service_healthy + server_manager: + condition: service_healthy + deployer: + condition: service_completed_successfully + volumes: + - ./deployments:/deployments:ro + - machine:/var/opt/cartesi/machine-snapshots + environment: + RUST_LOG: info + SERVER_MANAGER_ENDPOINT: http://server_manager:5001 + PROVIDER_HTTP_ENDPOINT: http://anvil:8545 + SESSION_ID: default_rollups_id + REDIS_ENDPOINT: redis://redis:6379 + CHAIN_ID: 31337 + DAPP_CONTRACT_ADDRESS_FILE: /deployments/localhost/dapp.json + SNAPSHOT_DIR: /var/opt/cartesi/machine-snapshots + SNAPSHOT_LATEST: /var/opt/cartesi/machine-snapshots/latest + + + inspect_server: + build: + context: .. + dockerfile: build/Dockerfile + tags: + - "cartesi/rollups-node:devel" + command: cartesi-rollups-inspect-server + restart: always + ports: + - "5005:5005" + depends_on: + server_manager: + condition: service_healthy + environment: + RUST_LOG: info + INSPECT_SERVER_ADDRESS: 0.0.0.0:5005 + SERVER_MANAGER_ADDRESS: server_manager:5001 + SESSION_ID: default_rollups_id + + indexer: + build: + context: .. + dockerfile: build/Dockerfile + tags: + - "cartesi/rollups-node:devel" + command: cartesi-rollups-indexer + restart: always + depends_on: + database: + condition: service_healthy + redis: + condition: service_healthy + deployer: + condition: service_completed_successfully + environment: + POSTGRES_ENDPOINT: postgres://postgres:password@database:5432/postgres + RUST_LOG: info + REDIS_ENDPOINT: redis://redis:6379 + CHAIN_ID: 31337 + DAPP_CONTRACT_ADDRESS_FILE: /deployments/localhost/dapp.json + volumes: + - ./deployments:/deployments:ro + + graphql_server: + build: + context: .. + dockerfile: build/Dockerfile + tags: + - "cartesi/rollups-node:devel" + command: cartesi-rollups-graphql-server + ports: + - "4000:4000" + depends_on: + database: + condition: service_healthy + environment: + RUST_LOG: info + GRAPHQL_HOST: "0.0.0.0" + GRAPHQL_PORT: "4000" + POSTGRES_ENDPOINT: postgres://postgres:password@database:5432/postgres + + + deployer: + image: cartesi/rollups-cli:1.0.0 + restart: on-failure + depends_on: + anvil: + condition: service_healthy + server_manager: + condition: service_healthy + command: + [ + "create", + "--rpc", + "http://anvil:8545", + "--deploymentFile", + "/opt/cartesi/share/deployments/localhost.json", + "--mnemonic", + "test test test test test test test test test test test junk", + "--templateHashFile", + "/var/opt/cartesi/machine-snapshots/0_0/hash", + "--outputFile", + "/deployments/localhost/dapp.json" + ] + volumes: + - blockchain-data:/opt/cartesi/share/deployments:ro + - machine:/var/opt/cartesi/machine-snapshots:ro + - ./deployments:/deployments + + + server_manager: + build: + context: .. + dockerfile: build/machine.Dockerfile + restart: always + ports: + - "5001:5001" + healthcheck: + test: ["CMD-SHELL", 'bash -c ''echo "" > /dev/tcp/127.0.0.1/5001;'''] + interval: 10s + timeout: 5s + retries: 5 + volumes: + - machine:/var/opt/cartesi/machine-snapshots + environment: + - SERVER_MANAGER_LOG_LEVEL=warning + - REMOTE_CARTESI_MACHINE_LOG_LEVEL=info + + database: + image: postgres:13-alpine + ports: + - 5432:5432 + healthcheck: + test: ["CMD-SHELL", "pg_isready -U postgres || exit 1"] + interval: 10s + timeout: 5s + retries: 5 + environment: + - POSTGRES_PASSWORD=password + volumes: + - database-data:/var/lib/postgresql/data + + redis: + image: redis:6-alpine + ports: + - 6379:6379 + restart: always + healthcheck: + test: ["CMD", "redis-cli", "ping"] + interval: 10s + timeout: 5s + retries: 5 + volumes: + - redis-data:/data + +volumes: + blockchain-data: {} + machine: {} + database-data: {} + redis-data: {}