Add stacks for testnet-onboarding-app and testnet-onboarding-api (#1)

Part of  [laconicd testnet validator enrollment](https://www.notion.so/laconicd-testnet-validator-enrollment-6fc1d3cafcc64fef8c5ed3affa27c675) and [Sumsub KYC integration in onboarding app](https://www.notion.so/Sumsub-KYC-integration-in-onboarding-app-607b598c9c1d4d12adc71725e2ab5e7e)

Reviewed-on: #1
Co-authored-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
Co-committed-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
This commit is contained in:
Prathamesh Musale 2024-07-26 06:31:40 +00:00 committed by nabarun
parent ae2d6d25ed
commit 1e3e592b10
12 changed files with 374 additions and 0 deletions

View File

@ -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)

View File

@ -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

View File

@ -0,0 +1,25 @@
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}
command: ["bash", "/scripts/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

View File

@ -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

View File

@ -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=$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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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
```

View File

@ -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

View File

@ -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 <http://localhost:3000>
## Clean up
* Stop the deployment:
```bash
laconic-so deployment --dir onboarding-app-deployment stop
```

View File

@ -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