From 5f451bec4f24eef3dd6288b2f067fefe7ef4cdb8 Mon Sep 17 00:00:00 2001 From: David Boreham Date: Wed, 5 Apr 2023 14:59:37 -0600 Subject: [PATCH 1/9] Copy of Zach's install script --- scripts/quick-install-ubuntu.sh | 70 +++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100755 scripts/quick-install-ubuntu.sh diff --git a/scripts/quick-install-ubuntu.sh b/scripts/quick-install-ubuntu.sh new file mode 100755 index 00000000..7221159a --- /dev/null +++ b/scripts/quick-install-ubuntu.sh @@ -0,0 +1,70 @@ +#!/usr/bin/env bash +set -euo pipefail ## https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/ + +install_dir=~/bin + +# This script assumes root permissions on a fresh Ubuntu Digital Ocean droplet +# with these recommended specs: 16 GB Memory / 8 Intel vCPUs / 320 GB Disk + +# dismiss the popups +export DEBIAN_FRONTEND=noninteractive + +## https://docs.docker.com/engine/install/ubuntu/ +sudo apt -y remove docker docker-engine docker.io containerd runc +sudo apt -y update -y && apt -y upgrade + +# laconic-so depends on jq +sudo apt -y install jq +# laconic-so depends on git +sudo apt -y install git +# curl used below +sudo apt -y install jq +# docker repo add depends on gnupg and updated ca-certificates +sudo apt -y install ca-certificates gnupg + +# Add dockerco package repository +sudo mkdir -m 0755 -p /etc/apt/keyrings +curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg +echo \ + "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \ + "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \ + sudo tee /etc/apt/sources.list.d/docker.list > /dev/null + +# Penny in the update jar +sudo apt -y update + +# Install docker +sudo apt -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin + +# Allow the current user to use Docker +sudo groupadd docker +sudo usermod -aG docker $USER + +# install latest `laconic-so` +install_filename=${install_dir}/laconic-so +mkdir -p ${install_dir} +curl -L -o ${install_filename} https://github.com/cerc-io/stack-orchestrator/releases/latest/download/laconic-so +chmod +x ${install_filename} + +# set here for this script +export PATH=$PATH:${install_dir} + +# added to profile, manually running `source ~/.profile` is then required +echo "Adding this to ~/.profile: export PATH=$PATH:${install_dir}" +echo "export PATH=$PATH:${install_dir}" >> ~/.profile + +# TODO: run this manually again after the script ends +# source ~/.profile + +# verify operation +laconic-so version + +echo "The Laconic Stack Orchestrator program has been installed at ${install_filename}" +echo "The directory ${install_dir} has been added to PATH in new shells via ~/.profile" +echo "Either open a new shell to use laconic-so on the PATH, or run this command in this shell:" +echo "export PATH=$PATH:${install_dir}" + +# Message the user to check docker is working for them +echo "Please test that docker installed correctly by running this command:" +echo "docker run hello-world" + -- 2.45.2 From b15c08b1f9760d5aa431229fab807c136261ab7c Mon Sep 17 00:00:00 2001 From: David Boreham Date: Wed, 5 Apr 2023 15:41:39 -0600 Subject: [PATCH 2/9] Few small fixes after testing on DO droplet --- scripts/quick-install-ubuntu.sh | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/scripts/quick-install-ubuntu.sh b/scripts/quick-install-ubuntu.sh index 7221159a..293b3f59 100755 --- a/scripts/quick-install-ubuntu.sh +++ b/scripts/quick-install-ubuntu.sh @@ -1,5 +1,7 @@ #!/usr/bin/env bash -set -euo pipefail ## https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/ +if [[ -n "$CERC_SCRIPT_DEBUG" ]]; then + set -x +fi install_dir=~/bin @@ -10,8 +12,22 @@ install_dir=~/bin export DEBIAN_FRONTEND=noninteractive ## https://docs.docker.com/engine/install/ubuntu/ -sudo apt -y remove docker docker-engine docker.io containerd runc -sudo apt -y update -y && apt -y upgrade +## https://superuser.com/questions/518859/ignore-packages-that-are-not-currently-installed-when-using-apt-get-remove1 +packages_to_remove="docker docker-engine docker.io containerd runc" +installed_packages_to_remove="" +for package_to_remove in $(echo $packages_to_remove); do + $(dpkg --info $package_to_remove &> /dev/null) + if [[ $? -eq 0 ]]; then + installed_packages_to_remove="$installed_packages_to_remove $package_to_remove" + fi +done + +# Enable stop on error now, since we needed it off for the code above +set -euo pipefail ## https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/ + +sudo apt -y remove $installed_packages_to_remove + +sudo apt -y update # laconic-so depends on jq sudo apt -y install jq @@ -37,7 +53,6 @@ sudo apt -y update sudo apt -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin # Allow the current user to use Docker -sudo groupadd docker sudo usermod -aG docker $USER # install latest `laconic-so` -- 2.45.2 From ab4b66060eace34f7da5fe756b318bd27a09fac7 Mon Sep 17 00:00:00 2001 From: David Boreham Date: Wed, 5 Apr 2023 21:23:42 -0600 Subject: [PATCH 3/9] Update scripts --- scripts/first_time_setup.sh | 11 ++++-- scripts/quick-install-ubuntu.sh | 65 ++++++++++++++++++++++++--------- 2 files changed, 55 insertions(+), 21 deletions(-) diff --git a/scripts/first_time_setup.sh b/scripts/first_time_setup.sh index e8900ce7..997c6173 100755 --- a/scripts/first_time_setup.sh +++ b/scripts/first_time_setup.sh @@ -1,8 +1,11 @@ -#!/bin/bash - +#!/usr/bin/env bash +# Script to automate the steps needed to make a cloned project repo runnable on the path +# (beware of PATH having some other file with the same name ahead of ours) +if [[ -n "$CERC_SCRIPT_DEBUG" ]]; then + set -x + echo PATH is $PATH +fi python3 -m venv venv source ./venv/bin/activate pip install --editable . pip install shiv -shiv -c laconic-so -o laconic-so . -./laconic-so --verbose --local-stack setup-repositories diff --git a/scripts/quick-install-ubuntu.sh b/scripts/quick-install-ubuntu.sh index 293b3f59..c317bdb7 100755 --- a/scripts/quick-install-ubuntu.sh +++ b/scripts/quick-install-ubuntu.sh @@ -5,9 +5,29 @@ fi install_dir=~/bin +# First display a reasonable warning to the user unless run with -y +if ! [[ $# -eq 1 && $1 == "-y" ]]; then + echo "**************************************************************************************" + echo "This script installs Laconic Stack Orchestrator into: ${install_dir}" + echo "It also *removes* any existing docker installed on this machine then installs" + echo "the latest docker release as well as other required packages." + echo "Only proceed if you are sure you want to make those changes to this machine." + echo "**************************************************************************************" + read -p "Are you sure you want to proceed? " -n 1 -r + echo + if [[ ! $REPLY =~ ^[Yy]$ ]] + then + exit 1 + fi +fi + # This script assumes root permissions on a fresh Ubuntu Digital Ocean droplet # with these recommended specs: 16 GB Memory / 8 Intel vCPUs / 320 GB Disk +# TODO: +# Check python3 is available +# Check machine resources are sufficient + # dismiss the popups export DEBIAN_FRONTEND=noninteractive @@ -25,8 +45,12 @@ done # Enable stop on error now, since we needed it off for the code above set -euo pipefail ## https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/ +echo "**************************************************************************************" +echo "Removing existing docker packages" sudo apt -y remove $installed_packages_to_remove +echo "**************************************************************************************" +echo "Installing dependencies" sudo apt -y update # laconic-so depends on jq @@ -49,37 +73,44 @@ echo \ # Penny in the update jar sudo apt -y update -# Install docker +echo "**************************************************************************************" +echo "Installing docker sudo apt -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin # Allow the current user to use Docker sudo usermod -aG docker $USER +echo "**************************************************************************************" +echo "Installing laconic-so # install latest `laconic-so` install_filename=${install_dir}/laconic-so mkdir -p ${install_dir} curl -L -o ${install_filename} https://github.com/cerc-io/stack-orchestrator/releases/latest/download/laconic-so chmod +x ${install_filename} -# set here for this script +echo "**************************************************************************************" +# Check if our PATH line is already there +path_add_command="export PATH=\$PATH:${install_dir}" +if ! grep -q "${path_add_command}" ~/.profile +then + echo "Adding this line to the end of ~/.profile:" + echo ${path_add_command} + echo ${path_add_command} >> ~/.profile +fi + +# PATH set here for commands run in this script export PATH=$PATH:${install_dir} +echo Installed laconic-so version: $(laconic-so version) -# added to profile, manually running `source ~/.profile` is then required -echo "Adding this to ~/.profile: export PATH=$PATH:${install_dir}" -echo "export PATH=$PATH:${install_dir}" >> ~/.profile - -# TODO: run this manually again after the script ends -# source ~/.profile - -# verify operation -laconic-so version - -echo "The Laconic Stack Orchestrator program has been installed at ${install_filename}" +echo "**************************************************************************************" +echo "The Laconic Stack Orchestrator program laconic-so has been installed at ${install_filename}" echo "The directory ${install_dir} has been added to PATH in new shells via ~/.profile" echo "Either open a new shell to use laconic-so on the PATH, or run this command in this shell:" -echo "export PATH=$PATH:${install_dir}" - +echo "export PATH=\$PATH:${install_dir}" +echo "**************************************************************************************" # Message the user to check docker is working for them -echo "Please test that docker installed correctly by running this command:" +echo "Please test that docker is correctly installed and working for your user by running the" +echo "command below (it should print a message beginning \"Hello from Docker!\"):" +echo echo "docker run hello-world" - +echo -- 2.45.2 From 56a62026a6527e5480d69421eab25d7c649e6c7c Mon Sep 17 00:00:00 2001 From: David Boreham Date: Wed, 5 Apr 2023 21:24:14 -0600 Subject: [PATCH 4/9] Rename script --- scripts/{first_time_setup.sh => developer-mode-setup.sh} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename scripts/{first_time_setup.sh => developer-mode-setup.sh} (100%) diff --git a/scripts/first_time_setup.sh b/scripts/developer-mode-setup.sh similarity index 100% rename from scripts/first_time_setup.sh rename to scripts/developer-mode-setup.sh -- 2.45.2 From 3ff51b52ffef508556c7e8dc0a1c2495dc170d22 Mon Sep 17 00:00:00 2001 From: David Boreham Date: Wed, 5 Apr 2023 21:30:38 -0600 Subject: [PATCH 5/9] Add sudo notice --- scripts/quick-install-ubuntu.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/quick-install-ubuntu.sh b/scripts/quick-install-ubuntu.sh index c317bdb7..393469ac 100755 --- a/scripts/quick-install-ubuntu.sh +++ b/scripts/quick-install-ubuntu.sh @@ -8,15 +8,15 @@ install_dir=~/bin # First display a reasonable warning to the user unless run with -y if ! [[ $# -eq 1 && $1 == "-y" ]]; then echo "**************************************************************************************" - echo "This script installs Laconic Stack Orchestrator into: ${install_dir}" - echo "It also *removes* any existing docker installed on this machine then installs" - echo "the latest docker release as well as other required packages." + echo "This script requires sudo privilege. It installs Laconic Stack Orchestrator" + echo "into: ${install_dir}. It also *removes* any existing docker installed on" + echo "this machine and then installs the latest docker release as well as other" + echo "required packages." echo "Only proceed if you are sure you want to make those changes to this machine." echo "**************************************************************************************" read -p "Are you sure you want to proceed? " -n 1 -r echo - if [[ ! $REPLY =~ ^[Yy]$ ]] - then + if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1 fi fi -- 2.45.2 From 6f781ae303915d7612fbc670b4f5f9b521b48121 Mon Sep 17 00:00:00 2001 From: Nabarun Gogoi Date: Thu, 6 Apr 2023 15:17:00 +0530 Subject: [PATCH 6/9] Separate out watcher and web-apps in mobymask-v2 stack (#287) * Separate out watcher and web-apps in mobymask stack * Take L2 RPC endpoint from the env file * Changes to run watcher and mobymask web-app separately * Support running watcher without contract deployment and L2 txs * Remove duplicate mobymask params env * Add code comments * Add instructions for running web-apps separately * Self review fixes * Fix timeout for mobymask-app on watcher server --------- Co-authored-by: prathamesh0 --- .../compose/docker-compose-mobymask-app.yml | 31 +++++++ .../compose/docker-compose-peer-test-app.yml | 21 +++++ .../docker-compose-watcher-mobymask-v2.yml | 50 ++-------- .../deploy-and-generate-invite.sh | 18 +++- .../mobymask-app-config.json | 1 + .../watcher-mobymask-v2/mobymask-app-start.sh | 19 +++- .../watcher-mobymask-v2/mobymask-app.env | 1 - .../watcher-mobymask-v2/mobymask-params.env | 14 +++ .../watcher-mobymask-v2/optimism-params.env | 3 +- .../watcher-mobymask-v2/start-server.sh | 28 ++++-- .../watcher-mobymask-v2/test-app-start.sh | 14 +++ .../watcher-config-template.toml | 6 +- .../cerc-mobymask-ui/Dockerfile | 2 +- .../cerc-react-peer/Dockerfile | 2 +- app/data/stacks/mobymask-v2/mobymask-only.md | 27 +++--- app/data/stacks/mobymask-v2/stack.yml | 2 + app/data/stacks/mobymask-v2/web-apps.md | 91 +++++++++++++++++++ 17 files changed, 250 insertions(+), 80 deletions(-) create mode 100644 app/data/compose/docker-compose-mobymask-app.yml create mode 100644 app/data/compose/docker-compose-peer-test-app.yml delete mode 100644 app/data/config/watcher-mobymask-v2/mobymask-app.env create mode 100644 app/data/config/watcher-mobymask-v2/mobymask-params.env create mode 100755 app/data/config/watcher-mobymask-v2/test-app-start.sh create mode 100644 app/data/stacks/mobymask-v2/web-apps.md diff --git a/app/data/compose/docker-compose-mobymask-app.yml b/app/data/compose/docker-compose-mobymask-app.yml new file mode 100644 index 00000000..db95eeac --- /dev/null +++ b/app/data/compose/docker-compose-mobymask-app.yml @@ -0,0 +1,31 @@ +version: '3.2' + +services: + # Builds and serves the MobyMask react-app + mobymask-app: + image: cerc/mobymask-ui:local + env_file: + - ../config/watcher-mobymask-v2/mobymask-params.env + # Waits for watcher server to be up before app build + # Required when running with watcher stack to get deployed contract address + command: + - sh + - -c + - ./wait-for-it.sh -h $${WATCHER_HOST} -p $${WATCHER_PORT} -s -t 0 -- ./mobymask-app-start.sh + volumes: + - ../config/wait-for-it.sh:/app/wait-for-it.sh + - ../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 + - mobymask_deployment:/server + ports: + - "0.0.0.0:3002:3000" + healthcheck: + test: ["CMD", "nc", "-v", "localhost", "3000"] + interval: 20s + timeout: 5s + retries: 15 + start_period: 10s + shm_size: '1GB' + +volumes: + mobymask_deployment: diff --git a/app/data/compose/docker-compose-peer-test-app.yml b/app/data/compose/docker-compose-peer-test-app.yml new file mode 100644 index 00000000..3ddbd308 --- /dev/null +++ b/app/data/compose/docker-compose-peer-test-app.yml @@ -0,0 +1,21 @@ +version: '3.2' + +services: + peer-test-app: + # Builds and serves the peer-test react-app + image: cerc/react-peer:local + working_dir: /app/packages/test-app + env_file: + - ../config/watcher-mobymask-v2/mobymask-params.env + command: ["sh", "./test-app-start.sh"] + volumes: + - ../config/watcher-mobymask-v2/test-app-config.json:/app/packages/test-app/src/test-app-config.json + - ../config/watcher-mobymask-v2/test-app-start.sh:/app/packages/test-app/test-app-start.sh + ports: + - "0.0.0.0:3003:3000" + healthcheck: + test: ["CMD", "nc", "-v", "localhost", "3000"] + interval: 20s + timeout: 5s + retries: 15 + start_period: 10s diff --git a/app/data/compose/docker-compose-watcher-mobymask-v2.yml b/app/data/compose/docker-compose-watcher-mobymask-v2.yml index fd68212a..2e014471 100644 --- a/app/data/compose/docker-compose-watcher-mobymask-v2.yml +++ b/app/data/compose/docker-compose-watcher-mobymask-v2.yml @@ -1,6 +1,7 @@ version: '3.2' services: + # Starts the PostgreSQL database for watcher mobymask-watcher-db: restart: unless-stopped image: postgres:14-alpine @@ -21,13 +22,17 @@ services: retries: 15 start_period: 10s + # Deploys MobyMask contract and generates an invite link + # Deployment is skipped if DEPLOYED_CONTRACT env is already set mobymask: image: cerc/mobymask:local working_dir: /app/packages/server env_file: - ../config/watcher-mobymask-v2/optimism-params.env + - ../config/watcher-mobymask-v2/mobymask-params.env environment: - ENV=PROD + # Waits for L2 Optimism Geth and Node servers to be up before deploying contract command: - sh - -c @@ -44,6 +49,7 @@ services: extra_hosts: - "host.docker.internal:host-gateway" + # Starts the mobymask-v2-watcher server mobymask-watcher-server: restart: unless-stopped depends_on: @@ -54,6 +60,7 @@ services: image: cerc/watcher-mobymask-v2:local env_file: - ../config/watcher-mobymask-v2/optimism-params.env + - ../config/watcher-mobymask-v2/mobymask-params.env command: ["sh", "start-server.sh"] volumes: - ../config/watcher-mobymask-v2/watcher-config-template.toml:/app/packages/mobymask-v2-watcher/environments/watcher-config-template.toml @@ -63,6 +70,7 @@ services: - ../config/watcher-mobymask-v2/start-server.sh:/app/packages/mobymask-v2-watcher/start-server.sh - mobymask_deployment:/server - fixturenet_geth_accounts:/geth-accounts:ro + # Expose GQL, metrics and relay node ports ports: - "0.0.0.0:3001:3001" - "0.0.0.0:9001:9001" @@ -76,48 +84,6 @@ services: extra_hosts: - "host.docker.internal:host-gateway" - # TODO: Move to a separate pod - mobymask-app: - depends_on: - mobymask-watcher-server: - condition: service_healthy - mobymask: - condition: service_completed_successfully - image: cerc/mobymask-ui:local - command: ["sh", "mobymask-app-start.sh"] - volumes: - - ../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 - - mobymask_deployment:/server - ports: - - "0.0.0.0:3002:3000" - healthcheck: - test: ["CMD", "nc", "-v", "localhost", "3000"] - interval: 20s - timeout: 5s - retries: 15 - start_period: 10s - shm_size: '1GB' - - peer-test-app: - depends_on: - mobymask-watcher-server: - condition: service_healthy - image: cerc/react-peer:local - working_dir: /app/packages/test-app - command: ["sh", "-c", "yarn build && serve -s build"] - volumes: - - ../config/watcher-mobymask-v2/test-app-config.json:/app/packages/test-app/src/config.json - ports: - - "0.0.0.0:3003:3000" - healthcheck: - test: ["CMD", "nc", "-v", "localhost", "3000"] - interval: 20s - timeout: 5s - retries: 15 - start_period: 10s - volumes: mobymask_watcher_db_data: mobymask_deployment: diff --git a/app/data/config/watcher-mobymask-v2/deploy-and-generate-invite.sh b/app/data/config/watcher-mobymask-v2/deploy-and-generate-invite.sh index 2a3000ee..743b1525 100755 --- a/app/data/config/watcher-mobymask-v2/deploy-and-generate-invite.sh +++ b/app/data/config/watcher-mobymask-v2/deploy-and-generate-invite.sh @@ -4,6 +4,8 @@ if [ -n "$CERC_SCRIPT_DEBUG" ]; then set -x fi +echo "Using L2 RPC endpoint ${L2_GETH_RPC}" + if [ -f /geth-accounts/accounts.csv ]; then echo "Using L1 private key from the mounted volume" # Read the private key of L1 account to deploy contract @@ -16,10 +18,16 @@ fi jq --arg privateKey "$PRIVATE_KEY_DEPLOYER" '.privateKey = $privateKey' secrets-template.json > secrets.json # Set the RPC URL -export L2_GETH_URL="http://${L2_GETH_HOST}:${L2_GETH_PORT}" -jq --arg rpcUrl "$L2_GETH_URL" '.rpcUrl = $rpcUrl' secrets.json > secrets_updated.json && mv secrets_updated.json secrets.json +jq --arg rpcUrl "$L2_GETH_RPC" '.rpcUrl = $rpcUrl' secrets.json > secrets_updated.json && mv secrets_updated.json secrets.json -export RPC_URL="${L2_GETH_URL}" +export RPC_URL="${L2_GETH_RPC}" + +# Check if DEPLOYED_CONTRACT environment variable set to skip contract deployment +if [[ -n "$DEPLOYED_CONTRACT" ]]; then + echo "DEPLOYED_CONTRACT is set to '$DEPLOYED_CONTRACT'" + echo "Exiting without deploying contract" + exit 0 +fi # Check and exit if a deployment already exists (on restarts) if [ -f ./config.json ]; then @@ -39,10 +47,10 @@ if [ -f ./config.json ]; then fi fi -# Wait until balance for deployer account is reflected +# Wait until balance for deployer account is updated cd ../hardhat while true; do - ACCOUNT_BALANCE=$(yarn balance --network optimism $PRIVATE_KEY_DEPLOYER | grep ETH) + ACCOUNT_BALANCE=$(yarn balance --network optimism "$PRIVATE_KEY_DEPLOYER" | grep ETH) if [ "$ACCOUNT_BALANCE" != "0.0 ETH" ]; then echo "Account balance updated: $ACCOUNT_BALANCE" diff --git a/app/data/config/watcher-mobymask-v2/mobymask-app-config.json b/app/data/config/watcher-mobymask-v2/mobymask-app-config.json index 3b00674f..2ccb816d 100644 --- a/app/data/config/watcher-mobymask-v2/mobymask-app-config.json +++ b/app/data/config/watcher-mobymask-v2/mobymask-app-config.json @@ -1,4 +1,5 @@ { + "name": "MobyMask", "relayNodes": [ "/ip4/127.0.0.1/tcp/9090/ws/p2p/12D3KooWSPCsVkHVyLQoCqhu2YRPvvM7o6r6NRYyLM5zeA6Uig5t" ], diff --git a/app/data/config/watcher-mobymask-v2/mobymask-app-start.sh b/app/data/config/watcher-mobymask-v2/mobymask-app-start.sh index efc4ed96..680e2e8a 100755 --- a/app/data/config/watcher-mobymask-v2/mobymask-app-start.sh +++ b/app/data/config/watcher-mobymask-v2/mobymask-app-start.sh @@ -4,9 +4,22 @@ if [ -n "$CERC_SCRIPT_DEBUG" ]; then set -x fi -# 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 +# Use config from mounted volume if available (when running web-app along with watcher stack) +if [ -f /server/config.json ]; then + echo "Merging config for deployed contract from mounted volume" + # 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 +else + echo "Setting deployed contract details from env" -npm run build + # Set config values from environment variables + jq --arg address "$DEPLOYED_CONTRACT" \ + --argjson chainId $CHAIN_ID \ + --argjson relayNodes "$RELAY_NODES" \ + '.address = $address | .chainId = $chainId | .relayNodes = $relayNodes' \ + /app/src/mobymask-app-config.json > /app/src/config.json +fi + +REACT_APP_WATCHER_URI="$APP_WATCHER_URL/graphql" npm run build serve -s build diff --git a/app/data/config/watcher-mobymask-v2/mobymask-app.env b/app/data/config/watcher-mobymask-v2/mobymask-app.env deleted file mode 100644 index 698d3502..00000000 --- a/app/data/config/watcher-mobymask-v2/mobymask-app.env +++ /dev/null @@ -1 +0,0 @@ -REACT_APP_WATCHER_URI=http://localhost:3001/graphql diff --git a/app/data/config/watcher-mobymask-v2/mobymask-params.env b/app/data/config/watcher-mobymask-v2/mobymask-params.env new file mode 100644 index 00000000..890c183b --- /dev/null +++ b/app/data/config/watcher-mobymask-v2/mobymask-params.env @@ -0,0 +1,14 @@ +# Change if pointing web app to external watcher endpoint +WATCHER_HOST="mobymask-watcher-server" +WATCHER_PORT=3001 +APP_WATCHER_URL="http://localhost:3001" + +# Set deployed MobyMask contract address to avoid deploying contract in stack +# mobymask-app will use this contract address in config if run separately +DEPLOYED_CONTRACT= + +# Chain ID is used by mobymask web-app for txs +CHAIN_ID=42069 + +# Set relay nodes to be used by web-apps +RELAY_NODES=["/ip4/127.0.0.1/tcp/9090/ws/p2p/12D3KooWSPCsVkHVyLQoCqhu2YRPvvM7o6r6NRYyLM5zeA6Uig5t"] diff --git a/app/data/config/watcher-mobymask-v2/optimism-params.env b/app/data/config/watcher-mobymask-v2/optimism-params.env index bafb37a8..489dd879 100644 --- a/app/data/config/watcher-mobymask-v2/optimism-params.env +++ b/app/data/config/watcher-mobymask-v2/optimism-params.env @@ -1,9 +1,10 @@ # Change if pointing to an external optimism geth endpoint # L2 endpoints -# TODO: Add another env for complete URL to handle https +L2_GETH_RPC="http://op-geth:8545" L2_GETH_HOST="op-geth" L2_GETH_PORT=8545 + L2_NODE_HOST="op-node" L2_NODE_PORT=8547 diff --git a/app/data/config/watcher-mobymask-v2/start-server.sh b/app/data/config/watcher-mobymask-v2/start-server.sh index 5fe9ab84..4030e522 100755 --- a/app/data/config/watcher-mobymask-v2/start-server.sh +++ b/app/data/config/watcher-mobymask-v2/start-server.sh @@ -4,8 +4,15 @@ if [ -n "$CERC_SCRIPT_DEBUG" ]; then set -x fi -# Assign deployed contract address from server config -CONTRACT_ADDRESS=$(jq -r '.address' /server/config.json | tr -d '"') +echo "Using L2 RPC endpoint ${L2_GETH_RPC}" + +# Use contract address from environment variable or set from config.json in mounted volume +if [ -n "$DEPLOYED_CONTRACT" ]; then + CONTRACT_ADDRESS="${DEPLOYED_CONTRACT}" +else + # Assign deployed contract address from server config (created by mobymask container after deploying contract) + CONTRACT_ADDRESS=$(jq -r '.address' /server/config.json | tr -d '"') +fi if [ -f /geth-accounts/accounts.csv ]; then echo "Using L1 private key from the mounted volume" @@ -15,11 +22,20 @@ else echo "Using PRIVATE_KEY_PEER from env" fi -sed "s/REPLACE_WITH_PRIVATE_KEY/${PRIVATE_KEY_PEER}/" environments/watcher-config-template.toml > environments/local.toml -sed -i "s/REPLACE_WITH_CONTRACT_ADDRESS/${CONTRACT_ADDRESS}/" environments/local.toml +# Set private key and contract address for watcher peer txs to L2 only if PRIVATE_KEY_PEER variable is set +if [ -n "$PRIVATE_KEY_PEER" ]; then + # Read in config template TOML file and modify it + CONTENT=$(cat environments/watcher-config-template.toml) + NEW_CONTENT=$(echo "$CONTENT" | sed -E "/\[metrics\]/i \\\n\n [server.p2p.peer.l2TxConfig]\n privateKey = \"${PRIVATE_KEY_PEER}\"\n contractAddress = \"${CONTRACT_ADDRESS}\"\n") -export L2_GETH_URL="http://${L2_GETH_HOST}:${L2_GETH_PORT}" -sed -i 's|REPLACE_WITH_L2_GETH_URL|'"${L2_GETH_URL}"'|' environments/local.toml + # Write the modified content to a watcher config file + echo "$NEW_CONTENT" > environments/local.toml + + sed -i 's|REPLACE_WITH_L2_GETH_RPC_ENDPOINT|'"${L2_GETH_RPC}"'|' environments/local.toml +else + # Copy template config to watcher config without setting params for peer L2 txs + cp environments/watcher-config-template.toml environments/local.toml +fi echo 'yarn server' yarn server diff --git a/app/data/config/watcher-mobymask-v2/test-app-start.sh b/app/data/config/watcher-mobymask-v2/test-app-start.sh new file mode 100755 index 00000000..de6ccc7c --- /dev/null +++ b/app/data/config/watcher-mobymask-v2/test-app-start.sh @@ -0,0 +1,14 @@ +#!/bin/sh +set -e +if [ -n "$CERC_SCRIPT_DEBUG" ]; then + set -x +fi + +# Set relay nodes in config from RELAY_NODES environment variable +jq --argjson relayNodes "$RELAY_NODES" \ + '.relayNodes = $relayNodes' \ + ./src/test-app-config.json > ./src/config.json + +yarn build + +serve -s build diff --git a/app/data/config/watcher-mobymask-v2/watcher-config-template.toml b/app/data/config/watcher-mobymask-v2/watcher-config-template.toml index 05554e3a..6b0223c7 100644 --- a/app/data/config/watcher-mobymask-v2/watcher-config-template.toml +++ b/app/data/config/watcher-mobymask-v2/watcher-config-template.toml @@ -36,10 +36,6 @@ peerIdFile = './peer-id.json' enableDebugInfo = true - [server.p2p.peer.l2TxConfig] - privateKey = 'REPLACE_WITH_PRIVATE_KEY' - contractAddress = 'REPLACE_WITH_CONTRACT_ADDRESS' - [metrics] host = "0.0.0.0" port = 9000 @@ -59,7 +55,7 @@ [upstream] [upstream.ethServer] gqlApiEndpoint = "http://ipld-eth-server:8083/graphql" - rpcProviderEndpoint = "REPLACE_WITH_L2_GETH_URL" + rpcProviderEndpoint = "REPLACE_WITH_L2_GETH_RPC_ENDPOINT" blockDelayInMilliSecs = 60000 [upstream.cache] diff --git a/app/data/container-build/cerc-mobymask-ui/Dockerfile b/app/data/container-build/cerc-mobymask-ui/Dockerfile index 68e3c77c..c04b001d 100644 --- a/app/data/container-build/cerc-mobymask-ui/Dockerfile +++ b/app/data/container-build/cerc-mobymask-ui/Dockerfile @@ -1,6 +1,6 @@ FROM node:18.15.0-alpine3.16 -RUN apk --update --no-cache add make git jq +RUN apk --update --no-cache add make git jq bash WORKDIR /app diff --git a/app/data/container-build/cerc-react-peer/Dockerfile b/app/data/container-build/cerc-react-peer/Dockerfile index cc852441..fcc198f3 100644 --- a/app/data/container-build/cerc-react-peer/Dockerfile +++ b/app/data/container-build/cerc-react-peer/Dockerfile @@ -1,6 +1,6 @@ FROM node:18.15.0-alpine3.16 -RUN apk --update --no-cache add make git python3 +RUN apk --update --no-cache add make git python3 jq WORKDIR /app diff --git a/app/data/stacks/mobymask-v2/mobymask-only.md b/app/data/stacks/mobymask-v2/mobymask-only.md index 69c2007b..246d9000 100644 --- a/app/data/stacks/mobymask-v2/mobymask-only.md +++ b/app/data/stacks/mobymask-v2/mobymask-only.md @@ -4,30 +4,21 @@ Instructions to setup and deploy MobyMask v2 watcher independently ## Setup -Prerequisite: An L2 Optimism RPC endpoint +Prerequisite: L2 Optimism Geth and Node RPC endpoints Clone required repositories: ```bash -laconic-so --stack mobymask-v2 setup-repositories --include cerc-io/MobyMask,cerc-io/watcher-ts,cerc-io/react-peer,cerc-io/mobymask-ui +laconic-so --stack mobymask-v2 setup-repositories --include cerc-io/MobyMask,cerc-io/watcher-ts ``` Checkout to the required versions and branches in repos: -```bash ```bash # watcher-ts cd ~/cerc/watcher-ts git checkout v0.2.34 -# react-peer -cd ~/cerc/react-peer -git checkout v0.2.31 - -# mobymask-ui -cd ~/cerc/mobymask-ui -git checkout laconic - # MobyMask cd ~/cerc/MobyMask git checkout v0.1.2 @@ -36,20 +27,24 @@ git checkout v0.1.2 Build the container images: ```bash -laconic-so --stack mobymask-v2 build-containers --include cerc/watcher-mobymask-v2,cerc/react-peer,cerc/mobymask-ui,cerc/mobymask +laconic-so --stack mobymask-v2 build-containers --include cerc/watcher-mobymask-v2,cerc/mobymask ``` This should create the required docker images in the local image registry ## Deploy -Update the [optimism-params.env](../../config/watcher-mobymask-v2/optimism-params.env) file with Optimism endpoints and other params if running Optimism separately +### Configuration +* In [mobymask-params.env](../../config/watcher-mobymask-v2/mobymask-params.env) file set `DEPLOYED_CONTRACT` to existing deployed mobymask contract address + * Setting `DEPLOYED_CONTRACT` will skip contract deployment when running stack +* Update the [optimism-params.env](../../config/watcher-mobymask-v2/optimism-params.env) file with Optimism endpoints and other params for the Optimism running separately + * If `PRIVATE_KEY_PEER` is not set the inline watcher peer will not send txs to L2 on receiving P2P network messages * NOTE: * Stack Orchestrator needs to be run in [`dev`](/docs/CONTRIBUTING.md#install-developer-mode) mode to be able to edit the env file * If Optimism is running on the host machine, use `host.docker.internal` as the hostname to access the host port -Deploy the stack: +### Deploy the stack ```bash laconic-so --stack mobymask-v2 deploy --include watcher-mobymask-v2 up @@ -67,7 +62,9 @@ docker ps docker logs -f ``` -See [Tests](./README.md#tests) and [Demo](./README.md#demo) to interact with stack +## Tests + +See [Tests](./README.md#tests) ## Clean up diff --git a/app/data/stacks/mobymask-v2/stack.yml b/app/data/stacks/mobymask-v2/stack.yml index cdcbd663..248351b1 100644 --- a/app/data/stacks/mobymask-v2/stack.yml +++ b/app/data/stacks/mobymask-v2/stack.yml @@ -27,3 +27,5 @@ pods: - fixturenet-eth - fixturenet-optimism - watcher-mobymask-v2 + - mobymask-app + - peer-test-app diff --git a/app/data/stacks/mobymask-v2/web-apps.md b/app/data/stacks/mobymask-v2/web-apps.md new file mode 100644 index 00000000..052a7cb7 --- /dev/null +++ b/app/data/stacks/mobymask-v2/web-apps.md @@ -0,0 +1,91 @@ +# Web Apps + +Instructions to setup and deploy MobyMask and Peer Test web apps + +## Setup + +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 +``` + +Checkout to the required versions and branches in repos: + +```bash +# react-peer +cd ~/cerc/react-peer +git checkout v0.2.31 + +# mobymask-ui +cd ~/cerc/mobymask-ui +git checkout laconic +``` + +Build the container images: + +```bash +laconic-so --stack mobymask-v2 build-containers --include cerc/react-peer-v2,cerc/mobymask-ui +``` + +This should create the required docker images in the local image registry + +## Deploy + +### Configuration + +* Update the [mobymask-params.env](../../config/watcher-mobymask-v2/mobymask-params.env) file with watcher endpoints and other params required by the web-apps + * `WATCHER_HOST` and `WATCHER_PORT` is used to check if watcher is up before building and deploying mobymask-app + * `APP_WATCHER_URL` is used by mobymask-app to make GQL queries + * `DEPLOYED_CONTRACT` and `CHAIN_ID` is used by mobymask-app in app config when creating messgaes for L2 txs + * `RELAY_NODES` is used by the web-apps to connect to the relay nodes (run in watcher) +* NOTE: + * Stack Orchestrator needs to be run in [`dev`](/docs/CONTRIBUTING.md#install-developer-mode) mode to be able to edit the env file + * If watcher is running on the host machine, use `host.docker.internal` as the hostname to access the host port + +### Deploy the stack + +For running mobymask-app +```bash +laconic-so --stack mobymask-v2 deploy --include mobymask-app up +``` + +For running peer-test-app +```bash +laconic-so --stack mobymask-v2 deploy --include peer-test-app up +``` + +To list down and monitor the running containers: + +```bash +docker ps + +# 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-v2 deploy --include mobymask-app down +``` + +For peer-test-app +```bash +laconic-so --stack mobymask-v2 deploy --include peer-test-app down +``` + +Clear volumes created by this stack: + +```bash +# List all relevant volumes +docker volume ls -q --filter "name=.*mobymask_deployment" + +# Remove all the listed volumes +docker volume rm $(docker volume ls -q --filter "name=.*mobymask_deployment") +``` -- 2.45.2 From df57e89f75d9ea71ca6b9b3e90e82646ffe5ebd5 Mon Sep 17 00:00:00 2001 From: David Boreham Date: Thu, 6 Apr 2023 05:48:23 -0600 Subject: [PATCH 7/9] Fix typo --- scripts/quick-install-ubuntu.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/quick-install-ubuntu.sh b/scripts/quick-install-ubuntu.sh index 393469ac..92d540b3 100755 --- a/scripts/quick-install-ubuntu.sh +++ b/scripts/quick-install-ubuntu.sh @@ -74,7 +74,7 @@ echo \ sudo apt -y update echo "**************************************************************************************" -echo "Installing docker +echo "Installing docker" sudo apt -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin # Allow the current user to use Docker @@ -98,6 +98,7 @@ then echo ${path_add_command} >> ~/.profile fi +echo "**************************************************************************************" # PATH set here for commands run in this script export PATH=$PATH:${install_dir} echo Installed laconic-so version: $(laconic-so version) -- 2.45.2 From 5063e4f2cd5841aa11e916f0c5fcbfea3eaf34b6 Mon Sep 17 00:00:00 2001 From: David Boreham Date: Thu, 6 Apr 2023 06:10:55 -0600 Subject: [PATCH 8/9] Fix another typo --- scripts/quick-install-ubuntu.sh | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/scripts/quick-install-ubuntu.sh b/scripts/quick-install-ubuntu.sh index 92d540b3..d1179b8b 100755 --- a/scripts/quick-install-ubuntu.sh +++ b/scripts/quick-install-ubuntu.sh @@ -45,9 +45,11 @@ done # Enable stop on error now, since we needed it off for the code above set -euo pipefail ## https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/ -echo "**************************************************************************************" -echo "Removing existing docker packages" -sudo apt -y remove $installed_packages_to_remove +if [[ -n "${installed_packages_to_remove}" ]]; then + echo "**************************************************************************************" + echo "Removing existing docker packages" + sudo apt -y remove $installed_packages_to_remove +fi echo "**************************************************************************************" echo "Installing dependencies" @@ -81,7 +83,7 @@ sudo apt -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin d sudo usermod -aG docker $USER echo "**************************************************************************************" -echo "Installing laconic-so +echo "Installing laconic-so" # install latest `laconic-so` install_filename=${install_dir}/laconic-so mkdir -p ${install_dir} @@ -107,7 +109,7 @@ echo "************************************************************************** echo "The Laconic Stack Orchestrator program laconic-so has been installed at ${install_filename}" echo "The directory ${install_dir} has been added to PATH in new shells via ~/.profile" echo "Either open a new shell to use laconic-so on the PATH, or run this command in this shell:" -echo "export PATH=\$PATH:${install_dir}" +echo "${path_add_command}" echo "**************************************************************************************" # Message the user to check docker is working for them echo "Please test that docker is correctly installed and working for your user by running the" -- 2.45.2 From f6900f17d21a4d7bf65327d0ba4aa0cccd7adc16 Mon Sep 17 00:00:00 2001 From: David Boreham Date: Thu, 6 Apr 2023 06:23:14 -0600 Subject: [PATCH 9/9] Update docker instructions --- scripts/quick-install-ubuntu.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/scripts/quick-install-ubuntu.sh b/scripts/quick-install-ubuntu.sh index d1179b8b..3611abdf 100755 --- a/scripts/quick-install-ubuntu.sh +++ b/scripts/quick-install-ubuntu.sh @@ -107,12 +107,11 @@ echo Installed laconic-so version: $(laconic-so version) echo "**************************************************************************************" echo "The Laconic Stack Orchestrator program laconic-so has been installed at ${install_filename}" -echo "The directory ${install_dir} has been added to PATH in new shells via ~/.profile" -echo "Either open a new shell to use laconic-so on the PATH, or run this command in this shell:" -echo "${path_add_command}" +echo "The directory ${install_dir} has been added to PATH in *new* shells via ~/.profile" echo "**************************************************************************************" # Message the user to check docker is working for them -echo "Please test that docker is correctly installed and working for your user by running the" +echo "Please log in again (docker will not work in this current shell) then:" +echo "test that docker is correctly installed and working for your user by running the" echo "command below (it should print a message beginning \"Hello from Docker!\"):" echo echo "docker run hello-world" -- 2.45.2