From 5c64ed0ea5a9aa8b2aee25b0c882333cded1e554 Mon Sep 17 00:00:00 2001 From: Shreerang Kale Date: Thu, 24 Oct 2024 15:01:41 +0530 Subject: [PATCH 1/4] Add stack for shopify faucet --- .../docker-compose-laconic-shopify-faucet.yml | 27 +++++++++++++++++++ .../config-template.toml | 12 +++++++++ .../laconic-shopify-faucet/start-faucet.sh | 26 ++++++++++++++++++ .../cerc-laconic-shopify-faucet/build.sh | 5 ++++ .../stacks/laconic-shopify-faucet/README.md | 1 + .../stacks/laconic-shopify-faucet/stack.yml | 9 +++++++ 6 files changed, 80 insertions(+) create mode 100644 stack-orchestrator/compose/docker-compose-laconic-shopify-faucet.yml create mode 100644 stack-orchestrator/config/laconic-shopify-faucet/config-template.toml create mode 100755 stack-orchestrator/config/laconic-shopify-faucet/start-faucet.sh create mode 100755 stack-orchestrator/container-build/cerc-laconic-shopify-faucet/build.sh create mode 100644 stack-orchestrator/stacks/laconic-shopify-faucet/README.md create mode 100644 stack-orchestrator/stacks/laconic-shopify-faucet/stack.yml diff --git a/stack-orchestrator/compose/docker-compose-laconic-shopify-faucet.yml b/stack-orchestrator/compose/docker-compose-laconic-shopify-faucet.yml new file mode 100644 index 0000000..8aea38d --- /dev/null +++ b/stack-orchestrator/compose/docker-compose-laconic-shopify-faucet.yml @@ -0,0 +1,27 @@ +services: + faucet: + restart: unless-stopped + image: cerc/laconic-shopify-faucet:local + command: ["bash", "-c", "./start-faucet.sh"] + environment: + CERC_SCRIPT_DEBUG: ${CERC_SCRIPT_DEBUG} + CERC_LACONICD_RPC_ENDPOINT: ${CERC_LACONICD_RPC_ENDPOINT:-http://laconicd:26657} + CERC_FAUCET_KEY: ${CERC_FAUCET_KEY} + CERC_LACONICD_CHAIN_ID: ${CERC_LACONICD_CHAIN_ID:-laconic_9000-1} + volumes: + - faucet-data:/app/db + - ../config/laconic-shopify-faucet/start-faucet.sh:/app/start-faucet.sh + - ../config/laconic-shopify-faucet/config-template.toml:/app/environments/config-template.toml + ports: + - 3000 + healthcheck: + test: ["CMD", "nc", "-vz", "127.0.0.1", "3000"] + interval: 10s + timeout: 5s + retries: 10 + start_period: 5s + extra_hosts: + - "host.docker.internal:host-gateway" + +volumes: + faucet-data: diff --git a/stack-orchestrator/config/laconic-shopify-faucet/config-template.toml b/stack-orchestrator/config/laconic-shopify-faucet/config-template.toml new file mode 100644 index 0000000..1a4e570 --- /dev/null +++ b/stack-orchestrator/config/laconic-shopify-faucet/config-template.toml @@ -0,0 +1,12 @@ +[upstream] + rpcEndpoint = "REPLACE_WITH_CERC_LACONICD_RPC_ENDPOINT" + chainId = "laconic_9000-1" + denom = "alnt" + prefix = "laconic" + gasPrice = "1" + faucetKey = "REPLACE_WITH_CERC_FAUCET_KEY" + +[server] + port=3000 + enableRateLimit=false + dbDir = "db" diff --git a/stack-orchestrator/config/laconic-shopify-faucet/start-faucet.sh b/stack-orchestrator/config/laconic-shopify-faucet/start-faucet.sh new file mode 100755 index 0000000..cdf2d02 --- /dev/null +++ b/stack-orchestrator/config/laconic-shopify-faucet/start-faucet.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +set -e +set -u +if [ -n "$CERC_SCRIPT_DEBUG" ]; then + set -x +fi + +config_template=$(cat environments/config-template.toml) +target_config="./environments/local.toml" + +# Check if faucet key is set +if [ -z "${CERC_FAUCET_KEY:-}" ]; then + echo "Error: CERC_FAUCET_KEY is not set. Exiting..." + exit 1 +fi + +echo "Using laconicd RPC endpoint: $CERC_LACONICD_RPC_ENDPOINT" + +FAUCET_CONFIG=$(echo "$config_template" | \ + sed -E "s|REPLACE_WITH_CERC_FAUCET_KEY|${CERC_FAUCET_KEY}|g; \ + s|REPLACE_WITH_CERC_LACONICD_RPC_ENDPOINT|${CERC_LACONICD_RPC_ENDPOINT}|g; ") + +echo "$FAUCET_CONFIG" > $target_config +echo "Starting faucet..." +node dist/index.js diff --git a/stack-orchestrator/container-build/cerc-laconic-shopify-faucet/build.sh b/stack-orchestrator/container-build/cerc-laconic-shopify-faucet/build.sh new file mode 100755 index 0000000..07186a4 --- /dev/null +++ b/stack-orchestrator/container-build/cerc-laconic-shopify-faucet/build.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +# Build cerc/laconic-shopify-faucet +source ${CERC_CONTAINER_BASE_DIR}/build-base.sh +docker build -t cerc/laconic-shopify-faucet:local ${build_command_args} ${CERC_REPO_BASE_DIR}/laconic-faucet diff --git a/stack-orchestrator/stacks/laconic-shopify-faucet/README.md b/stack-orchestrator/stacks/laconic-shopify-faucet/README.md new file mode 100644 index 0000000..ea93e17 --- /dev/null +++ b/stack-orchestrator/stacks/laconic-shopify-faucet/README.md @@ -0,0 +1 @@ +# Laconic Shopify Faucet diff --git a/stack-orchestrator/stacks/laconic-shopify-faucet/stack.yml b/stack-orchestrator/stacks/laconic-shopify-faucet/stack.yml new file mode 100644 index 0000000..800a342 --- /dev/null +++ b/stack-orchestrator/stacks/laconic-shopify-faucet/stack.yml @@ -0,0 +1,9 @@ +version: "1.0" +name: laconic-shopify-faucet +description: "Faucet for shopify app" +repos: + - git.vdb.to/cerc-io/laconic-faucet@sk-shopify-faucet +containers: + - cerc/laconic-shopify-faucet +pods: + - laconic-faucet -- 2.45.2 From a3c8cd68e86d3114cfefd829a2e4ce7d2497fdc0 Mon Sep 17 00:00:00 2001 From: Shreerang Kale Date: Thu, 24 Oct 2024 15:46:45 +0530 Subject: [PATCH 2/4] Update shopify-faucet pod name --- stack-orchestrator/stacks/laconic-shopify-faucet/stack.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stack-orchestrator/stacks/laconic-shopify-faucet/stack.yml b/stack-orchestrator/stacks/laconic-shopify-faucet/stack.yml index 800a342..0038b49 100644 --- a/stack-orchestrator/stacks/laconic-shopify-faucet/stack.yml +++ b/stack-orchestrator/stacks/laconic-shopify-faucet/stack.yml @@ -2,8 +2,8 @@ version: "1.0" name: laconic-shopify-faucet description: "Faucet for shopify app" repos: - - git.vdb.to/cerc-io/laconic-faucet@sk-shopify-faucet + - git.vdb.to/cerc-io/laconic-faucet@shopify-faucet containers: - cerc/laconic-shopify-faucet pods: - - laconic-faucet + - laconic-shopify-faucet -- 2.45.2 From 9ef02bf8f0b973b3519886819bdd95f6a5fad609 Mon Sep 17 00:00:00 2001 From: Shreerang Kale Date: Thu, 24 Oct 2024 15:55:38 +0530 Subject: [PATCH 3/4] Add README for laconic-shopify-faucet stack --- .../stacks/laconic-shopify-faucet/README.md | 116 +++++++++++++++++- .../stacks/laconic-shopify-faucet/stack.yml | 2 +- 2 files changed, 116 insertions(+), 2 deletions(-) diff --git a/stack-orchestrator/stacks/laconic-shopify-faucet/README.md b/stack-orchestrator/stacks/laconic-shopify-faucet/README.md index ea93e17..965dc07 100644 --- a/stack-orchestrator/stacks/laconic-shopify-faucet/README.md +++ b/stack-orchestrator/stacks/laconic-shopify-faucet/README.md @@ -1 +1,115 @@ -# Laconic Shopify Faucet +# laconic-shopify-faucet + +Instructions for running the laconic faucet + +## Setup + +* Clone the stack repo: + + ```bash + laconic-so fetch-stack git.vdb.to/cerc-io/testnet-laconicd-stack + ``` + +* Clone the laconic-faucet respository: + + ```bash + laconic-so --stack ~/cerc/testnet-laconicd-stack/stack-orchestrator/stacks/laconic-shopify-faucet setup-repositories + ``` + +* Build the container image: + + ```bash + laconic-so --stack ~/cerc/testnet-laconicd-stack/stack-orchestrator/stacks/laconic-shopify-faucet build-containers + ``` + + This should create the `cerc/laconic-shopify-faucet` image locally + +## Create a deployment + +* Create a spec file for the deployment: + + ```bash + laconic-so --stack ~/cerc/testnet-laconicd-stack/stack-orchestrator/stacks/laconic-shopify-faucet deploy init --output laconic-shopify-faucet-spec.yml + ``` + +* Edit `network` in the spec file to map container ports to host ports as required: + + ```bash + network: + ports: + faucet: + - '3000:3000' + ``` + +* Create a deployment from the spec file: + + ```bash + laconic-so --stack ~/cerc/testnet-laconicd-stack/stack-orchestrator/stacks/laconic-shopify-faucet deploy create --spec-file laconic-shopify-faucet-spec.yml --deployment-dir laconic-shopify-faucet-deployment + ``` + +## Configuration + +* Inside the `laconic-shopify-faucet-deployment` deployment directory, open `config.env` file and set following env variables: + + ```bash + # Private key of a funded faucet account + CERC_FAUCET_KEY= + + # Optional + + # laconicd RPC endpoint (default: http://laconicd:26657) + CERC_LACONICD_RPC_ENDPOINT= + + # laconicd chain id (default: laconic_9000-1) + CERC_LACONICD_CHAIN_ID= + ``` + +## Start the deployment + + ```bash + laconic-so deployment --dir laconic-shopify-faucet-deployment start + ``` + +## Check status + +* To list down and monitor the running container: + + ```bash + # With status + docker ps + + # Check logs for a container + docker logs -f + ``` + +## Run + +* Request tokens from the faucet for an account: + + ```bash + curl -X POST http://localhost:3000/faucet \ + -H "Content-Type: application/json" \ + -d '{"address": ""}' + + # Expected output: + # {"success":true,"txHash":""} + ``` + +## Clean up + +* Stop the `laconic-shopify-faucet` service running in the background: + + ```bash + # Stop the docker container + laconic-so deployment --dir laconic-shopify-faucet-deployment stop + ``` + +* To stop the service and also delete data: + + ```bash + # Stop the docker containers + laconic-so deployment --dir laconic-shopify-faucet-deployment stop --delete-volumes + + # Remove deployment directory (deployment will have to be recreated for a re-run) + rm -r laconic-shopify-faucet-deployment + ``` diff --git a/stack-orchestrator/stacks/laconic-shopify-faucet/stack.yml b/stack-orchestrator/stacks/laconic-shopify-faucet/stack.yml index 0038b49..86be391 100644 --- a/stack-orchestrator/stacks/laconic-shopify-faucet/stack.yml +++ b/stack-orchestrator/stacks/laconic-shopify-faucet/stack.yml @@ -2,7 +2,7 @@ version: "1.0" name: laconic-shopify-faucet description: "Faucet for shopify app" repos: - - git.vdb.to/cerc-io/laconic-faucet@shopify-faucet + - git.vdb.to/cerc-io/laconic-faucet@shopify containers: - cerc/laconic-shopify-faucet pods: -- 2.45.2 From 392747b15405991d488a9b2d0c6ad1146cfe4497 Mon Sep 17 00:00:00 2001 From: Shreerang Kale Date: Mon, 28 Oct 2024 11:43:20 +0530 Subject: [PATCH 4/4] Make chain ID, prefix and gas price configurable --- .../compose/docker-compose-laconic-shopify-faucet.yml | 2 ++ .../config/laconic-shopify-faucet/config-template.toml | 8 ++++---- .../config/laconic-shopify-faucet/start-faucet.sh | 3 +++ .../stacks/laconic-shopify-faucet/README.md | 6 ++++++ 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/stack-orchestrator/compose/docker-compose-laconic-shopify-faucet.yml b/stack-orchestrator/compose/docker-compose-laconic-shopify-faucet.yml index 8aea38d..0efa442 100644 --- a/stack-orchestrator/compose/docker-compose-laconic-shopify-faucet.yml +++ b/stack-orchestrator/compose/docker-compose-laconic-shopify-faucet.yml @@ -8,6 +8,8 @@ services: CERC_LACONICD_RPC_ENDPOINT: ${CERC_LACONICD_RPC_ENDPOINT:-http://laconicd:26657} CERC_FAUCET_KEY: ${CERC_FAUCET_KEY} CERC_LACONICD_CHAIN_ID: ${CERC_LACONICD_CHAIN_ID:-laconic_9000-1} + CERC_LACONICD_PREFIX: ${CERC_LACONICD_PREFIX:-laconic} + CERC_LACONICD_GAS_PRICE: ${CERC_LACONICD_GAS_PRICE:-1} volumes: - faucet-data:/app/db - ../config/laconic-shopify-faucet/start-faucet.sh:/app/start-faucet.sh diff --git a/stack-orchestrator/config/laconic-shopify-faucet/config-template.toml b/stack-orchestrator/config/laconic-shopify-faucet/config-template.toml index 1a4e570..eca0fc0 100644 --- a/stack-orchestrator/config/laconic-shopify-faucet/config-template.toml +++ b/stack-orchestrator/config/laconic-shopify-faucet/config-template.toml @@ -1,10 +1,10 @@ [upstream] rpcEndpoint = "REPLACE_WITH_CERC_LACONICD_RPC_ENDPOINT" - chainId = "laconic_9000-1" - denom = "alnt" - prefix = "laconic" - gasPrice = "1" + chainId = "REPLACE_WITH_CERC_LACONICD_CHAIN_ID" + prefix = "REPLACE_WITH_CERC_LACONICD_PREFIX" + gasPrice = "REPLACE_WITH_CERC_LACONICD_GAS_PRICE" faucetKey = "REPLACE_WITH_CERC_FAUCET_KEY" + denom = "alnt" [server] port=3000 diff --git a/stack-orchestrator/config/laconic-shopify-faucet/start-faucet.sh b/stack-orchestrator/config/laconic-shopify-faucet/start-faucet.sh index cdf2d02..baea620 100755 --- a/stack-orchestrator/config/laconic-shopify-faucet/start-faucet.sh +++ b/stack-orchestrator/config/laconic-shopify-faucet/start-faucet.sh @@ -19,6 +19,9 @@ echo "Using laconicd RPC endpoint: $CERC_LACONICD_RPC_ENDPOINT" FAUCET_CONFIG=$(echo "$config_template" | \ sed -E "s|REPLACE_WITH_CERC_FAUCET_KEY|${CERC_FAUCET_KEY}|g; \ + s|REPLACE_WITH_CERC_LACONICD_CHAIN_ID|${CERC_LACONICD_CHAIN_ID}|g; \ + s|REPLACE_WITH_CERC_LACONICD_PREFIX|${CERC_LACONICD_PREFIX}|g; \ + s|REPLACE_WITH_CERC_LACONICD_GAS_PRICE|${CERC_LACONICD_GAS_PRICE}|g; \ s|REPLACE_WITH_CERC_LACONICD_RPC_ENDPOINT|${CERC_LACONICD_RPC_ENDPOINT}|g; ") echo "$FAUCET_CONFIG" > $target_config diff --git a/stack-orchestrator/stacks/laconic-shopify-faucet/README.md b/stack-orchestrator/stacks/laconic-shopify-faucet/README.md index 965dc07..8f875c7 100644 --- a/stack-orchestrator/stacks/laconic-shopify-faucet/README.md +++ b/stack-orchestrator/stacks/laconic-shopify-faucet/README.md @@ -62,6 +62,12 @@ Instructions for running the laconic faucet # laconicd chain id (default: laconic_9000-1) CERC_LACONICD_CHAIN_ID= + + # laconicd address prefix (default: laconic) + CERC_LACONICD_PREFIX= + + # laconicd gas price (default: 1) + CERC_LACONICD_GAS_PRICE= ``` ## Start the deployment -- 2.45.2