Add a container for web-app

This commit is contained in:
Prathamesh Musale 2023-09-18 15:50:23 +05:30
parent 96c7bcad43
commit 4ce471b4b1
7 changed files with 207 additions and 6 deletions

View File

@ -0,0 +1,38 @@
version: '3.2'
services:
# Builds and serves the MobyMask v3 react-app
mobymask-v3-app:
restart: unless-stopped
image: cerc/mobymask-ui:local
env_file:
- ../config/watcher-mobymask-v3/mobymask-params.env
environment:
CERC_SCRIPT_DEBUG: ${CERC_SCRIPT_DEBUG}
CERC_CHAIN_ID: ${CERC_CHAIN_ID}
CERC_DEPLOYED_CONTRACT: ${CERC_DEPLOYED_CONTRACT}
CERC_RELAY_NODES: ${CERC_RELAY_NODES}
CERC_DENY_MULTIADDRS: ${CERC_DENY_MULTIADDRS}
CERC_PUBSUB: ${CERC_PUBSUB}
CERC_RELEASE: "laconic-v3"
CERC_NA_ADDRESS: ${CERC_NA_ADDRESS}
CERC_VPA_ADDRESS: ${CERC_VPA_ADDRESS}
CERC_CA_ADDRESS: ${CERC_CA_ADDRESS}
CERC_APP_WATCHER_URL: ${CERC_APP_WATCHER_URL}
CERC_PAYMENT_NITRO_ADDRESS: ${CERC_PAYMENT_NITRO_ADDRESS}
CERC_SNAP_URL: ${CERC_SNAP_URL}
working_dir: /scripts
command: ["sh", "mobymask-app-start.sh"]
volumes:
- ../config/watcher-mobymask-v3/mobymask-app-start.sh:/scripts/mobymask-app-start.sh
- ../config/watcher-mobymask-v2/mobymask-app-config.json:/app/src/mobymask-app-config.json
ports:
- "127.0.0.1:3004:80"
healthcheck:
test: ["CMD", "nc", "-vz", "localhost", "80"]
interval: 20s
timeout: 5s
retries: 15
start_period: 10s
extra_hosts:
- "host.docker.internal:host-gateway"

View File

@ -0,0 +1,62 @@
#!/bin/bash
set -e
if [ -n "$CERC_SCRIPT_DEBUG" ]; then
set -x
fi
CERC_CHAIN_ID="${CERC_CHAIN_ID:-${DEFAULT_CERC_CHAIN_ID}}"
CERC_DEPLOYED_CONTRACT="${CERC_DEPLOYED_CONTRACT:-${DEFAULT_CERC_DEPLOYED_CONTRACT}}"
CERC_RELAY_NODES="${CERC_RELAY_NODES:-${DEFAULT_CERC_RELAY_NODES}}"
CERC_DENY_MULTIADDRS="${CERC_DENY_MULTIADDRS:-${DEFAULT_CERC_DENY_MULTIADDRS}}"
CERC_PUBSUB="${CERC_PUBSUB:-${DEFAULT_CERC_PUBSUB}}"
echo "Using CERC_RELAY_NODES $CERC_RELAY_NODES"
if [ -z "$CERC_DEPLOYED_CONTRACT" ]; then
echo "CERC_DEPLOYED_CONTRACT not set"
exit 1
else
echo "Using CERC_DEPLOYED_CONTRACT ${CERC_DEPLOYED_CONTRACT} from env as the MobyMask contract address"
fi
# Checkout to the required release/branch
cd /app
git checkout $CERC_RELEASE
# Check if CERC_NA_ADDRESS is set
if [ -n "$CERC_NA_ADDRESS" ]; then
echo "CERC_NA_ADDRESS is set to '$CERC_NA_ADDRESS'"
echo "CERC_VPA_ADDRESS is set to '$CERC_VPA_ADDRESS'"
echo "CERC_CA_ADDRESS is set to '$CERC_CA_ADDRESS'"
echo "Using the above Nitro addresses"
# Create the required JSON and write it to a file
nitro_addresses_json=$(jq -n \
--arg na "$CERC_NA_ADDRESS" \
--arg vpa "$CERC_VPA_ADDRESS" \
--arg ca "$CERC_CA_ADDRESS" \
'.nitroAdjudicatorAddress = $na | .virtualPaymentAppAddress = $vpa | .consensusAppAddress = $ca')
echo "$nitro_addresses_json" > /app/src/utils/nitro-addresses.json
else
echo "Nitro addresses not provided"
exit 1
fi
# Export config values in a json file
jq --arg address "$CERC_DEPLOYED_CONTRACT" \
--argjson chainId "$CERC_CHAIN_ID" \
--argjson relayNodes "$CERC_RELAY_NODES" \
--argjson denyMultiaddrs "$CERC_DENY_MULTIADDRS" \
--arg pubsub "$CERC_PUBSUB" \
'.address = $address | .chainId = $chainId | .relayNodes = $relayNodes | .peer.denyMultiaddrs = $denyMultiaddrs | .peer.pubsub = $pubsub' \
/app/src/mobymask-app-config.json > /app/src/utils/config.json
yarn install
REACT_APP_WATCHER_URI="$CERC_APP_WATCHER_URL/graphql" \
REACT_APP_PAY_TO_NITRO_ADDRESS="$CERC_PAYMENT_NITRO_ADDRESS" \
REACT_APP_SNAP_ORIGIN="local:$CERC_SNAP_URL" \
yarn build
http-server -p 80 /app/build

