From 4d3042bfcce4618072ca630bdb9b48b3100e2eb8 Mon Sep 17 00:00:00 2001 From: Nabarun Gogoi <95nikass@gmail.com> Date: Mon, 20 Mar 2023 18:25:39 +0530 Subject: [PATCH] Add a stack for mobymask-v2-watcher to run peer tests (#222) * Add mobymask-v2-watcher stack with peer tests * Rename stack and container * Avoid building react-peer container * Improve step for getting container ID Former-commit-id: 78310788729e245040d3144d41c57160be14d774 --- .../docker-compose-watcher-mobymask-v2.yml | 47 +++++++++++++ app/data/config/watcher-mobymask-v2/.env | 1 + .../config/watcher-mobymask-v2/config.json | 8 +++ .../config/watcher-mobymask-v2/relay-id.json | 5 ++ .../config/watcher-mobymask-v2/watcher.toml | 70 +++++++++++++++++++ .../cerc-mobymask-ui/Dockerfile | 12 ++++ .../container-build/cerc-mobymask-ui/build.sh | 7 ++ .../cerc-react-peer/Dockerfile | 12 ++++ .../container-build/cerc-react-peer/build.sh | 7 ++ .../cerc-watcher-mobymask-v2/Dockerfile | 20 ++++++ .../cerc-watcher-mobymask-v2/build.sh | 7 ++ app/data/container-image-list.txt | 3 + app/data/pod-list.txt | 1 + app/data/repository-list.txt | 2 + app/data/stacks/mobymask-v2/README.md | 61 ++++++++++++++++ app/data/stacks/mobymask-v2/stack.yml | 11 +++ 16 files changed, 274 insertions(+) create mode 100644 app/data/compose/docker-compose-watcher-mobymask-v2.yml create mode 100644 app/data/config/watcher-mobymask-v2/.env create mode 100644 app/data/config/watcher-mobymask-v2/config.json create mode 100644 app/data/config/watcher-mobymask-v2/relay-id.json create mode 100644 app/data/config/watcher-mobymask-v2/watcher.toml create mode 100644 app/data/container-build/cerc-mobymask-ui/Dockerfile create mode 100755 app/data/container-build/cerc-mobymask-ui/build.sh create mode 100644 app/data/container-build/cerc-react-peer/Dockerfile create mode 100755 app/data/container-build/cerc-react-peer/build.sh create mode 100644 app/data/container-build/cerc-watcher-mobymask-v2/Dockerfile create mode 100755 app/data/container-build/cerc-watcher-mobymask-v2/build.sh create mode 100644 app/data/stacks/mobymask-v2/README.md create mode 100644 app/data/stacks/mobymask-v2/stack.yml diff --git a/app/data/compose/docker-compose-watcher-mobymask-v2.yml b/app/data/compose/docker-compose-watcher-mobymask-v2.yml new file mode 100644 index 00000000..250653f1 --- /dev/null +++ b/app/data/compose/docker-compose-watcher-mobymask-v2.yml @@ -0,0 +1,47 @@ +version: '3.2' + +services: + mobymask-watcher-db: + restart: unless-stopped + image: postgres:14-alpine + environment: + - POSTGRES_USER=vdbm + - POSTGRES_MULTIPLE_DATABASES=mobymask-watcher,mobymask-watcher-job-queue + - POSTGRES_EXTENSION=mobymask-watcher-job-queue:pgcrypto + - POSTGRES_PASSWORD=password + volumes: + - ../config/postgresql/multiple-postgressql-databases.sh:/docker-entrypoint-initdb.d/multiple-postgressql-databases.sh + - mobymask_watcher_db_data:/var/lib/postgresql/data + ports: + - "0.0.0.0:15432:5432" + healthcheck: + test: ["CMD", "nc", "-v", "localhost", "5432"] + interval: 20s + timeout: 5s + retries: 15 + start_period: 10s + + mobymask-watcher-server: + restart: unless-stopped + depends_on: + mobymask-watcher-db: + condition: service_healthy + image: cerc/watcher-mobymask-v2:local + command: ["sh", "-c", "yarn server"] + volumes: + - ../config/watcher-mobymask-v2/watcher.toml:/app/packages/mobymask-v2-watcher/environments/local.toml + - ../config/watcher-mobymask-v2/.env:/app/packages/peer/.env + - ../config/watcher-mobymask-v2/relay-id.json:/app/packages/mobymask-v2-watcher/relay-id.json + ports: + - "0.0.0.0:3001:3001" + - "0.0.0.0:9001:9001" + - "0.0.0.0:9090:9090" + healthcheck: + test: ["CMD", "nc", "-v", "localhost", "9090"] + interval: 20s + timeout: 5s + retries: 15 + start_period: 5s + +volumes: + mobymask_watcher_db_data: diff --git a/app/data/config/watcher-mobymask-v2/.env b/app/data/config/watcher-mobymask-v2/.env new file mode 100644 index 00000000..05af7658 --- /dev/null +++ b/app/data/config/watcher-mobymask-v2/.env @@ -0,0 +1 @@ +RELAY="/ip4/127.0.0.1/tcp/9090/http/p2p-webrtc-direct/p2p/12D3KooWSPCsVkHVyLQoCqhu2YRPvvM7o6r6NRYyLM5zeA6Uig5t" diff --git a/app/data/config/watcher-mobymask-v2/config.json b/app/data/config/watcher-mobymask-v2/config.json new file mode 100644 index 00000000..35c6f609 --- /dev/null +++ b/app/data/config/watcher-mobymask-v2/config.json @@ -0,0 +1,8 @@ +{ + "relayNodes": [ + "/ip4/127.0.0.1/tcp/9090/http/p2p-webrtc-direct/p2p/12D3KooWSPCsVkHVyLQoCqhu2YRPvvM7o6r6NRYyLM5zeA6Uig5t" + ], + "peer": { + "enableDebugInfo": true + } +} diff --git a/app/data/config/watcher-mobymask-v2/relay-id.json b/app/data/config/watcher-mobymask-v2/relay-id.json new file mode 100644 index 00000000..d7edc6dc --- /dev/null +++ b/app/data/config/watcher-mobymask-v2/relay-id.json @@ -0,0 +1,5 @@ +{ + "id": "12D3KooWSPCsVkHVyLQoCqhu2YRPvvM7o6r6NRYyLM5zeA6Uig5t", + "privKey": "CAESQGsqG5o4VlWJZM9XlA3MjabyZOXWQ2MLZU5AhBQsjXGt9iSlGtTuNOrHX5xSRgLBxLuMoqWsjGxE/dDB9c46RI8=", + "pubKey": "CAESIPYkpRrU7jTqx1+cUkYCwcS7jKKlrIxsRP3QwfXOOkSP" +} diff --git a/app/data/config/watcher-mobymask-v2/watcher.toml b/app/data/config/watcher-mobymask-v2/watcher.toml new file mode 100644 index 00000000..f765db61 --- /dev/null +++ b/app/data/config/watcher-mobymask-v2/watcher.toml @@ -0,0 +1,70 @@ +[server] + host = "0.0.0.0" + port = 3001 + kind = "lazy" + + # Checkpointing state. + checkpointing = true + + # Checkpoint interval in number of blocks. + checkpointInterval = 2000 + + # Enable state creation + enableState = true + + # Boolean to filter logs by contract. + filterLogs = true + + # Max block range for which to return events in eventsInRange GQL query. + # Use -1 for skipping check on block range. + maxEventsBlockRange = -1 + + [server.p2p] + enableRelay = true + enablePeer = false + + [server.p2p.relay] + host = "0.0.0.0" + port = 9090 + relayPeers = [] + peerIdFile = './relay-id.json' + enableDebugInfo = true + + [server.p2p.peer] + relayMultiaddr = '/ip4/mobymask-watcher-server/tcp/9090/http/p2p-webrtc-direct/p2p/12D3KooWSPCsVkHVyLQoCqhu2YRPvvM7o6r6NRYyLM5zeA6Uig5t' + pubSubTopic = 'mobymask' + peerIdFile = './peer-id.json' + enableDebugInfo = true + +[metrics] + host = "0.0.0.0" + port = 9000 + [metrics.gql] + port = 9001 + +[database] + type = "postgres" + host = "mobymask-watcher-db" + port = 5432 + database = "mobymask-watcher" + username = "vdbm" + password = "password" + synchronize = true + logging = false + +[upstream] + [upstream.ethServer] + gqlApiEndpoint = "http://ipld-eth-server:8083/graphql" + rpcProviderEndpoint = "http://ipld-eth-server:8082" + blockDelayInMilliSecs = 60000 + + [upstream.cache] + name = "requests" + enabled = false + deleteOnStart = false + +[jobQueue] + dbConnectionString = "postgres://vdbm:password@mobymask-watcher-db/mobymask-watcher-job-queue" + maxCompletionLagInSecs = 300 + jobDelayInMilliSecs = 100 + eventsInBatch = 50 diff --git a/app/data/container-build/cerc-mobymask-ui/Dockerfile b/app/data/container-build/cerc-mobymask-ui/Dockerfile new file mode 100644 index 00000000..86a056b7 --- /dev/null +++ b/app/data/container-build/cerc-mobymask-ui/Dockerfile @@ -0,0 +1,12 @@ +FROM node:18.15.0-alpine3.16 + +RUN apk --update --no-cache add make git + +WORKDIR /app + +COPY . . + +RUN echo "Building mobymask-ui" && \ + npm install + +WORKDIR /app diff --git a/app/data/container-build/cerc-mobymask-ui/build.sh b/app/data/container-build/cerc-mobymask-ui/build.sh new file mode 100755 index 00000000..cabd63ff --- /dev/null +++ b/app/data/container-build/cerc-mobymask-ui/build.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +# Build cerc/mobymask-ui + +# See: https://stackoverflow.com/a/246128/1701505 +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + +docker build -t cerc/mobymask-ui:local -f ${SCRIPT_DIR}/Dockerfile ${CERC_REPO_BASE_DIR}/mobymask-ui diff --git a/app/data/container-build/cerc-react-peer/Dockerfile b/app/data/container-build/cerc-react-peer/Dockerfile new file mode 100644 index 00000000..2511d623 --- /dev/null +++ b/app/data/container-build/cerc-react-peer/Dockerfile @@ -0,0 +1,12 @@ +FROM node:18.15.0-alpine3.16 + +RUN apk --update --no-cache add make git + +WORKDIR /app + +COPY . . + +RUN echo "Building react-peer" && \ + yarn && yarn workspace @cerc-io/react-peer build + +WORKDIR /app diff --git a/app/data/container-build/cerc-react-peer/build.sh b/app/data/container-build/cerc-react-peer/build.sh new file mode 100755 index 00000000..a3d328de --- /dev/null +++ b/app/data/container-build/cerc-react-peer/build.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +# Build cerc/react-peer + +# See: https://stackoverflow.com/a/246128/1701505 +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + +docker build -t cerc/react-peer:local -f ${SCRIPT_DIR}/Dockerfile ${CERC_REPO_BASE_DIR}/react-peer diff --git a/app/data/container-build/cerc-watcher-mobymask-v2/Dockerfile b/app/data/container-build/cerc-watcher-mobymask-v2/Dockerfile new file mode 100644 index 00000000..501c8f10 --- /dev/null +++ b/app/data/container-build/cerc-watcher-mobymask-v2/Dockerfile @@ -0,0 +1,20 @@ +FROM ubuntu:22.04 + +RUN apt-get update \ + && apt-get install -y curl gnupg build-essential \ + && curl --silent --location https://deb.nodesource.com/setup_18.x | bash - \ + && apt-get update \ + && apt-get install -y nodejs git \ + && node -v + +RUN corepack enable \ + && yarn --version + +WORKDIR /app + +COPY . . + +RUN echo "Building watcher-ts" && \ + yarn && yarn build + +WORKDIR /app/packages/mobymask-v2-watcher diff --git a/app/data/container-build/cerc-watcher-mobymask-v2/build.sh b/app/data/container-build/cerc-watcher-mobymask-v2/build.sh new file mode 100755 index 00000000..19e82818 --- /dev/null +++ b/app/data/container-build/cerc-watcher-mobymask-v2/build.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +# Build cerc/watcher-mobymask-v2 + +# See: https://stackoverflow.com/a/246128/1701505 +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + +docker build -t cerc/watcher-mobymask-v2:local -f ${SCRIPT_DIR}/Dockerfile ${CERC_REPO_BASE_DIR}/watcher-ts diff --git a/app/data/container-image-list.txt b/app/data/container-image-list.txt index 9fe22a4a..58e5e054 100644 --- a/app/data/container-image-list.txt +++ b/app/data/container-image-list.txt @@ -18,6 +18,9 @@ cerc/watcher-erc20 cerc/watcher-erc721 cerc/watcher-uniswap-v3 cerc/uniswap-v3-info +cerc/watcher-mobymask-v2 +cerc/react-peer +cerc/mobymask-ui cerc/test-container cerc/eth-probe cerc/builder-js diff --git a/app/data/pod-list.txt b/app/data/pod-list.txt index ac36a9af..99974fa6 100644 --- a/app/data/pod-list.txt +++ b/app/data/pod-list.txt @@ -14,6 +14,7 @@ watcher-mobymask watcher-erc20 watcher-erc721 watcher-uniswap-v3 +watcher-mobymask-v2 test eth-probe keycloak diff --git a/app/data/repository-list.txt b/app/data/repository-list.txt index 61b7290e..073c664b 100644 --- a/app/data/repository-list.txt +++ b/app/data/repository-list.txt @@ -11,6 +11,8 @@ cerc-io/laconic-sdk cerc-io/laconic-registry-cli cerc-io/mobymask-watcher cerc-io/watcher-ts +cerc-io/react-peer +cerc-io/mobymask-ui vulcanize/uniswap-watcher-ts vulcanize/uniswap-v3-info vulcanize/assemblyscript diff --git a/app/data/stacks/mobymask-v2/README.md b/app/data/stacks/mobymask-v2/README.md new file mode 100644 index 00000000..82886783 --- /dev/null +++ b/app/data/stacks/mobymask-v2/README.md @@ -0,0 +1,61 @@ +# MobyMask v2 watcher + +Instructions to deploy MobyMask v2 watcher stack using [laconic-stack-orchestrator](/README.md#install) + +## Setup + +Clone required repositories: + +```bash +laconic-so --stack mobymask-v2 setup-repositories +``` + +Build the container images: + +```bash +laconic-so --stack mobymask-v2 build-containers +``` + +This should create the required docker images in the local image registry. + +Deploy the stack: + +```bash +laconic-so --stack mobymask-v2 deploy-system up +``` + +## Tests + +Find the watcher container's id: + +```bash +docker ps | grep "cerc/watcher-mobymask-v2:local" +``` + +Example output + +``` +8b38e9a64d7e cerc/watcher-mobymask-v2:local "sh -c 'yarn server'" 35 seconds ago Up 14 seconds (health: starting) 0.0.0.0:3001->3001/tcp, 0.0.0.0:9001->9001/tcp, 0.0.0.0:9090->9090/tcp laconic-aeb84676de2b0a7671ae90d537fc7d26-mobymask-watcher-server-1 +``` + +In above output the container ID is `8b38e9a64d7e` + +Export it for later use: + +```bash +export CONTAINER_ID= +``` + +Run the peer tests: + +```bash +docker exec -w /app/packages/peer $CONTAINER_ID yarn test +``` + +## Clean up + +To stop all the services running in background run: + +```bash +laconic-so --stack mobymask-v2 deploy-system down +``` diff --git a/app/data/stacks/mobymask-v2/stack.yml b/app/data/stacks/mobymask-v2/stack.yml new file mode 100644 index 00000000..c9b13aa5 --- /dev/null +++ b/app/data/stacks/mobymask-v2/stack.yml @@ -0,0 +1,11 @@ +version: "1.0" +name: mobymask-v2 +repos: + - cerc-io/watcher-ts + - cerc-io/react-peer + - cerc-io/mobymask-ui +containers: + - cerc/watcher-mobymask-v2 + - cerc/mobymask-ui +pods: + - watcher-mobymask-v2