From 8a22b4fd47bc2bf2ac9ecdcecde292aabae41d38 Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Fri, 26 Jul 2024 10:21:16 +0530 Subject: [PATCH 1/4] 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 -- 2.45.2 From a1b19a2c1b1f1d98acea3009f6097f27c64180a4 Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Fri, 26 Jul 2024 10:53:10 +0530 Subject: [PATCH 2/4] Add script to build app image --- .../docker-compose-testnet-onboarding-app.yml | 3 +-- .../config/app/onboarding-app-start.sh | 14 +++++++------- .../cerc-testnet-onboarding-app/build.sh | 11 +++++++++++ 3 files changed, 19 insertions(+), 9 deletions(-) create mode 100755 stack-orchestrator/container-build/cerc-testnet-onboarding-app/build.sh diff --git a/stack-orchestrator/compose/docker-compose-testnet-onboarding-app.yml b/stack-orchestrator/compose/docker-compose-testnet-onboarding-app.yml index a5646bb..8ef20ea 100644 --- a/stack-orchestrator/compose/docker-compose-testnet-onboarding-app.yml +++ b/stack-orchestrator/compose/docker-compose-testnet-onboarding-app.yml @@ -12,8 +12,7 @@ services: 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"] + command: ["bash", "/scripts/onboarding-app-start.sh"] volumes: - ../config/app/onboarding-app-start.sh:/scripts/onboarding-app-start.sh ports: diff --git a/stack-orchestrator/config/app/onboarding-app-start.sh b/stack-orchestrator/config/app/onboarding-app-start.sh index b9d8011..09ff96c 100644 --- a/stack-orchestrator/config/app/onboarding-app-start.sh +++ b/stack-orchestrator/config/app/onboarding-app-start.sh @@ -15,14 +15,14 @@ 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_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 \ +REACT_APP_LACONICD_CHAIN_ID=$CERC_LACONICD_CHAIN_ID \ +REACT_APP_REGISTRY_GQL_ENDPOINT=$CERC_REGISTRY_GQL_ENDPOINT \ +REACT_APP_LACONICD_RPC_ENDPOINT=$CERC_LACONICD_RPC_ENDPOINT \ +REACT_APP_LACONICD_DENOM=$CERC_LACONICD_DENOM \ +REACT_APP_FAUCET_ENDPOINT=$CERC_FAUCET_ENDPOINT \ +REACT_APP_WALLET_META_URL=$CERC_WALLET_META_URL \ yarn build http-server -p 80 /app/build diff --git a/stack-orchestrator/container-build/cerc-testnet-onboarding-app/build.sh b/stack-orchestrator/container-build/cerc-testnet-onboarding-app/build.sh new file mode 100755 index 0000000..bce1018 --- /dev/null +++ b/stack-orchestrator/container-build/cerc-testnet-onboarding-app/build.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash +# Build cerc/testnet-onboarding-app + +source ${CERC_CONTAINER_BASE_DIR}/build-base.sh + +# See: https://stackoverflow.com/a/246128/1701505 +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + +CERC_NPM_REGISTRY_URL="https://git.vdb.to/api/packages/cerc-io/npm/" + +docker build -t cerc/testnet-onboarding-app:local ${build_command_args} -f ${SCRIPT_DIR}/Dockerfile ${CERC_REPO_BASE_DIR}/testnet-onboarding-app -- 2.45.2 From ee1fb9b7b80d10e8a694a057b19ae1d851a3e139 Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Fri, 26 Jul 2024 10:57:59 +0530 Subject: [PATCH 3/4] Add instructions to root README --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index a1c7fc3..ff894c3 100644 --- a/README.md +++ b/README.md @@ -1 +1,6 @@ # testnet-onboarding-app-stack + +Stacks to run Laconic testnet onboarding app and onboarding API + +* [onboarding-app stack documentation](stack-orchestrator/stacks/onboarding-app/README.md) +* [onboarding-api stack documentation](stack-orchestrator/stacks/onboarding-api/README.md) -- 2.45.2 From 5474625e22b010f82ca2e99d1aa80ed9cd5843d1 Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Fri, 26 Jul 2024 11:55:41 +0530 Subject: [PATCH 4/4] Add a stack for testnet-onboarding-api --- .../docker-compose-testnet-onboarding-api.yml | 21 ++++ stack-orchestrator/config/api/run.sh | 18 +++ .../config/app/onboarding-app-start.sh | 0 .../cerc-testnet-onboarding-api/build.sh | 5 + .../stacks/onboarding-api/README.md | 107 ++++++++++++++++++ .../stacks/onboarding-api/stack.yml | 9 ++ 6 files changed, 160 insertions(+) create mode 100644 stack-orchestrator/compose/docker-compose-testnet-onboarding-api.yml create mode 100755 stack-orchestrator/config/api/run.sh mode change 100644 => 100755 stack-orchestrator/config/app/onboarding-app-start.sh create mode 100755 stack-orchestrator/container-build/cerc-testnet-onboarding-api/build.sh create mode 100644 stack-orchestrator/stacks/onboarding-api/README.md create mode 100644 stack-orchestrator/stacks/onboarding-api/stack.yml diff --git a/stack-orchestrator/compose/docker-compose-testnet-onboarding-api.yml b/stack-orchestrator/compose/docker-compose-testnet-onboarding-api.yml new file mode 100644 index 0000000..2d9fc68 --- /dev/null +++ b/stack-orchestrator/compose/docker-compose-testnet-onboarding-api.yml @@ -0,0 +1,21 @@ +services: + testnet-onboarding-api: + restart: unless-stopped + image: cerc/testnet-onboarding-api:local + environment: + CERC_SCRIPT_DEBUG: ${CERC_SCRIPT_DEBUG} + SUMSUB_APP_TOKEN: ${SUMSUB_APP_TOKEN} + SUMSUB_SECRET_KEY: ${SUMSUB_SECRET_KEY} + KYC_LEVEL: ${KYC_LEVEL:-basic-kyc-level} + TTL_IN_SECS: ${TTL_IN_SECS:-600} + command: ["bash", "./run.sh"] + volumes: + - ../config/api/run.sh:/app/run.sh + ports: + - 3000 + healthcheck: + test: ["CMD", "nc", "-vz", "127.0.0.1", "3000"] + interval: 10s + timeout: 5s + retries: 10 + start_period: 5s diff --git a/stack-orchestrator/config/api/run.sh b/stack-orchestrator/config/api/run.sh new file mode 100755 index 0000000..41bbb5f --- /dev/null +++ b/stack-orchestrator/config/api/run.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +set -e +if [ -n "$CERC_SCRIPT_DEBUG" ]; then + set -x +fi + +echo "Using the following env variables:" +echo "SUMSUB_APP_TOKEN: ${SUMSUB_APP_TOKEN}" +echo "SUMSUB_SECRET_KEY: ${SUMSUB_SECRET_KEY}" +echo "KYC_LEVEL: ${KYC_LEVEL}" +echo "TTL_IN_SECS: ${TTL_IN_SECS}" + +SUMSUB_APP_TOKEN=$SUMSUB_APP_TOKEN \ +SUMSUB_SECRET_KEY=$SUMSUB_SECRET_KEY \ +KYC_LEVEL=$KYC_LEVEL \ +TTL_IN_SECS=$TTL_IN_SECS \ +node dist/index.js diff --git a/stack-orchestrator/config/app/onboarding-app-start.sh b/stack-orchestrator/config/app/onboarding-app-start.sh old mode 100644 new mode 100755 diff --git a/stack-orchestrator/container-build/cerc-testnet-onboarding-api/build.sh b/stack-orchestrator/container-build/cerc-testnet-onboarding-api/build.sh new file mode 100755 index 0000000..bb021fc --- /dev/null +++ b/stack-orchestrator/container-build/cerc-testnet-onboarding-api/build.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash +# Build cerc/testnet-onboarding-api + +source ${CERC_CONTAINER_BASE_DIR}/build-base.sh +docker build -t cerc/testnet-onboarding-api:local ${build_command_args} ${CERC_REPO_BASE_DIR}/testnet-onboarding-api diff --git a/stack-orchestrator/stacks/onboarding-api/README.md b/stack-orchestrator/stacks/onboarding-api/README.md new file mode 100644 index 0000000..3532434 --- /dev/null +++ b/stack-orchestrator/stacks/onboarding-api/README.md @@ -0,0 +1,107 @@ +# onboarding-api + +Instructions for running the `testnet-onboarding-api` 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-api setup-repositories + ``` + +* Build the container image: + + ```bash + laconic-so --stack ~/cerc/testnet-onboarding-app-stack/stack-orchestrator/stacks/onboarding-api build-containers + ``` + + This should create the `cerc/testnet-onboarding-api` 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-api deploy init --output onboarding-api-spec.yml + ``` + +* Edit `network` in the spec file to map container ports to host ports as required: + + ```bash + network: + ports: + testnet-onboarding-api: + - '3000:3000' + ``` + +* Create a deployment from the spec file: + + ```bash + laconic-so --stack ~/cerc/testnet-onboarding-app-stack/stack-orchestrator/stacks/onboarding-api deploy create --spec-file onboarding-api-spec.yml --deployment-dir onboarding-api-deployment + ``` + +## Configuration + +* Inside the `onboarding-api-deployment` deployment directory, open `config.env` file and set following env variables: + + ```bash + # Your sumsub application token + SUMSUB_APP_TOKEN= + + # Your sumsub secret key + SUMSUB_SECRET_KEY= + + # Optional + + # KYC level of access token being generated (default: basic-kyc-level) + KYC_LEVEL= + + # TTL for the generated access token in seconds (default: 600) + TTL_IN_SECS= + ``` + +## Start the deployment + + ```bash + laconic-so deployment --dir onboarding-api-deployment start + ``` + +## Check status + +* To list down and monitor the running container: + + ```bash + # With status + docker ps + + # Check logs for the server + laconic-so deployment --dir onboarding-api-deployment logs -f testnet-onboarding-api + ``` + +## Run + +* Generate an access token for a user: + + ```bash + curl -X POST http://localhost:3000/generate-token \ + -H "Content-Type: application/json" \ + -d '{"userId": "JamesBond007"}' + + # Expected output: + # {"token":"generated-access-token"} + ``` + +## Clean up + +* Stop the deployment: + + ```bash + laconic-so deployment --dir onboarding-api-deployment stop + ``` diff --git a/stack-orchestrator/stacks/onboarding-api/stack.yml b/stack-orchestrator/stacks/onboarding-api/stack.yml new file mode 100644 index 0000000..f027b4b --- /dev/null +++ b/stack-orchestrator/stacks/onboarding-api/stack.yml @@ -0,0 +1,9 @@ +version: "1.0" +name: onboarding-api +description: "Testnet onboarding API" +repos: + - git.vdb.to/cerc-io/testnet-onboarding-api +containers: + - cerc/testnet-onboarding-api +pods: + - testnet-onboarding-api -- 2.45.2