From 6b62247ef7a32e20e55c529afa0b80fadb6873a1 Mon Sep 17 00:00:00 2001 From: prathamesh0 <42446521+prathamesh0@users.noreply.github.com> Date: Tue, 11 Apr 2023 16:21:03 +0530 Subject: [PATCH] Add an option to pass env file to deploy command (#304) * Add an option to pass env file to deploy command * Use env variable mapping in fixturenet-optimism stack * Use default values from checked in env files * Use env variable mapping in mobymask-v2 stack * Update instructions * Add extra hosts in app compose files and update instructions * Add CERC prefix to env variables in fixturenet-optimism stack * Add CERC prefix to env variables in mobymask-v2 stack --- .../docker-compose-fixturenet-optimism.yml | 33 +++++++++--- .../compose/docker-compose-mobymask-app.yml | 10 +++- .../compose/docker-compose-peer-test-app.yml | 5 ++ .../docker-compose-watcher-mobymask-v2.yml | 23 ++++++--- .../fixturenet-optimism/generate-l2-config.sh | 4 +- .../config/fixturenet-optimism/l1-params.env | 18 +++---- .../optimism-contracts/run.sh | 40 +++++++++------ .../fixturenet-optimism/run-op-batcher.sh | 4 +- .../config/fixturenet-optimism/run-op-node.sh | 4 +- .../deploy-and-generate-invite.sh | 28 ++++++---- .../watcher-mobymask-v2/mobymask-app-start.sh | 13 +++-- .../watcher-mobymask-v2/mobymask-params.env | 20 ++++---- .../watcher-mobymask-v2/optimism-params.env | 16 +++--- .../watcher-mobymask-v2/start-server.sh | 22 +++++--- .../watcher-mobymask-v2/test-app-start.sh | 6 ++- .../watcher-config-template.toml | 6 +-- .../hardhat-tasks/send-balance.ts | 2 +- .../verify-contract-deployment.ts | 2 +- app/data/stacks/fixturenet-optimism/README.md | 4 +- .../stacks/fixturenet-optimism/l2-only.md | 29 ++++++++--- app/data/stacks/mobymask-v2/README.md | 4 +- app/data/stacks/mobymask-v2/mobymask-only.md | 51 +++++++++++++++---- app/data/stacks/mobymask-v2/web-apps.md | 47 +++++++++++++---- app/deploy_system.py | 5 +- 24 files changed, 276 insertions(+), 120 deletions(-) diff --git a/app/data/compose/docker-compose-fixturenet-optimism.yml b/app/data/compose/docker-compose-fixturenet-optimism.yml index 142a2251..cc1d64d3 100644 --- a/app/data/compose/docker-compose-fixturenet-optimism.yml +++ b/app/data/compose/docker-compose-fixturenet-optimism.yml @@ -9,9 +9,17 @@ services: image: cerc/optimism-contracts:local env_file: - ../config/fixturenet-optimism/l1-params.env + environment: + CERC_SCRIPT_DEBUG: ${CERC_SCRIPT_DEBUG} + CERC_L1_CHAIN_ID: ${CERC_L1_CHAIN_ID} + CERC_L1_RPC: ${CERC_L1_RPC} + CERC_L1_ADDRESS: ${CERC_L1_ADDRESS} + CERC_L1_PRIV_KEY: ${CERC_L1_PRIV_KEY} + CERC_L1_ADDRESS_2: ${CERC_L1_ADDRESS_2} + CERC_L1_PRIV_KEY_2: ${CERC_L1_PRIV_KEY_2} # Waits for L1 endpoint to be up before running the script command: | - "./wait-for-it.sh -h $${L1_HOST} -p $${L1_PORT} -s -t 60 -- ./run.sh" + "./wait-for-it.sh -h ${CERC_L1_HOST:-$${DEFAULT_CERC_L1_HOST}} -p ${CERC_L1_PORT:-$${DEFAULT_CERC_L1_PORT}} -s -t 60 -- ./run.sh" volumes: - ../config/wait-for-it.sh:/app/packages/contracts-bedrock/wait-for-it.sh - ../container-build/cerc-optimism-contracts/hardhat-tasks/verify-contract-deployment.ts:/app/packages/contracts-bedrock/tasks/verify-contract-deployment.ts @@ -33,6 +41,9 @@ services: condition: service_completed_successfully env_file: - ../config/fixturenet-optimism/l1-params.env + environment: + CERC_SCRIPT_DEBUG: ${CERC_SCRIPT_DEBUG} + CERC_L1_RPC: ${CERC_L1_RPC} volumes: - ../config/fixturenet-optimism/generate-l2-config.sh:/app/generate-l2-config.sh - l1_deployment:/contracts-bedrock:ro @@ -65,12 +76,15 @@ services: # Runs the L2 consensus client (Sequencer node) op-node: - env_file: - - ../config/fixturenet-optimism/l1-params.env + image: cerc/optimism-op-node:local depends_on: op-geth: condition: service_healthy - image: cerc/optimism-op-node:local + env_file: + - ../config/fixturenet-optimism/l1-params.env + environment: + CERC_SCRIPT_DEBUG: ${CERC_SCRIPT_DEBUG} + CERC_L1_RPC: ${CERC_L1_RPC} volumes: - ../config/fixturenet-optimism/run-op-node.sh:/app/run-op-node.sh - l2_config:/op-node-data:ro @@ -89,14 +103,17 @@ services: # Runs the batcher (takes transactions from the Sequencer and publishes them to L1) op-batcher: - env_file: - - ../config/fixturenet-optimism/l1-params.env + image: cerc/optimism-op-batcher:local depends_on: op-node: condition: service_healthy op-geth: condition: service_healthy - image: cerc/optimism-op-batcher:local + env_file: + - ../config/fixturenet-optimism/l1-params.env + environment: + CERC_SCRIPT_DEBUG: ${CERC_SCRIPT_DEBUG} + CERC_L1_RPC: ${CERC_L1_RPC} volumes: - ../config/wait-for-it.sh:/wait-for-it.sh - ../config/fixturenet-optimism/run-op-batcher.sh:/run-op-batcher.sh @@ -104,7 +121,7 @@ services: entrypoint: ["sh", "-c"] # Waits for L1 endpoint to be up before running the batcher command: | - "/wait-for-it.sh -h $${L1_HOST} -p $${L1_PORT} -s -t 60 -- /run-op-batcher.sh" + "/wait-for-it.sh -h ${CERC_L1_HOST:-$${DEFAULT_CERC_L1_HOST}} -p ${CERC_L1_PORT:-$${DEFAULT_CERC_L1_PORT}} -s -t 60 -- /run-op-batcher.sh" extra_hosts: - "host.docker.internal:host-gateway" diff --git a/app/data/compose/docker-compose-mobymask-app.yml b/app/data/compose/docker-compose-mobymask-app.yml index db95eeac..1cd4f9ab 100644 --- a/app/data/compose/docker-compose-mobymask-app.yml +++ b/app/data/compose/docker-compose-mobymask-app.yml @@ -6,12 +6,18 @@ services: image: cerc/mobymask-ui:local env_file: - ../config/watcher-mobymask-v2/mobymask-params.env + environment: + CERC_SCRIPT_DEBUG: ${CERC_SCRIPT_DEBUG} + CERC_CHAIN_ID: ${CERC_CHAIN_ID} + CERC_DEPLOYED_CONTRACT: ${CERC_DEPLOYED_CONTRACT} + CERC_APP_WATCHER_URL: ${CERC_APP_WATCHER_URL} + CERC_RELAY_NODES: ${CERC_RELAY_NODES} # 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 + - ./wait-for-it.sh -h ${CERC_WATCHER_HOST:-$${DEFAULT_CERC_WATCHER_HOST}} -p ${CERC_WATCHER_PORT:-$${DEFAULT_CERC_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 @@ -26,6 +32,8 @@ services: retries: 15 start_period: 10s shm_size: '1GB' + extra_hosts: + - "host.docker.internal:host-gateway" 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 index 3ddbd308..c0cc68cb 100644 --- a/app/data/compose/docker-compose-peer-test-app.yml +++ b/app/data/compose/docker-compose-peer-test-app.yml @@ -7,6 +7,9 @@ services: working_dir: /app/packages/test-app env_file: - ../config/watcher-mobymask-v2/mobymask-params.env + environment: + CERC_SCRIPT_DEBUG: ${CERC_SCRIPT_DEBUG} + CERC_RELAY_NODES: ${CERC_RELAY_NODES} command: ["sh", "./test-app-start.sh"] volumes: - ../config/watcher-mobymask-v2/test-app-config.json:/app/packages/test-app/src/test-app-config.json @@ -19,3 +22,5 @@ services: timeout: 5s retries: 15 start_period: 10s + extra_hosts: + - "host.docker.internal:host-gateway" diff --git a/app/data/compose/docker-compose-watcher-mobymask-v2.yml b/app/data/compose/docker-compose-watcher-mobymask-v2.yml index 2e014471..3af4eccb 100644 --- a/app/data/compose/docker-compose-watcher-mobymask-v2.yml +++ b/app/data/compose/docker-compose-watcher-mobymask-v2.yml @@ -22,8 +22,8 @@ services: retries: 15 start_period: 10s - # Deploys MobyMask contract and generates an invite link - # Deployment is skipped if DEPLOYED_CONTRACT env is already set + # Deploys the MobyMask contract and generates an invite link + # Deployment is skipped if CERC_DEPLOYED_CONTRACT env is set mobymask: image: cerc/mobymask:local working_dir: /app/packages/server @@ -31,14 +31,19 @@ services: - ../config/watcher-mobymask-v2/optimism-params.env - ../config/watcher-mobymask-v2/mobymask-params.env environment: - - ENV=PROD + CERC_SCRIPT_DEBUG: ${CERC_SCRIPT_DEBUG} + ENV: "PROD" + CERC_L2_GETH_RPC: ${CERC_L2_GETH_RPC} + CERC_PRIVATE_KEY_DEPLOYER: ${CERC_PRIVATE_KEY_DEPLOYER} + CERC_MOBYMASK_APP_BASE_URI: ${CERC_MOBYMASK_APP_BASE_URI} + CERC_DEPLOYED_CONTRACT: ${CERC_DEPLOYED_CONTRACT} # Waits for L2 Optimism Geth and Node servers to be up before deploying contract command: - sh - -c - | - ./wait-for-it.sh -h $${L2_GETH_HOST} -p $${L2_GETH_PORT} -s -t 0 && \ - ./wait-for-it.sh -h $${L2_NODE_HOST} -p $${L2_NODE_PORT} -s -t 0 && \ + ./wait-for-it.sh -h ${CERC_L2_GETH_HOST:-$${DEFAULT_CERC_L2_GETH_HOST}} -p ${CERC_L2_GETH_PORT:-$${DEFAULT_CERC_L2_GETH_PORT}} -s -t 0 && \ + ./wait-for-it.sh -h ${CERC_L2_NODE_HOST:-$${DEFAULT_CERC_L2_NODE_HOST}} -p ${CERC_L2_NODE_PORT:-$${DEFAULT_CERC_L2_NODE_PORT}} -s -t 0 && \ ./deploy-and-generate-invite.sh volumes: - ../config/wait-for-it.sh:/app/packages/server/wait-for-it.sh @@ -51,16 +56,22 @@ services: # 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 mobymask: condition: service_completed_successfully - image: cerc/watcher-mobymask-v2:local env_file: - ../config/watcher-mobymask-v2/optimism-params.env - ../config/watcher-mobymask-v2/mobymask-params.env + environment: + CERC_SCRIPT_DEBUG: ${CERC_SCRIPT_DEBUG} + CERC_L2_GETH_RPC: ${CERC_L2_GETH_RPC} + CERC_PRIVATE_KEY_PEER: ${CERC_PRIVATE_KEY_PEER} + CERC_ENABLE_PEER_L2_TXS: ${CERC_ENABLE_PEER_L2_TXS} + 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 diff --git a/app/data/config/fixturenet-optimism/generate-l2-config.sh b/app/data/config/fixturenet-optimism/generate-l2-config.sh index 9c439f32..b10048d2 100755 --- a/app/data/config/fixturenet-optimism/generate-l2-config.sh +++ b/app/data/config/fixturenet-optimism/generate-l2-config.sh @@ -4,6 +4,8 @@ if [ -n "$CERC_SCRIPT_DEBUG" ]; then set -x fi +CERC_L1_RPC="${CERC_L1_RPC:-${DEFAULT_CERC_L1_RPC}}" + # Check existing config if it exists if [ -f /app/jwt.txt ] && [ -f /app/rollup.json ]; then echo "Found existing L2 config, cross-checking with L1 deployment config" @@ -30,6 +32,6 @@ op-node genesis l2 \ --deployment-dir /contracts-bedrock/deployments/getting-started/ \ --outfile.l2 /app/genesis.json \ --outfile.rollup /app/rollup.json \ - --l1-rpc $L1_RPC + --l1-rpc $CERC_L1_RPC openssl rand -hex 32 > /app/jwt.txt diff --git a/app/data/config/fixturenet-optimism/l1-params.env b/app/data/config/fixturenet-optimism/l1-params.env index 93c58805..6b23c872 100644 --- a/app/data/config/fixturenet-optimism/l1-params.env +++ b/app/data/config/fixturenet-optimism/l1-params.env @@ -1,14 +1,14 @@ -# Change if pointing to an external L1 endpoint +# Defaults # L1 endpoint -L1_CHAIN_ID=1212 -L1_RPC="http://fixturenet-eth-geth-1:8545" -L1_HOST="fixturenet-eth-geth-1" -L1_PORT=8545 +DEFAULT_CERC_L1_CHAIN_ID=1212 +DEFAULT_CERC_L1_RPC="http://fixturenet-eth-geth-1:8545" +DEFAULT_CERC_L1_HOST="fixturenet-eth-geth-1" +DEFAULT_CERC_L1_PORT=8545 # Credentials for accounts on L1 to send balance to Optimism Proxy contract from # (enables them to do transactions on L2) -L1_ADDRESS= -L1_PRIV_KEY= -L1_ADDRESS_2= -L1_PRIV_KEY_2= +DEFAULT_CERC_L1_ADDRESS= +DEFAULT_CERC_L1_PRIV_KEY= +DEFAULT_CERC_L1_ADDRESS_2= +DEFAULT_CERC_L1_PRIV_KEY_2= diff --git a/app/data/config/fixturenet-optimism/optimism-contracts/run.sh b/app/data/config/fixturenet-optimism/optimism-contracts/run.sh index d4585d4a..c8d1911f 100755 --- a/app/data/config/fixturenet-optimism/optimism-contracts/run.sh +++ b/app/data/config/fixturenet-optimism/optimism-contracts/run.sh @@ -4,7 +4,15 @@ if [ -n "$CERC_SCRIPT_DEBUG" ]; then set -x fi -echo "Using L1 RPC endpoint ${L1_RPC}" +CERC_L1_CHAIN_ID="${CERC_L1_CHAIN_ID:-${DEFAULT_CERC_L1_CHAIN_ID}}" +CERC_L1_RPC="${CERC_L1_RPC:-${DEFAULT_CERC_L1_RPC}}" + +CERC_L1_ADDRESS="${CERC_L1_ADDRESS:-${DEFAULT_CERC_L1_ADDRESS}}" +CERC_L1_PRIV_KEY="${CERC_L1_PRIV_KEY:-${DEFAULT_CERC_L1_PRIV_KEY}}" +CERC_L1_ADDRESS_2="${CERC_L1_ADDRESS_2:-${DEFAULT_CERC_L1_ADDRESS_2}}" +CERC_L1_PRIV_KEY_2="${CERC_L1_PRIV_KEY_2:-${DEFAULT_CERC_L1_PRIV_KEY_2}}" + +echo "Using L1 RPC endpoint ${CERC_L1_RPC}" IMPORT_1="import './verify-contract-deployment'" IMPORT_2="import './rekey-json'" @@ -18,7 +26,7 @@ if ! grep -Fxq "$IMPORT_1" tasks/index.ts; then fi # Update the chainId in the hardhat config -sed -i "/getting-started/ {n; s/.*chainId.*/ chainId: $L1_CHAIN_ID,/}" hardhat.config.ts +sed -i "/getting-started/ {n; s/.*chainId.*/ chainId: $CERC_L1_CHAIN_ID,/}" hardhat.config.ts # Exit if a deployment already exists (on restarts) # Note: fixturenet-eth-geth currently starts fresh on a restart @@ -57,16 +65,16 @@ SEQUENCER_ADDRESS=$(echo "$KEYS_JSON" | jq -r '.Sequencer.address') # Read the private key of L1 accounts if [ -f /geth-accounts/accounts.csv ]; then echo "Using L1 account credentials from the mounted volume" - L1_ADDRESS=$(head -n 1 /geth-accounts/accounts.csv | cut -d ',' -f 2) - L1_PRIV_KEY=$(head -n 1 /geth-accounts/accounts.csv | cut -d ',' -f 3) - L1_ADDRESS_2=$(awk -F, 'NR==2{print $(NF-1)}' /geth-accounts/accounts.csv) - L1_PRIV_KEY_2=$(awk -F, 'NR==2{print $NF}' /geth-accounts/accounts.csv) + CERC_L1_ADDRESS=$(head -n 1 /geth-accounts/accounts.csv | cut -d ',' -f 2) + CERC_L1_PRIV_KEY=$(head -n 1 /geth-accounts/accounts.csv | cut -d ',' -f 3) + CERC_L1_ADDRESS_2=$(awk -F, 'NR==2{print $(NF-1)}' /geth-accounts/accounts.csv) + CERC_L1_PRIV_KEY_2=$(awk -F, 'NR==2{print $NF}' /geth-accounts/accounts.csv) else echo "Using L1 account credentials from env" fi # Select a finalized L1 block as the starting point for roll ups -until FINALIZED_BLOCK=$(cast block finalized --rpc-url "$L1_RPC"); do +until FINALIZED_BLOCK=$(cast block finalized --rpc-url "$CERC_L1_RPC"); do echo "Waiting for a finalized L1 block to exist, retrying after 10s" sleep 10 done @@ -78,22 +86,22 @@ L1_BLOCKTIMESTAMP=$(echo "$FINALIZED_BLOCK" | awk '/timestamp/{print $2}') echo "Selected L1 block ${L1_BLOCKNUMBER} as the starting block for roll ups" # Send balances to the above L2 addresses -yarn hardhat send-balance --to "${ADMIN_ADDRESS}" --amount 2 --private-key "${L1_PRIV_KEY}" --network getting-started -yarn hardhat send-balance --to "${PROPOSER_ADDRESS}" --amount 5 --private-key "${L1_PRIV_KEY}" --network getting-started -yarn hardhat send-balance --to "${BATCHER_ADDRESS}" --amount 1000 --private-key "${L1_PRIV_KEY}" --network getting-started +yarn hardhat send-balance --to "${ADMIN_ADDRESS}" --amount 2 --private-key "${CERC_L1_PRIV_KEY}" --network getting-started +yarn hardhat send-balance --to "${PROPOSER_ADDRESS}" --amount 5 --private-key "${CERC_L1_PRIV_KEY}" --network getting-started +yarn hardhat send-balance --to "${BATCHER_ADDRESS}" --amount 1000 --private-key "${CERC_L1_PRIV_KEY}" --network getting-started echo "Balances sent to L2 accounts" # Update the deployment config sed -i 's/"l2OutputOracleStartingTimestamp": TIMESTAMP/"l2OutputOracleStartingTimestamp": '"$L1_BLOCKTIMESTAMP"'/g' deploy-config/getting-started.json -jq --arg chainid "$L1_CHAIN_ID" '.l1ChainID = ($chainid | tonumber)' deploy-config/getting-started.json > tmp.json && mv tmp.json deploy-config/getting-started.json +jq --arg chainid "$CERC_L1_CHAIN_ID" '.l1ChainID = ($chainid | tonumber)' deploy-config/getting-started.json > tmp.json && mv tmp.json deploy-config/getting-started.json node update-config.js deploy-config/getting-started.json "$ADMIN_ADDRESS" "$PROPOSER_ADDRESS" "$BATCHER_ADDRESS" "$SEQUENCER_ADDRESS" "$L1_BLOCKHASH" echo "Updated the deployment config" # Create a .env file -echo "L1_RPC=$L1_RPC" > .env +echo "CERC_L1_RPC=$CERC_L1_RPC" > .env echo "PRIVATE_KEY_DEPLOYER=$ADMIN_PRIV_KEY" >> .env echo "Deploying the L1 smart contracts, this will take a while..." @@ -109,12 +117,12 @@ PROXY_ADDRESS=$(echo "$PROXY_JSON" | jq -r '.address') # Send balance to the above Proxy contract in L1 for reflecting balance in L2 # First account -yarn hardhat send-balance --to "${PROXY_ADDRESS}" --amount 1 --private-key "${L1_PRIV_KEY}" --network getting-started +yarn hardhat send-balance --to "${PROXY_ADDRESS}" --amount 1 --private-key "${CERC_L1_PRIV_KEY}" --network getting-started # Second account -yarn hardhat send-balance --to "${PROXY_ADDRESS}" --amount 1 --private-key "${L1_PRIV_KEY_2}" --network getting-started +yarn hardhat send-balance --to "${PROXY_ADDRESS}" --amount 1 --private-key "${CERC_L1_PRIV_KEY_2}" --network getting-started echo "Balance sent to Proxy L2 contract" echo "Use following accounts for transactions in L2:" -echo "${L1_ADDRESS}" -echo "${L1_ADDRESS_2}" +echo "${CERC_L1_ADDRESS}" +echo "${CERC_L1_ADDRESS_2}" echo "Done" diff --git a/app/data/config/fixturenet-optimism/run-op-batcher.sh b/app/data/config/fixturenet-optimism/run-op-batcher.sh index 3cab3e94..ff549213 100755 --- a/app/data/config/fixturenet-optimism/run-op-batcher.sh +++ b/app/data/config/fixturenet-optimism/run-op-batcher.sh @@ -4,6 +4,8 @@ if [ -n "$CERC_SCRIPT_DEBUG" ]; then set -x fi +CERC_L1_RPC="${CERC_L1_RPC:-${DEFAULT_CERC_L1_RPC}}" + # Get BACTHER_KEY from keys.json BATCHER_KEY=$(jq -r '.Batcher.privateKey' /l2-accounts/keys.json | tr -d '"') @@ -20,5 +22,5 @@ op-batcher \ --rpc.enable-admin \ --max-channel-duration=1 \ --target-l1-tx-size-bytes=2048 \ - --l1-eth-rpc=$L1_RPC \ + --l1-eth-rpc=$CERC_L1_RPC \ --private-key=$BATCHER_KEY diff --git a/app/data/config/fixturenet-optimism/run-op-node.sh b/app/data/config/fixturenet-optimism/run-op-node.sh index f495aeef..b7cc8680 100755 --- a/app/data/config/fixturenet-optimism/run-op-node.sh +++ b/app/data/config/fixturenet-optimism/run-op-node.sh @@ -4,6 +4,8 @@ if [ -n "$CERC_SCRIPT_DEBUG" ]; then set -x fi +CERC_L1_RPC="${CERC_L1_RPC:-${DEFAULT_CERC_L1_RPC}}" + # Get SEQUENCER KEY from keys.json SEQUENCER_KEY=$(jq -r '.Sequencer.privateKey' /l2-accounts/keys.json | tr -d '"') @@ -19,5 +21,5 @@ op-node \ --p2p.disable \ --rpc.enable-admin \ --p2p.sequencer.key=$SEQUENCER_KEY \ - --l1=$L1_RPC \ + --l1=$CERC_L1_RPC \ --l1.rpckind=any 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 f0513910..2e6ffcf7 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,30 +4,36 @@ if [ -n "$CERC_SCRIPT_DEBUG" ]; then set -x fi -echo "Using L2 RPC endpoint ${L2_GETH_RPC}" +CERC_L2_GETH_RPC="${CERC_L2_GETH_RPC:-${DEFAULT_CERC_L2_GETH_RPC}}" +CERC_PRIVATE_KEY_DEPLOYER="${CERC_PRIVATE_KEY_DEPLOYER:-${DEFAULT_CERC_PRIVATE_KEY_DEPLOYER}}" + +CERC_MOBYMASK_APP_BASE_URI="${CERC_MOBYMASK_APP_BASE_URI:-${DEFAULT_CERC_MOBYMASK_APP_BASE_URI}}" +CERC_DEPLOYED_CONTRACT="${CERC_DEPLOYED_CONTRACT:-${DEFAULT_CERC_DEPLOYED_CONTRACT}}" + +echo "Using L2 RPC endpoint ${CERC_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 - PRIVATE_KEY_DEPLOYER=$(head -n 1 /geth-accounts/accounts.csv | cut -d ',' -f 3) + CERC_PRIVATE_KEY_DEPLOYER=$(head -n 1 /geth-accounts/accounts.csv | cut -d ',' -f 3) else - echo "Using PRIVATE_KEY_DEPLOYER from env" + echo "Using CERC_PRIVATE_KEY_DEPLOYER from env" fi # Set the private key -jq --arg privateKey "$PRIVATE_KEY_DEPLOYER" '.privateKey = $privateKey' secrets-template.json > secrets.json +jq --arg privateKey "$CERC_PRIVATE_KEY_DEPLOYER" '.privateKey = $privateKey' secrets-template.json > secrets.json # Set the RPC URL -jq --arg rpcUrl "$L2_GETH_RPC" '.rpcUrl = $rpcUrl' secrets.json > secrets_updated.json && mv secrets_updated.json secrets.json +jq --arg rpcUrl "$CERC_L2_GETH_RPC" '.rpcUrl = $rpcUrl' secrets.json > secrets_updated.json && mv secrets_updated.json secrets.json # Set the MobyMask app base URI -jq --arg baseURI "$MOBYMASK_APP_BASE_URI" '.baseURI = $baseURI' secrets.json > secrets_updated.json && mv secrets_updated.json secrets.json +jq --arg baseURI "$CERC_MOBYMASK_APP_BASE_URI" '.baseURI = $baseURI' secrets.json > secrets_updated.json && mv secrets_updated.json secrets.json -export RPC_URL="${L2_GETH_RPC}" +export RPC_URL="${CERC_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'" +# Check if CERC_DEPLOYED_CONTRACT environment variable set to skip contract deployment +if [ -n "$CERC_DEPLOYED_CONTRACT" ]; then + echo "CERC_DEPLOYED_CONTRACT is set to '$CERC_DEPLOYED_CONTRACT'" echo "Exiting without deploying contract" exit 0 fi @@ -53,7 +59,7 @@ fi # 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 "$CERC_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-start.sh b/app/data/config/watcher-mobymask-v2/mobymask-app-start.sh index 680e2e8a..fbe2fbf9 100755 --- a/app/data/config/watcher-mobymask-v2/mobymask-app-start.sh +++ b/app/data/config/watcher-mobymask-v2/mobymask-app-start.sh @@ -4,6 +4,11 @@ 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_APP_WATCHER_URL="${CERC_APP_WATCHER_URL:-${DEFAULT_CERC_APP_WATCHER_URL}}" + # 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" @@ -13,13 +18,13 @@ else echo "Setting deployed contract details from env" # Set config values from environment variables - jq --arg address "$DEPLOYED_CONTRACT" \ - --argjson chainId $CHAIN_ID \ - --argjson relayNodes "$RELAY_NODES" \ + jq --arg address "$CERC_DEPLOYED_CONTRACT" \ + --argjson chainId $CERC_CHAIN_ID \ + --argjson relayNodes "$CERC_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 +REACT_APP_WATCHER_URI="$CERC_APP_WATCHER_URL/graphql" npm run build serve -s build diff --git a/app/data/config/watcher-mobymask-v2/mobymask-params.env b/app/data/config/watcher-mobymask-v2/mobymask-params.env index a8db6b4a..9f967170 100644 --- a/app/data/config/watcher-mobymask-v2/mobymask-params.env +++ b/app/data/config/watcher-mobymask-v2/mobymask-params.env @@ -1,20 +1,22 @@ -# Change if pointing web app to external watcher endpoint -WATCHER_HOST="mobymask-watcher-server" -WATCHER_PORT=3001 -APP_WATCHER_URL="http://localhost:3001" +# Defaults + +# Watcher endpoint +DEFAULT_CERC_WATCHER_HOST="mobymask-watcher-server" +DEFAULT_CERC_WATCHER_PORT=3001 +DEFAULT_CERC_APP_WATCHER_URL="http://localhost:3001" # Base URI for mobymask-app (used for generating invite) -MOBYMASK_APP_BASE_URI="http://127.0.0.1:3002/#" +DEFAULT_CERC_MOBYMASK_APP_BASE_URI="http://127.0.0.1:3002/#" # Set to false for disabling watcher peer to send txs to L2 -ENABLE_PEER_L2_TXS=true +DEFAULT_CERC_ENABLE_PEER_L2_TXS=true # 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= +DEFAULT_CERC_DEPLOYED_CONTRACT= # Chain ID is used by mobymask web-app for txs -CHAIN_ID=42069 +DEFAULT_CERC_CHAIN_ID=42069 # Set relay nodes to be used by web-apps -RELAY_NODES=["/ip4/127.0.0.1/tcp/9090/ws/p2p/12D3KooWSPCsVkHVyLQoCqhu2YRPvvM7o6r6NRYyLM5zeA6Uig5t"] +DEFAULT_CERC_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 489dd879..6bdc7ea3 100644 --- a/app/data/config/watcher-mobymask-v2/optimism-params.env +++ b/app/data/config/watcher-mobymask-v2/optimism-params.env @@ -1,13 +1,13 @@ -# Change if pointing to an external optimism geth endpoint +# Defaults # L2 endpoints -L2_GETH_RPC="http://op-geth:8545" -L2_GETH_HOST="op-geth" -L2_GETH_PORT=8545 +DEFAULT_CERC_L2_GETH_RPC="http://op-geth:8545" +DEFAULT_CERC_L2_GETH_HOST="op-geth" +DEFAULT_CERC_L2_GETH_PORT=8545 -L2_NODE_HOST="op-node" -L2_NODE_PORT=8547 +DEFAULT_CERC_L2_NODE_HOST="op-node" +DEFAULT_CERC_L2_NODE_PORT=8547 # Credentials for accounts to perform txs on L2 -PRIVATE_KEY_DEPLOYER= -PRIVATE_KEY_PEER= +DEFAULT_CERC_PRIVATE_KEY_DEPLOYER= +DEFAULT_CERC_PRIVATE_KEY_PEER= diff --git a/app/data/config/watcher-mobymask-v2/start-server.sh b/app/data/config/watcher-mobymask-v2/start-server.sh index 5597850b..ee7b73c3 100755 --- a/app/data/config/watcher-mobymask-v2/start-server.sh +++ b/app/data/config/watcher-mobymask-v2/start-server.sh @@ -4,11 +4,17 @@ if [ -n "$CERC_SCRIPT_DEBUG" ]; then set -x fi -echo "Using L2 RPC endpoint ${L2_GETH_RPC}" +CERC_L2_GETH_RPC="${CERC_L2_GETH_RPC:-${DEFAULT_CERC_L2_GETH_RPC}}" +CERC_PRIVATE_KEY_PEER="${CERC_PRIVATE_KEY_PEER:-${DEFAULT_CERC_PRIVATE_KEY_PEER}}" + +CERC_ENABLE_PEER_L2_TXS="${CERC_ENABLE_PEER_L2_TXS:-${DEFAULT_CERC_ENABLE_PEER_L2_TXS}}" +CERC_DEPLOYED_CONTRACT="${CERC_DEPLOYED_CONTRACT:-${DEFAULT_CERC_DEPLOYED_CONTRACT}}" + +echo "Using L2 RPC endpoint ${CERC_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}" +if [ -n "$CERC_DEPLOYED_CONTRACT" ]; then + CONTRACT_ADDRESS="${CERC_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 '"') @@ -17,19 +23,19 @@ fi if [ -f /geth-accounts/accounts.csv ]; then echo "Using L1 private key from the mounted volume" # Read the private key of L1 account for sending txs from peer - PRIVATE_KEY_PEER=$(awk -F, 'NR==2{print $NF}' /geth-accounts/accounts.csv) + CERC_PRIVATE_KEY_PEER=$(awk -F, 'NR==2{print $NF}' /geth-accounts/accounts.csv) else - echo "Using PRIVATE_KEY_PEER from env" + echo "Using CERC_PRIVATE_KEY_PEER from env" fi # Read in the config template TOML file and modify it WATCHER_CONFIG_TEMPLATE=$(cat environments/watcher-config-template.toml) WATCHER_CONFIG=$(echo "$WATCHER_CONFIG_TEMPLATE" | \ - sed -E "s/REPLACE_WITH_ENABLE_PEER_L2_TXS/${ENABLE_PEER_L2_TXS}/g; \ - s/REPLACE_WITH_PRIVATE_KEY_PEER/${PRIVATE_KEY_PEER}/g; \ + sed -E "s/REPLACE_WITH_CERC_ENABLE_PEER_L2_TXS/${CERC_ENABLE_PEER_L2_TXS}/g; \ + s/REPLACE_WITH_CERC_PRIVATE_KEY_PEER/${CERC_PRIVATE_KEY_PEER}/g; \ s/REPLACE_WITH_CONTRACT_ADDRESS/${CONTRACT_ADDRESS}/g; \ - s|REPLACE_WITH_L2_GETH_RPC_ENDPOINT|${L2_GETH_RPC}| ") + s|REPLACE_WITH_CERC_L2_GETH_RPC_ENDPOINT|${CERC_L2_GETH_RPC}| ") # Write the modified content to a new file echo "$WATCHER_CONFIG" > environments/local.toml diff --git a/app/data/config/watcher-mobymask-v2/test-app-start.sh b/app/data/config/watcher-mobymask-v2/test-app-start.sh index de6ccc7c..2f45da03 100755 --- a/app/data/config/watcher-mobymask-v2/test-app-start.sh +++ b/app/data/config/watcher-mobymask-v2/test-app-start.sh @@ -4,8 +4,10 @@ if [ -n "$CERC_SCRIPT_DEBUG" ]; then set -x fi -# Set relay nodes in config from RELAY_NODES environment variable -jq --argjson relayNodes "$RELAY_NODES" \ +CERC_RELAY_NODES="${CERC_RELAY_NODES:-${DEFAULT_CERC_RELAY_NODES}}" + +# Set relay nodes in config from CERC_RELAY_NODES environment variable +jq --argjson relayNodes "$CERC_RELAY_NODES" \ '.relayNodes = $relayNodes' \ ./src/test-app-config.json > ./src/config.json 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 c360ffed..843cdbfe 100644 --- a/app/data/config/watcher-mobymask-v2/watcher-config-template.toml +++ b/app/data/config/watcher-mobymask-v2/watcher-config-template.toml @@ -35,10 +35,10 @@ pubSubTopic = 'mobymask' peerIdFile = './peer-id.json' enableDebugInfo = true - enableL2Txs = REPLACE_WITH_ENABLE_PEER_L2_TXS + enableL2Txs = REPLACE_WITH_CERC_ENABLE_PEER_L2_TXS [server.p2p.peer.l2TxsConfig] - privateKey = 'REPLACE_WITH_PRIVATE_KEY_PEER' + privateKey = 'REPLACE_WITH_CERC_PRIVATE_KEY_PEER' contractAddress = 'REPLACE_WITH_CONTRACT_ADDRESS' [metrics] @@ -60,7 +60,7 @@ [upstream] [upstream.ethServer] gqlApiEndpoint = "http://ipld-eth-server:8083/graphql" - rpcProviderEndpoint = "REPLACE_WITH_L2_GETH_RPC_ENDPOINT" + rpcProviderEndpoint = "REPLACE_WITH_CERC_L2_GETH_RPC_ENDPOINT" blockDelayInMilliSecs = 60000 [upstream.cache] diff --git a/app/data/container-build/cerc-optimism-contracts/hardhat-tasks/send-balance.ts b/app/data/container-build/cerc-optimism-contracts/hardhat-tasks/send-balance.ts index 54615647..dd7065bc 100644 --- a/app/data/container-build/cerc-optimism-contracts/hardhat-tasks/send-balance.ts +++ b/app/data/container-build/cerc-optimism-contracts/hardhat-tasks/send-balance.ts @@ -8,7 +8,7 @@ task('send-balance', 'Sends Ether to a specified Ethereum account') .addParam('privateKey', 'The private key of the sender') .setAction(async ({ to, amount, privateKey }, {}) => { // Open the wallet using sender's private key - const provider = new ethers.providers.JsonRpcProvider(`${process.env.L1_RPC}`) + const provider = new ethers.providers.JsonRpcProvider(`${process.env.CERC_L1_RPC}`) const wallet = new ethers.Wallet(privateKey, provider) // Send amount to the specified address diff --git a/app/data/container-build/cerc-optimism-contracts/hardhat-tasks/verify-contract-deployment.ts b/app/data/container-build/cerc-optimism-contracts/hardhat-tasks/verify-contract-deployment.ts index 5b673ca1..340bc4f3 100644 --- a/app/data/container-build/cerc-optimism-contracts/hardhat-tasks/verify-contract-deployment.ts +++ b/app/data/container-build/cerc-optimism-contracts/hardhat-tasks/verify-contract-deployment.ts @@ -9,7 +9,7 @@ task( .addParam('transactionHash', 'Hash of the deployment transaction') .setAction(async ({ contract, transactionHash }, { ethers }) => { const provider = new ethers.providers.JsonRpcProvider( - `${process.env.L1_RPC}` + `${process.env.CERC_L1_RPC}` ) // Get the deployment tx receipt diff --git a/app/data/stacks/fixturenet-optimism/README.md b/app/data/stacks/fixturenet-optimism/README.md index 61ca97b3..502e3305 100644 --- a/app/data/stacks/fixturenet-optimism/README.md +++ b/app/data/stacks/fixturenet-optimism/README.md @@ -10,6 +10,8 @@ Clone required repositories: ```bash laconic-so --stack fixturenet-optimism setup-repositories + +# 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: @@ -109,7 +111,7 @@ docker volume rm $(docker volume ls -q --filter "name=.*fixturenet_geth_accounts docker volume rm $(docker volume ls -q --filter name=l2_geth_data) ``` - * Reuse the deployment command used in [Deploy](#deploy) to restart the stopped containers + * Re-run the deployment command used in [Deploy](#deploy) to restart the stopped containers ## Known Issues diff --git a/app/data/stacks/fixturenet-optimism/l2-only.md b/app/data/stacks/fixturenet-optimism/l2-only.md index a1c33717..821d16a8 100644 --- a/app/data/stacks/fixturenet-optimism/l2-only.md +++ b/app/data/stacks/fixturenet-optimism/l2-only.md @@ -10,6 +10,8 @@ Clone required repositories: ```bash laconic-so --stack fixturenet-optimism setup-repositories --exclude cerc-io/go-ethereum + +# 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: @@ -35,16 +37,29 @@ This should create the required docker images in the local image registry: ## Deploy -Update the [l1-params.env](../../config/fixturenet-optimism/l1-params.env) file with L1 endpoint (`L1_RPC`, `L1_HOST` and `L1_PORT`) and other params +Create and update an env file to be used in the next step ([defaults](../../config/fixturenet-optimism/l1-params.env)): -* 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 L1 is running on the host machine, use `host.docker.internal` as the hostname to access the host port + ```bash + # External L1 endpoint + CERC_L1_CHAIN_ID= + CERC_L1_RPC= + CERC_L1_HOST= + CERC_L1_PORT= + + # Credentials for accounts on L1 to send balance to Optimism Proxy contract from + # (enables them to do transactions on L2) + CERC_L1_ADDRESS= + CERC_L1_PRIV_KEY= + CERC_L1_ADDRESS_2= + CERC_L1_PRIV_KEY_2= + ``` + +* NOTE: If L1 is running on the host machine, use `host.docker.internal` as the hostname to access the host port Deploy the stack: ```bash -laconic-so --stack fixturenet-optimism deploy up --include fixturenet-optimism +laconic-so --stack fixturenet-optimism deploy --include fixturenet-optimism --env-file up ``` The `fixturenet-optimism-contracts` service may take a while (`~15 mins`) to complete running as it: @@ -69,7 +84,7 @@ docker logs -f Stop all services running in the background: ```bash -laconic-so --stack fixturenet-optimism deploy down --include fixturenet-optimism +laconic-so --stack fixturenet-optimism deploy --include fixturenet-optimism down ``` Clear volumes created by this stack: @@ -84,4 +99,4 @@ docker volume rm $(docker volume ls -q --filter "name=.*fixturenet_geth_accounts ## Troubleshooting -See [Troubleshooting](./README.md#troubleshooting) \ No newline at end of file +See [Troubleshooting](./README.md#troubleshooting) diff --git a/app/data/stacks/mobymask-v2/README.md b/app/data/stacks/mobymask-v2/README.md index 54f66239..ab36f302 100644 --- a/app/data/stacks/mobymask-v2/README.md +++ b/app/data/stacks/mobymask-v2/README.md @@ -1,10 +1,12 @@ # MobyMask v2 watcher -Instructions to setup and deploy an end-to-end MobyMask v2 stack ([L1](../fixturenet-eth/) + [L2](../fixturenet-optimism/) chains + watcher) using [laconic-stack-orchestrator](/README.md#install) +Instructions to setup and deploy an end-to-end MobyMask v2 stack ([L1](../fixturenet-eth/) + [L2](../fixturenet-optimism/) chains + watcher + web-app(s)) using [laconic-stack-orchestrator](/README.md#install) We support running just the watcher part of stack, given an external L2 Optimism endpoint. Follow [mobymask-only](./mobymask-only.md) for the same. +We also support running just the web-app(s), given external watcher GQL (for mobymask-app) and relay node endpoints. Follow [web-apps.md](./web-apps.md) for the same. + ## Setup Clone required repositories: diff --git a/app/data/stacks/mobymask-v2/mobymask-only.md b/app/data/stacks/mobymask-v2/mobymask-only.md index 74290151..27073034 100644 --- a/app/data/stacks/mobymask-v2/mobymask-only.md +++ b/app/data/stacks/mobymask-v2/mobymask-only.md @@ -10,6 +10,8 @@ Clone required repositories: ```bash laconic-so --stack mobymask-v2 setup-repositories --include cerc-io/MobyMask,cerc-io/watcher-ts + +# 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: @@ -36,19 +38,38 @@ This should create the required docker images in the local image registry ### 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 - * `ENABLE_PEER_L2_TXS` is used to enable/disable sending txs to L2 chain from watcher peer. -* Update the [optimism-params.env](../../config/watcher-mobymask-v2/optimism-params.env) file with Optimism endpoints and other params for the Optimism running separately - * `PRIVATE_KEY_PEER` is used by watcher peer to send txs to L2 chain -* 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 +Create and update an env file to be used in the next step ([defaults](../../config/watcher-mobymask-v2/)): + + ```bash + # External L2 endpoints + CERC_L2_GETH_RPC= + CERC_L2_GETH_HOST= + CERC_L2_GETH_PORT= + + CERC_L2_NODE_HOST= + CERC_L2_NODE_PORT= + + # Credentials for accounts to perform txs on L2 + CERC_PRIVATE_KEY_DEPLOYER= + CERC_PRIVATE_KEY_PEER= + + # Base URI for mobymask-app + # (used for generating a root invite link after deploying the contract) + CERC_MOBYMASK_APP_BASE_URI="http://127.0.0.1:3002/#" + + # Set to false for disabling watcher peer to send txs to L2 + CERC_ENABLE_PEER_L2_TXS=true + + # (Optional) Set already deployed MobyMask contract address to avoid deploying contract in the stack + CERC_DEPLOYED_CONTRACT= + ``` + +* NOTE: If Optimism is running on the host machine, use `host.docker.internal` as the hostname to access the host port ### Deploy the stack ```bash -laconic-so --stack mobymask-v2 deploy --include watcher-mobymask-v2 up +laconic-so --stack mobymask-v2 deploy --include watcher-mobymask-v2 --env-file up ``` To list down and monitor the running containers: @@ -63,10 +84,22 @@ docker ps docker logs -f ``` +The watcher endpoint is exposed on host port `3001` and the relay node endpoint is exposed on host port `9090` + +Check the logs of the deployment container to get the deployed contract's address and generated root invite link: + +```bash +docker logs -f $(docker ps -aq --filter name="mobymask-1") +``` + ## Tests See [Tests](./README.md#tests) +## Web Apps + +For deploying the web-app(s) separately after deploying the watcher, follow [web-apps.md](./web-apps.md) + ## Clean up Stop all services running in the background: diff --git a/app/data/stacks/mobymask-v2/web-apps.md b/app/data/stacks/mobymask-v2/web-apps.md index 052a7cb7..2c1ed253 100644 --- a/app/data/stacks/mobymask-v2/web-apps.md +++ b/app/data/stacks/mobymask-v2/web-apps.md @@ -10,6 +10,8 @@ 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: @@ -36,36 +38,61 @@ This should create the required docker images in the local image registry ### 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 +Create and update an env file to be used in the next step ([defaults](../../config/watcher-mobymask-v2/mobymask-params.env)): + + ```bash + # Set relay nodes to be used by the web-app + CERC_RELAY_NODES=["/ip4/127.0.0.1/tcp/9090/ws/p2p/12D3KooWSPCsVkHVyLQoCqhu2YRPvvM7o6r6NRYyLM5zeA6Uig5t"] + + # Also add if running MobyMask app: + + # External watcher endpoint (to check if watcher is up) + CERC_WATCHER_HOST= + CERC_WATCHER_PORT= + + # 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 + ``` + +* NOTE: 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 +laconic-so --stack mobymask-v2 deploy --include mobymask-app --env-file up + +# Runs on host port 3002 ``` For running peer-test-app ```bash -laconic-so --stack mobymask-v2 deploy --include peer-test-app up +laconic-so --stack mobymask-v2 deploy --include peer-test-app --env-file up + +# Runs on host port 3003 ``` To list down and monitor the running containers: ```bash +laconic-so --stack mobymask-v2 deploy --include [mobymask-app | peer-test-app] ps + docker ps # Check logs for a container docker logs -f ``` +## Demo + +Follow the [demo](./demo.md) to try out the MobyMask app with L2 chain + ## Clean up Stop all services running in the background: diff --git a/app/deploy_system.py b/app/deploy_system.py index 9371a2f8..3c347fdf 100644 --- a/app/deploy_system.py +++ b/app/deploy_system.py @@ -32,11 +32,12 @@ from .util import include_exclude_check, get_parsed_stack_config @click.command() @click.option("--include", help="only start these components") @click.option("--exclude", help="don\'t start these components") +@click.option("--env-file", help="env file to be used") @click.option("--cluster", help="specify a non-default cluster name") @click.argument('command', required=True) # help: command: up|down|ps @click.argument('extra_args', nargs=-1) # help: command: up|down|ps @click.pass_context -def command(ctx, include, exclude, cluster, command, extra_args): +def command(ctx, include, exclude, env_file, cluster, command, extra_args): '''deploy a stack''' # TODO: implement option exclusion and command value constraint lost with the move from argparse to click @@ -51,7 +52,7 @@ def command(ctx, include, exclude, cluster, command, extra_args): cluster_context = _make_cluster_context(ctx.obj, include, exclude, cluster) # See: https://gabrieldemarmiesse.github.io/python-on-whales/sub-commands/compose/ - docker = DockerClient(compose_files=cluster_context.compose_files, compose_project_name=cluster_context.cluster) + docker = DockerClient(compose_files=cluster_context.compose_files, compose_project_name=cluster_context.cluster, compose_env_file=env_file) extra_args_list = list(extra_args) or None