From c7310b8e6d50fec3fb11e4c946582710661de370 Mon Sep 17 00:00:00 2001 From: prathamesh0 <42446521+prathamesh0@users.noreply.github.com> Date: Fri, 26 Jul 2024 16:02:27 +0530 Subject: [PATCH] Add a laconic-wallet-web stack (#3) * Add a laconic-wallet-web stack * Restructure stack folder * Add transform-modules-commonjs babel plugin --- .dockerignore | 1 + config-overrides.js | 3 +- package.json | 1 + stack/README.md | 3 + .../docker-compose-laconic-wallet-web.yml | 21 +++++ stack/stack-orchestrator/config/app/run.sh | 19 +++++ .../cerc-laconic-wallet-web/Dockerfile | 43 +++++++++++ .../cerc-laconic-wallet-web/build.sh | 11 +++ .../stack/laconic-wallet-web/README.md | 76 +++++++++++++++++++ .../stack/laconic-wallet-web/stack.yml | 7 ++ 10 files changed, 184 insertions(+), 1 deletion(-) create mode 100644 .dockerignore create mode 100644 stack/README.md create mode 100644 stack/stack-orchestrator/compose/docker-compose-laconic-wallet-web.yml create mode 100755 stack/stack-orchestrator/config/app/run.sh create mode 100644 stack/stack-orchestrator/container-build/cerc-laconic-wallet-web/Dockerfile create mode 100755 stack/stack-orchestrator/container-build/cerc-laconic-wallet-web/build.sh create mode 100644 stack/stack-orchestrator/stack/laconic-wallet-web/README.md create mode 100644 stack/stack-orchestrator/stack/laconic-wallet-web/stack.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..b69c736 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +stack diff --git a/config-overrides.js b/config-overrides.js index ee526a6..d10f3ea 100644 --- a/config-overrides.js +++ b/config-overrides.js @@ -21,7 +21,8 @@ module.exports = function override(config, env) { ], plugins: [ "@babel/plugin-proposal-class-properties", - "@babel/plugin-proposal-object-rest-spread" + "@babel/plugin-proposal-object-rest-spread", + "@babel/plugin-transform-modules-commonjs" ] } } diff --git a/package.json b/package.json index 2390ea4..59f4e8f 100644 --- a/package.json +++ b/package.json @@ -70,6 +70,7 @@ ] }, "devDependencies": { + "@babel/plugin-transform-modules-commonjs": "^7.24.8", "@types/lodash": "^4.17.7", "@types/node": "^16.7.13", "@types/react": "^18.0.0", diff --git a/stack/README.md b/stack/README.md new file mode 100644 index 0000000..c70e35c --- /dev/null +++ b/stack/README.md @@ -0,0 +1,3 @@ +# laconic-wallet-web-stack + +[laconic-wallet-web stack documentation](./stack-orchestrator/stack/laconic-wallet-web/README.md) diff --git a/stack/stack-orchestrator/compose/docker-compose-laconic-wallet-web.yml b/stack/stack-orchestrator/compose/docker-compose-laconic-wallet-web.yml new file mode 100644 index 0000000..785058b --- /dev/null +++ b/stack/stack-orchestrator/compose/docker-compose-laconic-wallet-web.yml @@ -0,0 +1,21 @@ +services: + # Builds and serves the React laconic-wallet-web app + laconic-wallet-web: + restart: unless-stopped + image: cerc/laconic-wallet-web:local + environment: + CERC_SCRIPT_DEBUG: ${CERC_SCRIPT_DEBUG} + WALLET_CONNECT_ID: ${WALLET_CONNECT_ID} + CERC_DEFAULT_GAS_PRICE: ${CERC_DEFAULT_GAS_PRICE:-0.025} + CERC_GAS_ADJUSTMENT: ${CERC_GAS_ADJUSTMENT:-2} + command: ["bash", "/scripts/run.sh"] + volumes: + - ../config/app/run.sh:/scripts/run.sh + ports: + - "80" + healthcheck: + test: ["CMD", "nc", "-vz", "localhost", "80"] + interval: 20s + timeout: 5s + retries: 15 + start_period: 10s diff --git a/stack/stack-orchestrator/config/app/run.sh b/stack/stack-orchestrator/config/app/run.sh new file mode 100755 index 0000000..2a1b6f3 --- /dev/null +++ b/stack/stack-orchestrator/config/app/run.sh @@ -0,0 +1,19 @@ +#!/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_DEFAULT_GAS_PRICE: ${CERC_DEFAULT_GAS_PRICE}" +echo "CERC_GAS_ADJUSTMENT: ${CERC_GAS_ADJUSTMENT}" + +# Build with required env +REACT_APP_WALLET_CONNECT_PROJECT_ID=$WALLET_CONNECT_ID \ +REACT_APP_DEFAULT_GAS_PRICE=$DEFAULT_GAS_PRICE \ +REACT_APP_GAS_ADJUSTMENT=$GAS_ADJUSTMENT \ +yarn build + +http-server -p 80 /app/build diff --git a/stack/stack-orchestrator/container-build/cerc-laconic-wallet-web/Dockerfile b/stack/stack-orchestrator/container-build/cerc-laconic-wallet-web/Dockerfile new file mode 100644 index 0000000..e00ac66 --- /dev/null +++ b/stack/stack-orchestrator/container-build/cerc-laconic-wallet-web/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/stack-orchestrator/container-build/cerc-laconic-wallet-web/build.sh b/stack/stack-orchestrator/container-build/cerc-laconic-wallet-web/build.sh new file mode 100755 index 0000000..c10643e --- /dev/null +++ b/stack/stack-orchestrator/container-build/cerc-laconic-wallet-web/build.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash +# Build cerc/laconic-wallet-web + +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/laconic-wallet-web:local ${build_command_args} -f ${SCRIPT_DIR}/Dockerfile ${CERC_REPO_BASE_DIR}/laconic-wallet-web diff --git a/stack/stack-orchestrator/stack/laconic-wallet-web/README.md b/stack/stack-orchestrator/stack/laconic-wallet-web/README.md new file mode 100644 index 0000000..1e36827 --- /dev/null +++ b/stack/stack-orchestrator/stack/laconic-wallet-web/README.md @@ -0,0 +1,76 @@ +# laconic-wallet-web + +Instructions for running the `laconic-wallet-web` 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/laconic-wallet-web + ``` + +* Build the container image: + + ```bash + laconic-so --stack ~/cerc/laconic-wallet-web/stack/stack-orchestrator/stack/laconic-wallet-web build-containers + ``` + + This should create the `cerc/laconic-wallet-web` image locally + +## Create a deployment + +* Create a spec file for the deployment: + + ```bash + laconic-so --stack ~/cerc/laconic-wallet-web/stack/stack-orchestrator/stack/laconic-wallet-web deploy init --output laconic-wallet-web-spec.yml + ``` + +* Edit `network` in the spec file to map container ports to host ports as required: + + ```bash + network: + ports: + laconic-wallet-web: + - '3000:80' + ``` + +* Create a deployment from the spec file: + + ```bash + laconic-so --stack ~/cerc/laconic-wallet-web/stack/stack-orchestrator/stack/laconic-wallet-web deploy create --spec-file laconic-wallet-web-spec.yml --deployment-dir laconic-wallet-web-deployment + ``` + +## Configuration + +* Inside the `laconic-wallet-web-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 + + # Default gas price for txs (default: 0.025) + CERC_DEFAULT_GAS_PRICE= + + # Gas adjustment (default: 2) + # Reference: https://github.com/cosmos/cosmos-sdk/issues/16020 + CERC_GAS_ADJUSTMENT= + ``` + +## Start the deployment + +```bash +laconic-so deployment --dir laconic-wallet-web-deployment start +``` + +Open the wallet app in a browser at + +## Clean up + +* Stop the deployment: + + ```bash + laconic-so deployment --dir laconic-wallet-web-deployment stop + ``` diff --git a/stack/stack-orchestrator/stack/laconic-wallet-web/stack.yml b/stack/stack-orchestrator/stack/laconic-wallet-web/stack.yml new file mode 100644 index 0000000..380c8fd --- /dev/null +++ b/stack/stack-orchestrator/stack/laconic-wallet-web/stack.yml @@ -0,0 +1,7 @@ +version: "1.0" +name: laconic-wallet-web +description: "Laconic web wallet" +containers: + - cerc/laconic-wallet-web +pods: + - laconic-wallet-web