From 8a22b4fd47bc2bf2ac9ecdcecde292aabae41d38 Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Fri, 26 Jul 2024 10:21:16 +0530 Subject: [PATCH] Add a stack for testnet-onboarding-app --- .../docker-compose-testnet-onboarding-app.yml | 26 ++++++ .../config/app/onboarding-app-start.sh | 28 ++++++ .../cerc-testnet-onboarding-app/Dockerfile | 43 +++++++++ .../stacks/onboarding-app/README.md | 93 +++++++++++++++++++ .../stacks/onboarding-app/stack.yml | 9 ++ 5 files changed, 199 insertions(+) create mode 100644 stack-orchestrator/compose/docker-compose-testnet-onboarding-app.yml create mode 100644 stack-orchestrator/config/app/onboarding-app-start.sh create mode 100644 stack-orchestrator/container-build/cerc-testnet-onboarding-app/Dockerfile create mode 100644 stack-orchestrator/stacks/onboarding-app/README.md create mode 100644 stack-orchestrator/stacks/onboarding-app/stack.yml diff --git a/stack-orchestrator/compose/docker-compose-testnet-onboarding-app.yml b/stack-orchestrator/compose/docker-compose-testnet-onboarding-app.yml new file mode 100644 index 0000000..a5646bb --- /dev/null +++ b/stack-orchestrator/compose/docker-compose-testnet-onboarding-app.yml @@ -0,0 +1,26 @@ +services: + # Builds and serves the React testnet-onboarding-app + testnet-onboarding-app: + restart: unless-stopped + image: cerc/testnet-onboarding-app:local + environment: + CERC_SCRIPT_DEBUG: ${CERC_SCRIPT_DEBUG} + WALLET_CONNECT_ID: ${WALLET_CONNECT_ID} + CERC_LACONICD_CHAIN_ID: ${CERC_LACONICD_CHAIN_ID:-laconic_9000-1} + CERC_REGISTRY_GQL_ENDPOINT: ${CERC_REGISTRY_GQL_ENDPOINT:-http://localhost:9473/api} + CERC_LACONICD_RPC_ENDPOINT: ${CERC_LACONICD_RPC_ENDPOINT:-http://localhost:26657} + CERC_LACONICD_DENOM: ${CERC_LACONICD_DENOM:-photon} + CERC_FAUCET_ENDPOINT: ${CERC_FAUCET_ENDPOINT:-http://localhost:4000} + CERC_WALLET_META_URL: ${CERC_WALLET_META_URL:-http://localhost:3000} + working_dir: /scripts + command: ["bash", "onboarding-app-start.sh"] + volumes: + - ../config/app/onboarding-app-start.sh:/scripts/onboarding-app-start.sh + ports: + - "80" + healthcheck: + test: ["CMD", "nc", "-vz", "localhost", "80"] + interval: 20s + timeout: 5s + retries: 15 + start_period: 10s diff --git a/stack-orchestrator/config/app/onboarding-app-start.sh b/stack-orchestrator/config/app/onboarding-app-start.sh new file mode 100644 index 0000000..b9d8011 --- /dev/null +++ b/stack-orchestrator/config/app/onboarding-app-start.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +set -e +if [ -n "$CERC_SCRIPT_DEBUG" ]; then + set -x +fi + +echo "Using the following env variables:" +echo "WALLET_CONNECT_ID: ${WALLET_CONNECT_ID}" +echo "CERC_LACONICD_CHAIN_ID: ${CERC_LACONICD_CHAIN_ID}" +echo "CERC_REGISTRY_GQL_ENDPOINT: ${CERC_REGISTRY_GQL_ENDPOINT}" +echo "CERC_LACONICD_RPC_ENDPOINT: ${CERC_LACONICD_RPC_ENDPOINT}" +echo "CERC_LACONICD_DENOM: ${CERC_LACONICD_DENOM}" +echo "CERC_FAUCET_ENDPOINT: ${CERC_FAUCET_ENDPOINT}" +echo "CERC_WALLET_META_URL: ${CERC_WALLET_META_URL}" + +# Build with required env +REACT_APP_WALLET_CONNECT_ID= $WALLET_CONNECT_ID \ +REACT_APP_ETHEREUM_MAINNET_CHAIN_ID=1 \ +REACT_APP_LACONICD_CHAIN_ID=$LACONICD_CHAIN_ID \ +REACT_APP_REGISTRY_GQL_ENDPOINT=$REGISTRY_GQL_ENDPOINT \ +REACT_APP_LACONICD_RPC_ENDPOINT=$LACONICD_RPC_ENDPOINT \ +REACT_APP_LACONICD_DENOM=$LACONICD_DENOM \ +REACT_APP_FAUCET_ENDPOINT=$FAUCET_ENDPOINT \ +REACT_APP_WALLET_META_URL=$WALLET_META_URL \ +yarn build + +http-server -p 80 /app/build diff --git a/stack-orchestrator/container-build/cerc-testnet-onboarding-app/Dockerfile b/stack-orchestrator/container-build/cerc-testnet-onboarding-app/Dockerfile new file mode 100644 index 0000000..e00ac66 --- /dev/null +++ b/stack-orchestrator/container-build/cerc-testnet-onboarding-app/Dockerfile @@ -0,0 +1,43 @@ +# Originally from: https://github.com/devcontainers/images/blob/main/src/javascript-node/.devcontainer/Dockerfile +# [Choice] Node.js version (use -bullseye variants on local arm64/Apple Silicon): 18, 16, 14, 18-bullseye, 16-bullseye, 14-bullseye, 18-buster, 16-buster, 14-buster +ARG VARIANT=18-bullseye +FROM node:${VARIANT} + +ARG USERNAME=node +ARG NPM_GLOBAL=/usr/local/share/npm-global + +# Add NPM global to PATH. +ENV PATH=${NPM_GLOBAL}/bin:${PATH} +# Prevents npm from printing version warnings +ENV NPM_CONFIG_UPDATE_NOTIFIER=false + +RUN \ + # Configure global npm install location, use group to adapt to UID/GID changes + if ! cat /etc/group | grep -e "^npm:" > /dev/null 2>&1; then groupadd -r npm; fi \ + && usermod -a -G npm ${USERNAME} \ + && umask 0002 \ + && mkdir -p ${NPM_GLOBAL} \ + && touch /usr/local/etc/npmrc \ + && chown ${USERNAME}:npm ${NPM_GLOBAL} /usr/local/etc/npmrc \ + && chmod g+s ${NPM_GLOBAL} \ + && npm config -g set prefix ${NPM_GLOBAL} \ + && su ${USERNAME} -c "npm config -g set prefix ${NPM_GLOBAL}" \ + # Install eslint + && su ${USERNAME} -c "umask 0002 && npm install -g eslint" \ + && npm cache clean --force > /dev/null 2>&1 + +# Install additional OS packages. +RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ + && apt-get -y install --no-install-recommends jq bash netcat + +RUN mkdir -p /scripts + +# Install simple web server for now (use nginx perhaps later) +RUN yarn global add http-server + +WORKDIR /app +COPY . . +RUN yarn install + +# Expose port for http +EXPOSE 80 diff --git a/stack-orchestrator/stacks/onboarding-app/README.md b/stack-orchestrator/stacks/onboarding-app/README.md new file mode 100644 index 0000000..9928880 --- /dev/null +++ b/stack-orchestrator/stacks/onboarding-app/README.md @@ -0,0 +1,93 @@ +# onboarding-app + +Instructions for running the `testnet-onboarding-app` using [laconic-so](https://git.vdb.to/cerc-io/stack-orchestrator) + +## Setup + +* Clone the stack repo: + + ```bash + laconic-so fetch-stack git.vdb.to/cerc-io/testnet-onboarding-app-stack + ``` + +* Setup required repositories: + + ```bash + laconic-so --stack ~/cerc/testnet-onboarding-app-stack/stack-orchestrator/stacks/onboarding-app setup-repositories + ``` + +* Build the container image: + + ```bash + laconic-so --stack ~/cerc/testnet-onboarding-app-stack/stack-orchestrator/stacks/onboarding-app build-containers + ``` + + This should create the `cerc/testnet-onboarding-app` image locally + +## Create a deployment + +* Create a spec file for the deployment: + + ```bash + laconic-so --stack ~/cerc/testnet-onboarding-app-stack/stack-orchestrator/stacks/onboarding-app deploy init --output onboarding-app-spec.yml + ``` + +* Edit `network` in the spec file to map container ports to host ports as required: + + ```bash + network: + ports: + testnet-onboarding-app: + - '3000:80' + ``` + +* Create a deployment from the spec file: + + ```bash + laconic-so --stack ~/cerc/testnet-onboarding-app-stack/stack-orchestrator/stacks/onboarding-app deploy create --spec-file onboarding-app-spec.yml --deployment-dir onboarding-app-deployment + ``` + +## Configuration + +* Inside the `onboarding-app-deployment` deployment directory, open `config.env` file and set following env variables: + + ```bash + # WalletConnect project ID, same should be used in the laconic-wallet + WALLET_CONNECT_ID= + + # Optional + + # laconicd chain id (default: laconic_9000-1) + CERC_LACONICD_CHAIN_ID= + + # laconicd registry GQL endpoint (default: http://localhost:9473/api) + CERC_REGISTRY_GQL_ENDPOINT= + + # laconicd RPC endpoint (default: http://laconicd:26657) + CERC_LACONICD_RPC_ENDPOINT= + + # laconicd token denom (default: photon) + CERC_LACONICD_DENOM= + + # Faucet RPC endpoint (default: http://localhost:4000) + CERC_FAUCET_ENDPOINT= + + # laconic wallet meta URL (default: http://localhost:3000) + CERC_WALLET_META_URL= + ``` + +## Start the deployment + + ```bash + laconic-so deployment --dir onboarding-app-deployment start + ``` + + Open the app in a browser at + +## Clean up + +* Stop the deployment: + + ```bash + laconic-so deployment --dir onboarding-app-deployment stop + ``` diff --git a/stack-orchestrator/stacks/onboarding-app/stack.yml b/stack-orchestrator/stacks/onboarding-app/stack.yml new file mode 100644 index 0000000..630d153 --- /dev/null +++ b/stack-orchestrator/stacks/onboarding-app/stack.yml @@ -0,0 +1,9 @@ +version: "1.0" +name: onboarding-app +description: "Testnet onboarding app" +repos: + - git.vdb.to/cerc-io/testnet-onboarding-app +containers: + - cerc/testnet-onboarding-app +pods: + - testnet-onboarding-app