Add web-apps and laconicd in MobyMask v2 watcher stack #226

Merged
nikugogoi merged 7 commits from ng-mobymask-web-app into main 2023-03-24 11:53:54 +00:00
18 changed files with 222 additions and 22 deletions
Showing only changes of commit ebefc14bc9 - Show all commits

View File

@ -0,0 +1,25 @@
version: "3.2"
services:
laconicd:
restart: unless-stopped
image: cerc/laconicd:local
command: ["sh", "/docker-entrypoint-scripts.d/create-fixturenet.sh"]
volumes:
- ../config/fixturenet-laconicd/create-fixturenet.sh:/docker-entrypoint-scripts.d/create-fixturenet.sh
ports:
- "9473"
- "8545"
- "8546"
- "1317"
healthcheck:
test: ["CMD", "nc", "-v", "localhost", "8545"]
interval: 20s
timeout: 5s
retries: 15
start_period: 10s
networks:
# https://docs.docker.com/compose/networking/#configure-the-default-network
default:
name: mobymask-v2-network

View File

@ -21,6 +21,26 @@ services:
retries: 15
start_period: 10s
mobymask:
restart: unless-stopped
depends_on:
mobymask-watcher-db:
condition: service_healthy
image: cerc/mobymask:local
working_dir: /app/packages/server
environment:
- ENV=PROD
command: ["sh", "-c", "npm start"]
volumes:
- ../config/watcher-mobymask-v2/secrets.json:/app/packages/server/secrets.json
- moby_data_server:/app/packages/server
healthcheck:
test: ["CMD", "nc", "-v", "localhost", "3330"]
interval: 20s
timeout: 5s
retries: 15
start_period: 10s
mobymask-watcher-server:
restart: unless-stopped
depends_on:
@ -43,14 +63,32 @@ services:
retries: 15
start_period: 5s
mobymask-watcher-peer:
restart: unless-stopped
depends_on:
mobymask:
condition: service_healthy
image: cerc/watcher-mobymask-v2:local
command: ["sh", "peer-start.sh"]
volumes:
- ../config/watcher-mobymask-v2/watcher.toml:/app/packages/mobymask-v2-watcher/environments/local.toml
- ../config/watcher-mobymask-v2/peer-id.json:/app/packages/mobymask-v2-watcher/peer-id.json
- ../config/watcher-mobymask-v2/peer-start.sh:/app/packages/mobymask-v2-watcher/peer-start.sh
- moby_data_server:/server
mobymask-app:
depends_on:
mobymask-watcher-server:
condition: service_healthy
mobymask:
condition: service_healthy
image: cerc/mobymask-ui:local
command: ["sh", "-c", "npm run build && serve -s build"]
command: ["sh", "mobymask-app-start.sh"]
volumes:
- ../config/watcher-mobymask-v2/mobymask-app-config.json:/app/src/config.json
- ../config/watcher-mobymask-v2/mobymask-app.env:/app/.env
- ../config/watcher-mobymask-v2/mobymask-app-config.json:/app/src/mobymask-app-config.json
- ../config/watcher-mobymask-v2/mobymask-app-start.sh:/app/mobymask-app-start.sh
- moby_data_server:/server
ports:
- "0.0.0.0:3002:3000"
healthcheck:
@ -59,6 +97,7 @@ services:
timeout: 5s
retries: 15
start_period: 10s
shm_size: '1GB'
peer-test-app:
depends_on:
@ -80,3 +119,12 @@ services:
volumes:
mobymask_watcher_db_data:
moby_data_server:
networks:
# https://docs.docker.com/compose/networking/#configure-the-default-network
default:
# https://docs.docker.com/compose/networking/#use-a-pre-existing-network
name: mobymask-v2-network
external: true

View File

