From 4ce471b4b14199bef7e5e321aee33d4d2c04c723 Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Mon, 18 Sep 2023 15:50:23 +0530 Subject: [PATCH] Add a container for web-app --- .../docker-compose-mobymask-app-v3.yml | 38 ++++++++ .../watcher-mobymask-v3/mobymask-app-start.sh | 62 ++++++++++++ .../watcher-mobymask-v3/mobymask-params.env | 3 - app/data/stacks/mobymask-v3/README.md | 7 +- app/data/stacks/mobymask-v3/stack.yml | 2 +- app/data/stacks/mobymask-v3/watcher.md | 4 +- app/data/stacks/mobymask-v3/web-app.md | 97 +++++++++++++++++++ 7 files changed, 207 insertions(+), 6 deletions(-) create mode 100644 app/data/compose/docker-compose-mobymask-app-v3.yml create mode 100644 app/data/config/watcher-mobymask-v3/mobymask-app-start.sh create mode 100644 app/data/stacks/mobymask-v3/web-app.md diff --git a/app/data/compose/docker-compose-mobymask-app-v3.yml b/app/data/compose/docker-compose-mobymask-app-v3.yml new file mode 100644 index 00000000..bc0973c8 --- /dev/null +++ b/app/data/compose/docker-compose-mobymask-app-v3.yml @@ -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" diff --git a/app/data/config/watcher-mobymask-v3/mobymask-app-start.sh b/app/data/config/watcher-mobymask-v3/mobymask-app-start.sh new file mode 100644 index 00000000..d7f87f19 --- /dev/null +++ b/app/data/config/watcher-mobymask-v3/mobymask-app-start.sh @@ -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 diff --git a/app/data/config/watcher-mobymask-v3/mobymask-params.env b/app/data/config/watcher-mobymask-v3/mobymask-params.env index a346baac..35a54b69 100644 --- a/app/data/config/watcher-mobymask-v3/mobymask-params.env +++ b/app/data/config/watcher-mobymask-v3/mobymask-params.env @@ -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=[] diff --git a/app/data/stacks/mobymask-v3/README.md b/app/data/stacks/mobymask-v3/README.md index 666f6bbf..6ea57af5 100644 --- a/app/data/stacks/mobymask-v3/README.md +++ b/app/data/stacks/mobymask-v3/README.md @@ -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 diff --git a/app/data/stacks/mobymask-v3/stack.yml b/app/data/stacks/mobymask-v3/stack.yml index 4f08ea7f..85af73ac 100644 --- a/app/data/stacks/mobymask-v3/stack.yml +++ b/app/data/stacks/mobymask-v3/stack.yml @@ -13,4 +13,4 @@ containers: - cerc/mobymask-ui pods: - watcher-mobymask-v3 - # - mobymask-app-v3 + - mobymask-app-v3 diff --git a/app/data/stacks/mobymask-v3/watcher.md b/app/data/stacks/mobymask-v3/watcher.md index 4fa7007c..5ff4dd62 100644 --- a/app/data/stacks/mobymask-v3/watcher.md +++ b/app/data/stacks/mobymask-v3/watcher.md @@ -1,7 +1,9 @@ -# MobyMask v3 watcher +# MobyMask v3 Watcher ## Setup +Prerequisite: L2 Optimism Geth and Node RPC endpoints + Clone required repositories: ```bash diff --git a/app/data/stacks/mobymask-v3/web-app.md b/app/data/stacks/mobymask-v3/web-app.md new file mode 100644 index 00000000..03ebd226 --- /dev/null +++ b/app/data/stacks/mobymask-v3/web-app.md @@ -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 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 +``` + +## 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") +```