diff --git a/app/data/compose/docker-compose-mobymask-app.yml b/app/data/compose/docker-compose-mobymask-app.yml deleted file mode 100644 index db95eeac..00000000 --- a/app/data/compose/docker-compose-mobymask-app.yml +++ /dev/null @@ -1,31 +0,0 @@ -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 deleted file mode 100644 index 3ddbd308..00000000 --- a/app/data/compose/docker-compose-peer-test-app.yml +++ /dev/null @@ -1,21 +0,0 @@ -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 2e014471..fd68212a 100644 --- a/app/data/compose/docker-compose-watcher-mobymask-v2.yml +++ b/app/data/compose/docker-compose-watcher-mobymask-v2.yml @@ -1,7 +1,6 @@ version: '3.2' services: - # Starts the PostgreSQL database for watcher mobymask-watcher-db: restart: unless-stopped image: postgres:14-alpine @@ -22,17 +21,13 @@ 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 @@ -49,7 +44,6 @@ services: extra_hosts: - "host.docker.internal:host-gateway" - # Starts the mobymask-v2-watcher server mobymask-watcher-server: restart: unless-stopped depends_on: @@ -60,7 +54,6 @@ 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 @@ -70,7 +63,6 @@ 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" @@ -84,6 +76,48 @@ 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 743b1525..2a3000ee 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,8 +4,6 @@ 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 @@ -18,16 +16,10 @@ fi jq --arg privateKey "$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 +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 -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 +export RPC_URL="${L2_GETH_URL}" # Check and exit if a deployment already exists (on restarts) if [ -f ./config.json ]; then @@ -47,10 +39,10 @@ if [ -f ./config.json ]; then fi fi -# Wait until balance for deployer account is updated +# Wait until balance for deployer account is reflected 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 2ccb816d..3b00674f 100644 --- a/app/data/config/watcher-mobymask-v2/mobymask-app-config.json +++ b/app/data/config/watcher-mobymask-v2/mobymask-app-config.json @@ -1,5 +1,4 @@ { - "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 680e2e8a..efc4ed96 100755 --- a/app/data/config/watcher-mobymask-v2/mobymask-app-start.sh +++ b/app/data/config/watcher-mobymask-v2/mobymask-app-start.sh @@ -4,22 +4,9 @@ if [ -n "$CERC_SCRIPT_DEBUG" ]; then set -x fi -# 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" +# 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 - # 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 +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 new file mode 100644 index 00000000..698d3502 --- /dev/null +++ b/app/data/config/watcher-mobymask-v2/mobymask-app.env @@ -0,0 +1 @@ +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 deleted file mode 100644 index 890c183b..00000000 --- a/app/data/config/watcher-mobymask-v2/mobymask-params.env +++ /dev/null @@ -1,14 +0,0 @@ -# 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 489dd879..bafb37a8 100644 --- a/app/data/config/watcher-mobymask-v2/optimism-params.env +++ b/app/data/config/watcher-mobymask-v2/optimism-params.env @@ -1,10 +1,9 @@ # Change if pointing to an external optimism geth endpoint # L2 endpoints -L2_GETH_RPC="http://op-geth:8545" +# TODO: Add another env for complete URL to handle https 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 4030e522..5fe9ab84 100755 --- a/app/data/config/watcher-mobymask-v2/start-server.sh +++ b/app/data/config/watcher-mobymask-v2/start-server.sh @@ -4,15 +4,8 @@ if [ -n "$CERC_SCRIPT_DEBUG" ]; then set -x fi -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 +# Assign deployed contract address from server config +CONTRACT_ADDRESS=$(jq -r '.address' /server/config.json | tr -d '"') if [ -f /geth-accounts/accounts.csv ]; then echo "Using L1 private key from the mounted volume" @@ -22,20 +15,11 @@ else echo "Using PRIVATE_KEY_PEER from env" fi -# 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") +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 - # 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 +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 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 deleted file mode 100755 index de6ccc7c..00000000 --- a/app/data/config/watcher-mobymask-v2/test-app-start.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/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 6b0223c7..05554e3a 100644 --- a/app/data/config/watcher-mobymask-v2/watcher-config-template.toml +++ b/app/data/config/watcher-mobymask-v2/watcher-config-template.toml @@ -36,6 +36,10 @@ 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 @@ -55,7 +59,7 @@ [upstream] [upstream.ethServer] gqlApiEndpoint = "http://ipld-eth-server:8083/graphql" - rpcProviderEndpoint = "REPLACE_WITH_L2_GETH_RPC_ENDPOINT" + rpcProviderEndpoint = "REPLACE_WITH_L2_GETH_URL" 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 c04b001d..68e3c77c 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 bash +RUN apk --update --no-cache add make git jq WORKDIR /app diff --git a/app/data/container-build/cerc-react-peer/Dockerfile b/app/data/container-build/cerc-react-peer/Dockerfile index fcc198f3..cc852441 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 jq +RUN apk --update --no-cache add make git python3 WORKDIR /app diff --git a/app/data/stacks/mobymask-v2/mobymask-only.md b/app/data/stacks/mobymask-v2/mobymask-only.md index 246d9000..69c2007b 100644 --- a/app/data/stacks/mobymask-v2/mobymask-only.md +++ b/app/data/stacks/mobymask-v2/mobymask-only.md @@ -4,21 +4,30 @@ Instructions to setup and deploy MobyMask v2 watcher independently ## Setup -Prerequisite: L2 Optimism Geth and Node RPC endpoints +Prerequisite: An L2 Optimism RPC endpoint Clone required repositories: ```bash -laconic-so --stack mobymask-v2 setup-repositories --include cerc-io/MobyMask,cerc-io/watcher-ts +laconic-so --stack mobymask-v2 setup-repositories --include cerc-io/MobyMask,cerc-io/watcher-ts,cerc-io/react-peer,cerc-io/mobymask-ui ``` 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 @@ -27,24 +36,20 @@ git checkout v0.1.2 Build the container images: ```bash -laconic-so --stack mobymask-v2 build-containers --include cerc/watcher-mobymask-v2,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 ## Deploy -### Configuration +Update the [optimism-params.env](../../config/watcher-mobymask-v2/optimism-params.env) file with Optimism endpoints and other params if running Optimism separately -* 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 @@ -62,9 +67,7 @@ docker ps docker logs -f ``` -## Tests - -See [Tests](./README.md#tests) +See [Tests](./README.md#tests) and [Demo](./README.md#demo) to interact with stack ## Clean up diff --git a/app/data/stacks/mobymask-v2/stack.yml b/app/data/stacks/mobymask-v2/stack.yml index 248351b1..cdcbd663 100644 --- a/app/data/stacks/mobymask-v2/stack.yml +++ b/app/data/stacks/mobymask-v2/stack.yml @@ -27,5 +27,3 @@ 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 deleted file mode 100644 index 052a7cb7..00000000 --- a/app/data/stacks/mobymask-v2/web-apps.md +++ /dev/null @@ -1,91 +0,0 @@ -# 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") -``` diff --git a/scripts/developer-mode-setup.sh b/scripts/developer-mode-setup.sh new file mode 100755 index 00000000..997c6173 --- /dev/null +++ b/scripts/developer-mode-setup.sh @@ -0,0 +1,11 @@ +#!/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 diff --git a/scripts/first_time_setup.sh b/scripts/first_time_setup.sh deleted file mode 100755 index e8900ce7..00000000 --- a/scripts/first_time_setup.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -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 new file mode 100755 index 00000000..3611abdf --- /dev/null +++ b/scripts/quick-install-ubuntu.sh @@ -0,0 +1,118 @@ +#!/usr/bin/env bash +if [[ -n "$CERC_SCRIPT_DEBUG" ]]; then + set -x +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 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 + 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 + +## https://docs.docker.com/engine/install/ubuntu/ +## 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/ + +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" +sudo apt -y update + +# 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 + +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} + +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 + +echo "**************************************************************************************" +# PATH set here for commands run in this script +export PATH=$PATH:${install_dir} +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 "**************************************************************************************" +# Message the user to check docker is working for them +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" +echo