From c4002dcc5c5001d3b45cda334bcc64929a1c7dbc Mon Sep 17 00:00:00 2001 From: Nabarun Gogoi Date: Wed, 19 Apr 2023 13:48:51 +0530 Subject: [PATCH] Use standalone mobymask-v2-watcher-ts for running watcher server (#327) * Use standalone mobymask-v2-watcher-ts to run peer test * Add watcher-ts image for running peer tests * Run separate containers for peer ids generation and tests * Wait for watcher to be up before starting peer-test-app * Resolve peer-test-app compose file and remove setup-repositories for web-apps --- .../compose/docker-compose-peer-test-app.yml | 6 ++- .../docker-compose-watcher-mobymask-v2.yml | 42 +++++++++++++++++-- .../watcher-mobymask-v2/generate-peer-ids.sh | 20 +++++++++ .../watcher-mobymask-v2/set-tests-env.sh | 10 +++++ .../watcher-mobymask-v2/start-server.sh | 24 +---------- .../cerc-watcher-mobymask-v2/Dockerfile | 2 +- .../cerc-watcher-mobymask-v2/build.sh | 2 +- .../cerc-watcher-ts/Dockerfile | 10 +++++ .../container-build/cerc-watcher-ts/build.sh | 7 ++++ app/data/container-image-list.txt | 1 + app/data/pod-list.txt | 1 + app/data/repository-list.txt | 1 + app/data/stacks/mobymask-v2/README.md | 14 ++----- app/data/stacks/mobymask-v2/demo.md | 2 +- app/data/stacks/mobymask-v2/stack.yml | 4 +- app/data/stacks/mobymask-v2/web-apps.md | 20 --------- 16 files changed, 103 insertions(+), 63 deletions(-) create mode 100755 app/data/config/watcher-mobymask-v2/generate-peer-ids.sh create mode 100755 app/data/config/watcher-mobymask-v2/set-tests-env.sh create mode 100644 app/data/container-build/cerc-watcher-ts/Dockerfile create mode 100755 app/data/container-build/cerc-watcher-ts/build.sh diff --git a/app/data/compose/docker-compose-peer-test-app.yml b/app/data/compose/docker-compose-peer-test-app.yml index 0a8d1c65..927f92f7 100644 --- a/app/data/compose/docker-compose-peer-test-app.yml +++ b/app/data/compose/docker-compose-peer-test-app.yml @@ -10,8 +10,12 @@ services: environment: CERC_SCRIPT_DEBUG: ${CERC_SCRIPT_DEBUG} CERC_RELAY_NODES: ${CERC_RELAY_NODES} - command: ["sh", "./test-app-start.sh"] + command: + - sh + - -c + - ./wait-for-it.sh -h ${CERC_WATCHER_HOST:-$${DEFAULT_CERC_WATCHER_HOST}} -p ${CERC_WATCHER_PORT:-$${DEFAULT_CERC_WATCHER_PORT}} -s -t 0 -- ./test-app-start.sh volumes: + - ../config/wait-for-it.sh:/scripts/wait-for-it.sh - ../config/watcher-mobymask-v2/test-app-start.sh:/scripts/test-app-start.sh - peers_ids:/peers ports: diff --git a/app/data/compose/docker-compose-watcher-mobymask-v2.yml b/app/data/compose/docker-compose-watcher-mobymask-v2.yml index 601d13b6..fa68d017 100644 --- a/app/data/compose/docker-compose-watcher-mobymask-v2.yml +++ b/app/data/compose/docker-compose-watcher-mobymask-v2.yml @@ -54,6 +54,18 @@ services: extra_hosts: - "host.docker.internal:host-gateway" + # Creates peer-id files if they don't exist + peer-ids-gen: + image: cerc/watcher-ts:local + restart: on-failure + environment: + CERC_SCRIPT_DEBUG: ${CERC_SCRIPT_DEBUG} + working_dir: /app/packages/peer + command: ["sh", "generate-peer-ids.sh"] + volumes: + - ../config/watcher-mobymask-v2/generate-peer-ids.sh:/app/packages/peer/generate-peer-ids.sh + - peers_ids:/peer-ids + # Starts the mobymask-v2-watcher server mobymask-watcher-server: image: cerc/watcher-mobymask-v2:local @@ -61,6 +73,8 @@ services: depends_on: mobymask-watcher-db: condition: service_healthy + peer-ids-gen: + condition: service_completed_successfully mobymask: condition: service_completed_successfully env_file: @@ -76,9 +90,9 @@ services: CERC_DEPLOYED_CONTRACT: ${CERC_DEPLOYED_CONTRACT} command: ["sh", "start-server.sh"] volumes: - - ../config/watcher-mobymask-v2/watcher-config-template.toml:/app/packages/mobymask-v2-watcher/environments/watcher-config-template.toml - - ../config/watcher-mobymask-v2/start-server.sh:/app/packages/mobymask-v2-watcher/start-server.sh - - peers_ids:/app/packages/mobymask-v2-watcher/peers + - ../config/watcher-mobymask-v2/watcher-config-template.toml:/app/environments/watcher-config-template.toml + - ../config/watcher-mobymask-v2/start-server.sh:/app/start-server.sh + - peers_ids:/app/peers - mobymask_deployment:/server - fixturenet_geth_accounts:/geth-accounts:ro # Expose GQL, metrics and relay node ports @@ -95,6 +109,28 @@ services: extra_hosts: - "host.docker.internal:host-gateway" + # Container to run peer tests + peer-tests: + image: cerc/watcher-ts:local + restart: on-failure + depends_on: + mobymask-watcher-server: + condition: service_healthy + peer-ids-gen: + condition: service_completed_successfully + environment: + CERC_SCRIPT_DEBUG: ${CERC_SCRIPT_DEBUG} + working_dir: /app/packages/peer + command: + - sh + - -c + - | + ./set-tests-env.sh && \ + tail -f /dev/null + volumes: + - ../config/watcher-mobymask-v2/set-tests-env.sh:/app/packages/peer/set-tests-env.sh + - peers_ids:/peer-ids + volumes: mobymask_watcher_db_data: peers_ids: diff --git a/app/data/config/watcher-mobymask-v2/generate-peer-ids.sh b/app/data/config/watcher-mobymask-v2/generate-peer-ids.sh new file mode 100755 index 00000000..5c97c45d --- /dev/null +++ b/app/data/config/watcher-mobymask-v2/generate-peer-ids.sh @@ -0,0 +1,20 @@ +#!/bin/sh +set -e +if [ -n "$CERC_SCRIPT_DEBUG" ]; then + set -x +fi + +# Check for peer ids in ./peers folder, create if not present +if [ -f /peer-ids/relay-id.json ]; then + echo "Using peer id for relay node from the mounted volume" +else + echo "Creating a new peer id for relay node" + yarn create-peer -f /peer-ids/relay-id.json +fi + +if [ -f /peer-ids/peer-id.json ]; then + echo "Using peer id for peer node from the mounted volume" +else + echo "Creating a new peer id for peer node" + yarn create-peer -f /peer-ids/peer-id.json +fi diff --git a/app/data/config/watcher-mobymask-v2/set-tests-env.sh b/app/data/config/watcher-mobymask-v2/set-tests-env.sh new file mode 100755 index 00000000..5e31b763 --- /dev/null +++ b/app/data/config/watcher-mobymask-v2/set-tests-env.sh @@ -0,0 +1,10 @@ +#!/bin/sh +set -e +if [ -n "$CERC_SCRIPT_DEBUG" ]; then + set -x +fi + +CERC_RELAY_MULTIADDR="/dns4/mobymask-watcher-server/tcp/9090/ws/p2p/$(jq -r '.id' /peer-ids/relay-id.json)" + +# Write the relay node's multiaddr to /app/packages/peer/.env for running tests +echo "RELAY=\"$CERC_RELAY_MULTIADDR\"" > ./.env diff --git a/app/data/config/watcher-mobymask-v2/start-server.sh b/app/data/config/watcher-mobymask-v2/start-server.sh index b5a3518e..02184842 100755 --- a/app/data/config/watcher-mobymask-v2/start-server.sh +++ b/app/data/config/watcher-mobymask-v2/start-server.sh @@ -14,26 +14,7 @@ CERC_DEPLOYED_CONTRACT="${CERC_DEPLOYED_CONTRACT:-${DEFAULT_CERC_DEPLOYED_CONTRA echo "Using L2 RPC endpoint ${CERC_L2_GETH_RPC}" -# Check for peer ids in ./peers folder, create if not present -if [ -f ./peers/relay-id.json ]; then - echo "Using peer id for relay node from the mounted volume" -else - echo "Creating a new peer id for relay node" - cd ../peer - yarn create-peer -f ../mobymask-v2-watcher/peers/relay-id.json - cd ../mobymask-v2-watcher -fi - -if [ -f ./peers/peer-id.json ]; then - echo "Using peer id for peer node from the mounted volume" -else - echo "Creating a new peer id for peer node" - cd ../peer - yarn create-peer -f ../mobymask-v2-watcher/peers/peer-id.json - cd ../mobymask-v2-watcher -fi - -CERC_RELAY_MULTIADDR="/dns4/mobymask-watcher-server/tcp/9090/ws/p2p/$(jq -r '.id' ./peers/relay-id.json)" +CERC_RELAY_MULTIADDR="/dns4/mobymask-watcher-server/tcp/9090/ws/p2p/$(jq -r '.id' /app/peers/relay-id.json)" # Use contract address from environment variable or set from config.json in mounted volume if [ -n "$CERC_DEPLOYED_CONTRACT" ]; then @@ -65,8 +46,5 @@ WATCHER_CONFIG=$(echo "$WATCHER_CONFIG_TEMPLATE" | \ # Write the modified content to a new file echo "$WATCHER_CONFIG" > environments/local.toml -# Write the relay node's multiaddr to /app/packages/peer/.env for running tests -echo "RELAY=\"$CERC_RELAY_MULTIADDR\"" > /app/packages/peer/.env - echo 'yarn server' yarn server diff --git a/app/data/container-build/cerc-watcher-mobymask-v2/Dockerfile b/app/data/container-build/cerc-watcher-mobymask-v2/Dockerfile index 18aff5cd..9d1a70b7 100644 --- a/app/data/container-build/cerc-watcher-mobymask-v2/Dockerfile +++ b/app/data/container-build/cerc-watcher-mobymask-v2/Dockerfile @@ -17,4 +17,4 @@ COPY . . RUN echo "Building watcher-ts" && \ yarn && yarn build -WORKDIR /app/packages/mobymask-v2-watcher +WORKDIR /app diff --git a/app/data/container-build/cerc-watcher-mobymask-v2/build.sh b/app/data/container-build/cerc-watcher-mobymask-v2/build.sh index f8b59224..b26ad999 100755 --- a/app/data/container-build/cerc-watcher-mobymask-v2/build.sh +++ b/app/data/container-build/cerc-watcher-mobymask-v2/build.sh @@ -6,4 +6,4 @@ source ${CERC_CONTAINER_BASE_DIR}/build-base.sh # 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 ${build_command_args} ${CERC_REPO_BASE_DIR}/watcher-ts +docker build -t cerc/watcher-mobymask-v2:local -f ${SCRIPT_DIR}/Dockerfile ${build_command_args} ${CERC_REPO_BASE_DIR}/mobymask-v2-watcher-ts diff --git a/app/data/container-build/cerc-watcher-ts/Dockerfile b/app/data/container-build/cerc-watcher-ts/Dockerfile new file mode 100644 index 00000000..75ba2efa --- /dev/null +++ b/app/data/container-build/cerc-watcher-ts/Dockerfile @@ -0,0 +1,10 @@ +FROM node:16.17.1-alpine3.16 + +RUN apk --update --no-cache add git python3 alpine-sdk jq + +WORKDIR /app + +COPY . . + +RUN echo "Building watcher-ts" && \ + yarn && yarn build diff --git a/app/data/container-build/cerc-watcher-ts/build.sh b/app/data/container-build/cerc-watcher-ts/build.sh new file mode 100755 index 00000000..e180ec0e --- /dev/null +++ b/app/data/container-build/cerc-watcher-ts/build.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +# Build cerc/watcher-erc20 + +# See: https://stackoverflow.com/a/246128/1701505 +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + +docker build -t cerc/watcher-ts: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 150d81ae..0635c4c8 100644 --- a/app/data/container-image-list.txt +++ b/app/data/container-image-list.txt @@ -14,6 +14,7 @@ cerc/laconic-registry-cli cerc/laconic-console-host cerc/fixturenet-eth-geth cerc/fixturenet-eth-lighthouse +cerc/watcher-ts cerc/watcher-mobymask cerc/watcher-erc20 cerc/watcher-erc721 diff --git a/app/data/pod-list.txt b/app/data/pod-list.txt index f24c9ed0..ef42ad9e 100644 --- a/app/data/pod-list.txt +++ b/app/data/pod-list.txt @@ -10,6 +10,7 @@ laconicd fixturenet-laconicd fixturenet-eth fixturenet-eth-metrics +watcher-ts watcher-mobymask watcher-erc20 watcher-erc721 diff --git a/app/data/repository-list.txt b/app/data/repository-list.txt index 3f8c84bf..bfb6085c 100644 --- a/app/data/repository-list.txt +++ b/app/data/repository-list.txt @@ -12,6 +12,7 @@ cerc-io/laconic-registry-cli cerc-io/laconic-console cerc-io/mobymask-watcher cerc-io/watcher-ts +cerc-io/mobymask-v2-watcher-ts cerc-io/react-peer cerc-io/mobymask-ui cerc-io/MobyMask diff --git a/app/data/stacks/mobymask-v2/README.md b/app/data/stacks/mobymask-v2/README.md index aaa4ac7f..fb4aebcd 100644 --- a/app/data/stacks/mobymask-v2/README.md +++ b/app/data/stacks/mobymask-v2/README.md @@ -23,15 +23,7 @@ Checkout to the required versions and branches in repos ```bash # watcher-ts cd ~/cerc/watcher-ts -git checkout v0.2.35 - -# react-peer -cd ~/cerc/react-peer -git checkout v0.2.32 - -# mobymask-ui -cd ~/cerc/mobymask-ui -git checkout v0.1.2 +git checkout v0.2.39 # MobyMask cd ~/cerc/MobyMask @@ -73,13 +65,13 @@ Deploy the stack: Find the watcher container's id and export it for later use: ```bash -export CONTAINER_ID=$(docker ps -q --filter "name=mobymask-watcher-server") +export CONTAINER_ID=$(docker ps -q --filter "name=peer-tests") ``` Run the peer tests: ```bash -docker exec -w /app/packages/peer $CONTAINER_ID yarn test +docker exec $CONTAINER_ID yarn test ``` ## Web Apps diff --git a/app/data/stacks/mobymask-v2/demo.md b/app/data/stacks/mobymask-v2/demo.md index 329b554d..953390cf 100644 --- a/app/data/stacks/mobymask-v2/demo.md +++ b/app/data/stacks/mobymask-v2/demo.md @@ -66,7 +66,7 @@ * Get the deployed contract address: ```bash - docker exec -it $(docker ps -aq --filter name="mobymask-app") cat src/config.json + docker exec -it $(docker ps -aq --filter name="mobymask-app") cat /config/config.yml ``` The value of `address` field is the deployed contract address diff --git a/app/data/stacks/mobymask-v2/stack.yml b/app/data/stacks/mobymask-v2/stack.yml index 248351b1..b91e4461 100644 --- a/app/data/stacks/mobymask-v2/stack.yml +++ b/app/data/stacks/mobymask-v2/stack.yml @@ -6,8 +6,7 @@ repos: - ethereum-optimism/optimism - ethereum-optimism/op-geth - cerc-io/watcher-ts - - cerc-io/react-peer - - cerc-io/mobymask-ui + - cerc-io/mobymask-v2-watcher-ts - cerc-io/MobyMask containers: - cerc/go-ethereum @@ -19,6 +18,7 @@ containers: - cerc/optimism-l2geth - cerc/optimism-op-batcher - cerc/optimism-op-node + - cerc/watcher-ts - cerc/watcher-mobymask-v2 - cerc/react-peer - cerc/mobymask-ui diff --git a/app/data/stacks/mobymask-v2/web-apps.md b/app/data/stacks/mobymask-v2/web-apps.md index 866f22f0..76293f1f 100644 --- a/app/data/stacks/mobymask-v2/web-apps.md +++ b/app/data/stacks/mobymask-v2/web-apps.md @@ -6,26 +6,6 @@ Instructions to setup and deploy MobyMask and Peer Test web apps Prerequisite: Watcher with GQL and relay node endpoints -Clone required repositories: - -```bash -laconic-so --stack mobymask-v2 setup-repositories --include cerc-io/react-peer,cerc-io/mobymask-ui - -# If this throws an error as a result of being already checked out to a branch/tag in a repo, remove the repositories mentioned below and re-run the command -``` - -Checkout to the required versions and branches in repos: - -```bash -# react-peer -cd ~/cerc/react-peer -git checkout v0.2.32 - -# mobymask-ui -cd ~/cerc/mobymask-ui -git checkout v0.1.2 -``` - Build the container images: ```bash