Skip to content

Commit

Permalink
Use standalone mobymask-v2-watcher-ts for running watcher server (cer…
Browse files Browse the repository at this point in the history
…c-io#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

Former-commit-id: c4002dc
  • Loading branch information
nikugogoi authored Apr 19, 2023
1 parent 4caae1d commit 53fbc60
Show file tree
Hide file tree
Showing 16 changed files with 103 additions and 63 deletions.
6 changes: 5 additions & 1 deletion app/data/compose/docker-compose-peer-test-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
42 changes: 39 additions & 3 deletions app/data/compose/docker-compose-watcher-mobymask-v2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,27 @@ 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
restart: unless-stopped
depends_on:
mobymask-watcher-db:
condition: service_healthy
peer-ids-gen:
condition: service_completed_successfully
mobymask:
condition: service_completed_successfully
env_file:
Expand All @@ -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
Expand All @@ -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:
Expand Down
20 changes: 20 additions & 0 deletions app/data/config/watcher-mobymask-v2/generate-peer-ids.sh
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions app/data/config/watcher-mobymask-v2/set-tests-env.sh
Original file line number Diff line number Diff line change
@@ -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
24 changes: 1 addition & 23 deletions app/data/config/watcher-mobymask-v2/start-server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ COPY . .
RUN echo "Building watcher-ts" && \
yarn && yarn build

WORKDIR /app/packages/mobymask-v2-watcher
WORKDIR /app
2 changes: 1 addition & 1 deletion app/data/container-build/cerc-watcher-mobymask-v2/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 10 additions & 0 deletions app/data/container-build/cerc-watcher-ts/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions app/data/container-build/cerc-watcher-ts/build.sh
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions app/data/container-image-list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions app/data/pod-list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ laconicd
fixturenet-laconicd
fixturenet-eth
fixturenet-eth-metrics
watcher-ts
watcher-mobymask
watcher-erc20
watcher-erc721
Expand Down
1 change: 1 addition & 0 deletions app/data/repository-list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 3 additions & 11 deletions app/data/stacks/mobymask-v2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/data/stacks/mobymask-v2/demo.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions app/data/stacks/mobymask-v2/stack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
20 changes: 0 additions & 20 deletions app/data/stacks/mobymask-v2/web-apps.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 53fbc60

Please sign in to comment.