Set L1 account private keys from env

This commit is contained in:
nabarun 2023-04-04 15:54:56 +05:30
parent 64c08a529e
commit 9b41d91b91
7 changed files with 61 additions and 22 deletions

View File

@ -25,28 +25,31 @@ services:
restart: unless-stopped
image: cerc/mobymask:local
working_dir: /app/packages/server
# TODO: Configure env file for private key
env_file:
- ../config/watcher-mobymask-v2/optimism-params.env
environment:
- ENV=PROD
command: |-
./wait-for-it.sh -h $${L2_GETH_HOST} -p $${L2_GETH_PORT} -s \
./wait-for-it.sh -h $${L2_NODE_HOST} -p $${L2_NODE_PORT} -s \
sh ./deploy-and-generate-invite.sh
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 && \
./deploy-and-generate-invite.sh
volumes:
# TODO: Move out to config dir
- ../config/fixturenet-optimism/wait-for-it.sh:/app/packages/server/wait-for-it.sh
- ../config/wait-for-it.sh:/app/packages/server/wait-for-it.sh
- ../config/watcher-mobymask-v2/secrets-template.json:/app/packages/server/secrets-template.json
- ../config/watcher-mobymask-v2/deploy-and-generate-invite.sh:/app/packages/server/deploy-and-generate-invite.sh
- moby_data_server:/app/packages/server
- ../test/fixturenet_geth_accounts:/geth-accounts:ro
- fixturenet_geth_accounts:/geth-accounts:ro
healthcheck:
test: ["CMD", "nc", "-v", "localhost", "3330"]
interval: 20s
timeout: 5s
retries: 15
start_period: 10s
extra_hosts:
- "host.docker.internal:host-gateway"
mobymask-watcher-server:
restart: unless-stopped
@ -56,7 +59,6 @@ services:
mobymask:
condition: service_healthy
image: cerc/watcher-mobymask-v2:local
# TODO: Configure env file for private key
env_file:
- ../config/watcher-mobymask-v2/optimism-params.env
command: ["sh", "server-start.sh"]
@ -67,7 +69,7 @@ services:
- ../config/watcher-mobymask-v2/peer-id.json:/app/packages/mobymask-v2-watcher/peer-id.json
- ../config/watcher-mobymask-v2/server-start.sh:/app/packages/mobymask-v2-watcher/server-start.sh
- moby_data_server:/server
- ../test/fixturenet_geth_accounts:/geth-accounts:ro
- fixturenet_geth_accounts:/geth-accounts:ro
ports:
- "0.0.0.0:3001:3001"
- "0.0.0.0:9001:9001"

View File

@ -1,12 +1,20 @@
#!/bin/sh
set -e
if [ -n "$CERC_SCRIPT_DEBUG" ]; then
set -x
fi
# Read the private key of L1 account to deploy contract
# TODO: Take from env if /geth-accounts volume doesn't exist to allow using separately running L1
L1_PRIV_KEY=$(head -n 1 /geth-accounts/accounts.csv | cut -d ',' -f 3)
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)
else
echo "Using PRIVATE_KEY_DEPLOYER from env"
fi
# Set the private key
jq --arg privateKey "$L1_PRIV_KEY" '.privateKey = $privateKey' secrets-template.json > secrets.json
jq --arg privateKey "$PRIVATE_KEY_DEPLOYER" '.privateKey = $privateKey' secrets-template.json > secrets.json
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

View File

@ -1,5 +1,8 @@
#!/bin/sh
set -e
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

View File

@ -1,14 +1,25 @@
#!/bin/sh
set -e
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 '"')
L1_PRIV_KEY_2=$(awk -F, 'NR==2{print $NF}' /geth-accounts/accounts.csv)
sed "s/REPLACE_WITH_PRIVATE_KEY/${L1_PRIV_KEY_2}/" environments/watcher-config-template.toml > environments/local.toml
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)
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
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
sed -i 's|REPLACE_WITH_L2_GETH_URL|'"${L2_GETH_URL}"'|' environments/local.toml
echo 'yarn server'
yarn server

View File

@ -58,8 +58,8 @@
[upstream]
[upstream.ethServer]
gqlApiEndpoint = "REPLACE_WITH_L2_GETH_URL"
rpcProviderEndpoint = "http://op-geth:8545"
gqlApiEndpoint = "http://ipld-eth-server:8083/graphql"
rpcProviderEndpoint = "REPLACE_WITH_L2_GETH_URL"
blockDelayInMilliSecs = 60000
[upstream.cache]

View File

@ -10,7 +10,7 @@ Clone required repositories:
laconic-so --stack mobymask-v2 setup-repositories
# Include repositories required for MobyMask if running optimism separately
laconic-so --stack fixturenet-optimism 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,cerc-io/react-peer,cerc-io/mobymask-ui
```
NOTE: If repositories already exist and are checked out to different versions, `setup-repositories` command will throw an error.
@ -46,7 +46,7 @@ Build the container images:
laconic-so --stack mobymask-v2 build-containers
# Only build containers required for MobyMask if running optimism separately
laconic-so --stack fixturenet-optimism 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/react-peer,cerc/mobymask-ui,cerc/mobymask
```
This should create the required docker images in the local image registry.
@ -65,7 +65,7 @@ Deploy the stack:
laconic-so --stack mobymask-v2 deploy-system up
# Only start watcher-mobymask-v2 pod if running optimism separately
laconic-so --stack mobymask-v2 deploy up --include watcher-mobymask-v2
laconic-so --stack mobymask-v2 deploy --include watcher-mobymask-v2 up
```
* List and check the health status of all the containers using `docker ps` and wait for them to be `healthy`
@ -85,6 +85,9 @@ Find the watcher container's id and export it for later use:
```bash
laconic-so --stack mobymask-v2 deploy-system ps | grep "mobymask-watcher-server"
# If only running watcher-mobymask-v2 pod
laconic-so --stack mobymask-v2 deploy-system --include watcher-mobymask-v2 ps | grep "mobymask-watcher-server"
export CONTAINER_ID=<CONTAINER_ID>
```
@ -136,6 +139,9 @@ Stop all the services running in background run:
```bash
laconic-so --stack mobymask-v2 deploy-system down
# If only ran watcher-mobymask-v2 pod
laconic-so --stack mobymask-v2 deploy down --include watcher-mobymask-v2
```
Clear volumes:

View File

@ -4,6 +4,9 @@
```bash
laconic-so --stack mobymask-v2 deploy-system logs mobymask
# If only running watcher-mobymask-v2 pod
laconic-so --stack mobymask-v2 deploy-system --include watcher-mobymask-v2 logs mobymask
```
The invite link is seen at the end of the logs. Example log:
@ -35,6 +38,9 @@
```bash
laconic-so --stack mobymask-v2 deploy-system ps | grep mobymask-watcher-server
# If only running watcher-mobymask-v2 pod
laconic-so --stack mobymask-v2 deploy-system --include watcher-mobymask-v2 ps | grep mobymask-watcher-server
```
* Check logs:
@ -75,6 +81,9 @@
```bash
laconic-so --stack mobymask-v2 deploy-system exec mobymask-app "cat src/config.json"
# If only running watcher-mobymask-v2 pod
laconic-so --stack mobymask-v2 deploy-system --include watcher-mobymask-v2 exec mobymask-app "cat src/config.json"
```
The value of `address` field is the deployed contract address