View File

@ -1,8 +1,5 @@
# Defaults
# Watcher endpoint
DEFAULT_CERC_APP_WATCHER_URL="http://localhost:3001"
# Set of relay peers to connect to from the relay node
DEFAULT_CERC_RELAY_PEERS=[]

View File

@ -1 +1,6 @@
# MobyMask v3 watcher
# MobyMask v3
Instructions to setup and deploy MobyMask v3 stack (watcher + web-app) using [laconic-stack-orchestrator](/README.md#install)
* Follow [watcher.md](./watcher.md) for deploying the watcher
* Follow [web-app.md](./web-app.md) for deploying the app

View File

@ -13,4 +13,4 @@ containers:
- cerc/mobymask-ui
pods:
- watcher-mobymask-v3
# - mobymask-app-v3
- mobymask-app-v3

View File

@ -1,7 +1,9 @@
# MobyMask v3 watcher
# MobyMask v3 Watcher
## Setup
Prerequisite: L2 Optimism Geth and Node RPC endpoints
Clone required repositories:
```bash

View File

@ -0,0 +1,97 @@
# MobyMask v3 App
## Setup
Prerequisite: Watcher with GQL and relay node endpoints
Clone required repositories:
```bash
laconic-so --stack mobymask-v3 setup-repositories --pull --include github.com/cerc-io/mobymask-ui
```
Build the container images:
```bash
laconic-so --stack mobymask-v3 build-containers --include cerc/mobymask-ui
```
## Deploy
### Configuration
Create and update an env file to be used in the next step ([defaults](../../config/watcher-mobymask-v3/mobymask-params.env)):
```bash
# Set of relay nodes to be used by the web-app
# (use double quotes " for strings, avoid space after commas)
# Eg. CERC_RELAY_NODES=["/dns4/example.com/tcp/443/wss/p2p/12D3KooWGHmDDCc93XUWL16FMcTPCGu2zFaMkf67k8HZ4gdQbRDr"]
CERC_RELAY_NODES=[]
# Set of multiaddrs to be avoided while dialling
CERC_DENY_MULTIADDRS=[]
# Also add if running MobyMask app:
# Watcher endpoint used by the app for GQL queries
CERC_APP_WATCHER_URL="http://127.0.0.1:3001"
# Set deployed MobyMask contract address to be used in MobyMask app's config
CERC_DEPLOYED_CONTRACT=
# L2 Chain ID used by mobymask web-app for L2 txs
CERC_CHAIN_ID=42069
# (Optional) Type of pubsub to be used ("floodsub" | "gossipsub")
CERC_PUBSUB=""
# Set Nitro addresses
CERC_NA_ADDRESS=
CERC_VPA_ADDRESS=
CERC_CA_ADDRESS=
# Nitro account address to make the query and mutation payments to
CERC_PAYMENT_NITRO_ADDRESS=
# Endpoint for Mobymask snap installation
CERC_SNAP_URL=
```
### Deploy the stack
```bash
laconic-so --stack mobymask-v3 deploy --cluster mobymask_v3 --include mobymask-app-v3 --env-file <PATH_TO_ENV_FILE> up
# Runs the MobyMask v3 app on host port 3004
```
To list down and monitor the running containers:
```bash
laconic-so --stack mobymask-v3 deploy --cluster mobymask_v3 --include mobymask-v3-app ps
# With status
docker ps -a
# Check logs for a container
docker logs -f <CONTAINER_ID>
```
## Clean up
Stop all services running in the background:
For mobymask-app
```bash
laconic-so --stack mobymask-v3 deploy --cluster mobymask_v3 --include mobymask-app-v3 down
```
Clear volumes created by this stack:
```bash
# List all relevant volumes
docker volume ls -q --filter "name=mobymask_v3"
# Remove all the listed volumes
docker volume rm $(docker volume ls -q --filter "name=mobymask_v3")
```