@ -1,7 +1,4 @@
{
"address": "0xF1Ec16Eedc547A60574EAD530AA120f1e108a9f4",
"name": "MobyMask",
"chainId": 9000,
"relayNodes": [
"/ip4/127.0.0.1/tcp/9090/http/p2p-webrtc-direct/p2p/12D3KooWSPCsVkHVyLQoCqhu2YRPvvM7o6r6NRYyLM5zeA6Uig5t"
],

View File

@ -0,0 +1,8 @@
#!/bin/sh
# Merging config files to get deployed contract address
jq -s '.[0] * .[1]' /app/src/mobymask-app-config.json /server/config.json > /app/src/config.json
npm run build
serve -s build

View File

@ -0,0 +1 @@
REACT_APP_WATCHER_URI=http://localhost:3001/graphql

View File

@ -0,0 +1,5 @@
{
"id": "12D3KooWK6myjc8r1KBnfP9igp31qJkPaVfsKDjKrjoSefV5SDEo",
"privKey": "CAESQJMHbMaH+UEOtjGOzXYtoPO/cdHakCtN1hcnknIWzx/6ie1lxb+8kfzBjwt7apfj8fHlTCYSIVK8Q2AWu9a2h3g=",
"pubKey": "CAESIIntZcW/vJH8wY8Le2qX4/Hx5UwmEiFSvENgFrvWtod4"
}

View File

@ -0,0 +1,10 @@
#!/bin/sh
# Private key of account with balance
PRIVATE_KEY=
# Assign deployed contract address from server config
CONTRACT_ADDRESS=`jq '.address' /server/config.json`
echo 'yarn peer-listener --contract-address <CONTRACT_ADDRESS> --private-key <PRIVATE_KEY>'
yarn peer-listener --contract-address $CONTRACT_ADDRESS --private-key $PRIVATE_KEY

View File

@ -0,0 +1,5 @@
{
"rpcUrl": "http://laconicd:8545",
"privateKey": "c7f31b8b2d5c760c895cbbe881390c78a9435eedb08011a3a23a4d4195a50d6d",
"baseURI": "http://127.0.0.1:3002/#"
}

View File

@ -31,7 +31,7 @@
enableDebugInfo = true
[server.p2p.peer]
relayMultiaddr = '/ip4/mobymask-watcher-server/tcp/9090/http/p2p-webrtc-direct/p2p/12D3KooWSPCsVkHVyLQoCqhu2YRPvvM7o6r6NRYyLM5zeA6Uig5t'
relayMultiaddr = '/dns/mobymask-watcher-server/tcp/9090/http/p2p-webrtc-direct/p2p/12D3KooWSPCsVkHVyLQoCqhu2YRPvvM7o6r6NRYyLM5zeA6Uig5t'
pubSubTopic = 'mobymask'
peerIdFile = './peer-id.json'
enableDebugInfo = true
@ -55,7 +55,7 @@
[upstream]
[upstream.ethServer]
gqlApiEndpoint = "http://ipld-eth-server:8083/graphql"
rpcProviderEndpoint = "http://ipld-eth-server:8082"
rpcProviderEndpoint = "http://laconicd:8545"
blockDelayInMilliSecs = 60000
[upstream.cache]

View File

@ -1,6 +1,6 @@
FROM node:18.15.0-alpine3.16
RUN apk --update --no-cache add make git
RUN apk --update --no-cache add make git jq
WORKDIR /app

View File

@ -0,0 +1,13 @@
FROM node:16.17.1-alpine3.16
RUN apk --update --no-cache add python3 alpine-sdk
WORKDIR /app
COPY . .
RUN yarn
# Add scripts
RUN mkdir /scripts
ENV PATH="${PATH}:/scripts"

View File

@ -0,0 +1,7 @@
#!/usr/bin/env bash
# Build cerc/mobymask
# See: https://stackoverflow.com/a/246128/1701505
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
docker build -t cerc/mobymask:local -f ${SCRIPT_DIR}/Dockerfile ${CERC_REPO_BASE_DIR}/MobyMask

View File

@ -4,7 +4,7 @@ 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 busybox \
&& apt-get install -y nodejs git busybox jq \
&& node -v
RUN corepack enable \

View File

@ -21,6 +21,7 @@ cerc/uniswap-v3-info
cerc/watcher-mobymask-v2
cerc/react-peer
cerc/mobymask-ui
cerc/mobymask
cerc/test-container
cerc/eth-probe
cerc/builder-js

View File

@ -15,6 +15,7 @@ watcher-erc20
watcher-erc721
watcher-uniswap-v3
watcher-mobymask-v2
mobymask-laconicd
test
eth-probe
keycloak

View File

@ -13,6 +13,7 @@ cerc-io/mobymask-watcher
cerc-io/watcher-ts
cerc-io/react-peer
cerc-io/mobymask-ui
cerc-io/MobyMask
vulcanize/uniswap-watcher-ts
vulcanize/uniswap-v3-info
vulcanize/assemblyscript

View File

@ -10,13 +10,21 @@ Clone required repositories:
laconic-so --stack mobymask-v2 setup-repositories
```
Checkout to the required branch in mobymask-ui
Checkout to the required branches in repos
```bash
cd ~/cerc/mobymask-ui
* mobymask-ui
```bash
cd ~/cerc/mobymask-ui
git checkout laconic
```
git checkout laconic
```
* MobyMask
```bash
cd ~/cerc/MobyMask
git checkout v0.1.1
```
Build the container images:
@ -28,25 +36,69 @@ This should create the required docker images in the local image registry.
Deploy the stack:
```bash
laconic-so --stack mobymask-v2 deploy-system up
```
* Deploy the laconic chain
```bash
laconic-so --stack mobymask-v2 deploy-system --include mobymask-laconicd up
```
* Check that laconic chain status is healthy
```bash
docker ps
```
* Export the private key from laconicd
```bash
laconic-so --stack mobymask-v2 deploy-system --include mobymask-laconicd exec laconicd "echo y | laconicd keys export mykey --unarmored-hex --unsafe"
```
* Set the private key in [secrets.json](../../config/watcher-mobymask-v2/secrets.json) file that will be used by mobymask container to deploy contract
* Create a new account
```bash
laconic-so --stack mobymask-v2 deploy-system --include mobymask-laconicd exec laconicd "laconicd keys add alice"
```
* Transfer balance to new account
```bash
laconic-so --stack mobymask-v2 deploy-system --include mobymask-laconicd exec laconicd 'laconicd tx bank send $(laconicd keys show mykey -a) $(laconicd keys show alice -a) 1000000000000000000000000aphoton --fees 2000aphoton'
```
* Export the private key of new account from laconicd
```bash
laconic-so --stack mobymask-v2 deploy-system --include mobymask-laconicd exec laconicd "echo y | laconicd keys export alice --unarmored-hex --unsafe"
```
* Set the private key (`PRIVATE_KEY`) in [peer-start.sh](../../config/watcher-mobymask-v2/peer-start.sh) file that will be used to start the peer that sends txs to L2 chain
* Deploy the other containers
```bash
laconic-so --stack mobymask-v2 deploy-system --include watcher-mobymask-v2 up
```
* Check that all containers are healthy using `docker ps`
## Tests
Find the watcher container's id:
```bash
docker ps | grep "cerc/watcher-mobymask-v2:local"
laconic-so --stack mobymask-v2 deploy-system --include watcher-mobymask-v2 ps | grep "mobymask-watcher-server"
```
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
id: 5d3aae4b22039fcd1c9b18feeb91318ede1100581e75bb5ac54f9e436066b02c, name: laconic-bfb01caf98b1b8f7c8db4d33f11b905a-mobymask-watcher-server-1, ports: 0.0.0.0:3001->3001/tcp, 0.0.0.0:9001->9001/tcp, 0.0.0.0:9090->9090/tcp
```
In above output the container ID is `8b38e9a64d7e`
In above output the container ID is `5d3aae4b22039fcd1c9b18feeb91318ede1100581e75bb5ac54f9e436066b02c`
Export it for later use:
@ -80,10 +132,31 @@ The peer-test-app should be running at http://localhost:3003
* The [react-peer package](https://github.com/cerc-io/react-peer/tree/main/packages/react-peer) (published in [gitea](https://git.vdb.to/cerc-io/-/packages/npm/@cerc-io%2Freact-peer)) which uses the peer package can be used in react app for connecting to the network
## Demo
<!-- TODO -->
## Clean up
To stop all the services running in background run:
Stop all the services running in background run:
```bash
laconic-so --stack mobymask-v2 deploy-system down
laconic-so --stack mobymask-v2 deploy-system --include watcher-mobymask-v2 down
laconic-so --stack mobymask-v2 deploy-system --include mobymask-laconicd down
```
Clear volumes:
* List all volumes
```bash
docker volume ls
```
* Remove volumes created by this stack
Example:
```bash
docker volume rm laconic-bfb01caf98b1b8f7c8db4d33f11b905a_moby_data_server
```

View File

@ -4,9 +4,14 @@ repos:
- cerc-io/watcher-ts
- cerc-io/react-peer
- cerc-io/mobymask-ui
- cerc-io/laconicd
- cerc-io/MobyMask
containers:
- cerc/watcher-mobymask-v2
- cerc/react-peer
- cerc/mobymask-ui
- cerc/laconicd
- cerc/mobymask
pods:
- mobymask-laconicd
- watcher-mobymask-v2