Add a laconic-wallet-web stack (#3)

* Add a laconic-wallet-web stack

* Restructure stack folder

* Add transform-modules-commonjs babel plugin
This commit is contained in:
prathamesh0 2024-07-26 16:02:27 +05:30 committed by GitHub
parent f554c82149
commit c7310b8e6d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 184 additions and 1 deletions

1
.dockerignore Normal file
View File

@ -0,0 +1 @@
stack

View File

@ -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"
]
}
}

View File

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

3
stack/README.md Normal file
View File

@ -0,0 +1,3 @@
# laconic-wallet-web-stack
[laconic-wallet-web stack documentation](./stack-orchestrator/stack/laconic-wallet-web/README.md)

View File

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

View File

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

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

View File

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

View File

@ -0,0 +1,7 @@
version: "1.0"
name: laconic-wallet-web
description: "Laconic web wallet"
containers:
- cerc/laconic-wallet-web
pods:
- laconic-wallet-web