From 31369644301c47cdb4e6f1a311255854b2a6f7a9 Mon Sep 17 00:00:00 2001 From: zramsay Date: Wed, 21 Aug 2024 15:51:14 -0400 Subject: [PATCH] testnet deploy --- .github/workflows/config-check.yaml | 21 ------ .github/workflows/docker.yaml | 51 -------------- .../workflows/mainnet-deploy.yaml.disabled | 28 -------- .github/workflows/publish.yaml | 39 +++++++++++ .github/workflows/testnet-deploy.yaml | 27 -------- package.json | 3 +- scripts/publish-app-record.sh | 69 +++++++++++++++++++ scripts/request-app-deployment.sh | 67 ++++++++++++++++++ 8 files changed, 177 insertions(+), 128 deletions(-) delete mode 100644 .github/workflows/config-check.yaml delete mode 100644 .github/workflows/docker.yaml delete mode 100644 .github/workflows/mainnet-deploy.yaml.disabled create mode 100644 .github/workflows/publish.yaml delete mode 100644 .github/workflows/testnet-deploy.yaml create mode 100755 scripts/publish-app-record.sh create mode 100755 scripts/request-app-deployment.sh diff --git a/.github/workflows/config-check.yaml b/.github/workflows/config-check.yaml deleted file mode 100644 index a9bad362..00000000 --- a/.github/workflows/config-check.yaml +++ /dev/null @@ -1,21 +0,0 @@ - -name: Config Checker - -on: - # push: - # branches: [ master ] - pull_request: - # branches: [ master ] - paths: - - 'chains/mainnet/**' - - 'chains/testnet/**' - -jobs: - deploy: - name: Check Blockchain Config - runs-on: ubuntu-latest - steps: - - name: Git Checkout Latest - uses: actions/checkout@v3 - - name: Check Chain Configs - uses: ping-pub/ping-dashboard-config-checker@v1.0 \ No newline at end of file diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml deleted file mode 100644 index ce1e3034..00000000 --- a/.github/workflows/docker.yaml +++ /dev/null @@ -1,51 +0,0 @@ -name: docker - -on: - push: - branches: - - 'master-backup' - -jobs: - docker: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v2 -# - -# name: Set up QEMU -# uses: docker/setup-qemu-action@v1 -# - -# name: Set up Docker Buildx -# uses: docker/setup-buildx-action@v1 - - name: Install - run: yarn install - - name: Build - run: yarn run vue-cli-service build - - name: Login to DockerHub - uses: docker/login-action@v1 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Docker meta - id: meta - uses: docker/metadata-action@v3 - with: - # list of Docker images to use as base name for tags - images: | - yaoling/wallet - # generate Docker tags based on the following events/attributes - tags: | - type=sha - type=schedule - type=ref,event=branch - type=ref,event=pr - type=semver,pattern={{version}} - type=semver,pattern={{major}}.{{minor}} - type=semver,pattern={{major}} - - name: Build and push - uses: docker/build-push-action@v2 - with: - context: . - push: ${{ github.event_name != 'pull_request' }} - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file diff --git a/.github/workflows/mainnet-deploy.yaml.disabled b/.github/workflows/mainnet-deploy.yaml.disabled deleted file mode 100644 index 0b69f65c..00000000 --- a/.github/workflows/mainnet-deploy.yaml.disabled +++ /dev/null @@ -1,28 +0,0 @@ - -name: Deploy to ping.pub - -on: - push: - branches: [ master2 ] - # pull_request: - # branches: [ master ] - -jobs: - deploy: - name: Ping deploy - runs-on: mainnet - steps: - - name: Environment - run: export NODE_OPTIONS="--max_old_space_size=4096" - - - name: Git Checkout Latest - uses: actions/checkout@v3 - - - name: Install - run: yarn install --ignore-engines - - - name: Build - run: yarn build - - - name: Deploy - run: cp -rf ./dist/* /var/www/html/ \ No newline at end of file diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml new file mode 100644 index 00000000..380aae58 --- /dev/null +++ b/.github/workflows/publish.yaml @@ -0,0 +1,39 @@ +name: Publish ApplicationRecord to Registry +on: + release: + types: [published] + push: + branches: + - main + - '*' + +env: + CERC_REGISTRY_USER_KEY: ${{ secrets.CICD_VAASL_LACONIC_USER_KEY }} + CERC_REGISTRY_BOND_ID: ${{ secrets.CICD_VAASL_LACONIC_BOND_ID }} + CERC_REGISTRY_DEPLOYMENT_HOSTNAME: ${{ vars.CERC_REGISTRY_DEPLOYMENT_HOSTNAME }} + CERC_REGISTRY_DEPLOYMENT_REQUEST_USER_KEY: ${{ secrets.CICD_VAASL_DEPLOYMENT_REQUEST_USER_KEY }} + CERC_REGISTRY_DEPLOYMENT_REQUEST_BOND_ID: ${{ secrets.CICD_VAASL_DEPLOYMENT_REQUEST_BOND_ID }} + CERC_REGISTRY_DEPLOYMENT_REQUEST_PAYMENT_TO: ${{ secrets.CICD_VAASL_DEPLOYMENT_REQUEST_PAYMENT_TO }} + +jobs: + cns_publish: + runs-on: ubuntu-latest + steps: + - name: "Clone project repository" + uses: actions/checkout@v3 + - name: Use Node.js + uses: actions/setup-node@v3 + with: + node-version: 18 + - name: "Enable Yarn" + run: corepack enable + - name: "Install registry CLI" + run: | + npm config set @cerc-io:registry https://git.vdb.to/api/packages/cerc-io/npm/ + npm install -g @cerc-io/laconic-registry-cli + - name: "Install jq" + run: apt -y update && apt -y install jq + - name: "Publish Application Record" + run: scripts/publish-app-record.sh + - name: "Request Deployment" + run: scripts/request-app-deployment.sh diff --git a/.github/workflows/testnet-deploy.yaml b/.github/workflows/testnet-deploy.yaml deleted file mode 100644 index 55391d01..00000000 --- a/.github/workflows/testnet-deploy.yaml +++ /dev/null @@ -1,27 +0,0 @@ - -name: Testnet Deploy - -on: - push: - branches: [ testnet ] - pull_request: - branches: [ testnet ] - -jobs: - deploy: - name: Ping deploy - runs-on: testnet - steps: - - name: print - run: echo ${GITHUB_REF#refs/heads/} - - name: Git Checkout Latest - uses: actions/checkout@v2 - - - name: Install - run: yarn install - - - name: Build - run: yarn run vue-cli-service build - - - name: Deploy - run: cp -rf ./dist/* /var/www/html/ \ No newline at end of file diff --git a/package.json b/package.json index e4f50215..9f9c9275 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,7 @@ { - "name": "ping.pub", + "name": "@lcn-demo/ping.pub", "version": "3.0.0", + "repository": "https://git.vdb.to/zramsay/cosmos-explorer", "private": true, "target": "", "scripts": { diff --git a/scripts/publish-app-record.sh b/scripts/publish-app-record.sh new file mode 100755 index 00000000..f4dca2cd --- /dev/null +++ b/scripts/publish-app-record.sh @@ -0,0 +1,69 @@ +#!/bin/bash + +set -e + +RECORD_FILE=tmp.rf.$$ +CONFIG_FILE=`mktemp` + +CERC_APP_TYPE=${CERC_APP_TYPE:-"webapp/next"} +CERC_REPO_REF=${CERC_REPO_REF:-${GITHUB_SHA:-`git log -1 --format="%H"`}} +CERC_IS_LATEST_RELEASE=${CERC_IS_LATEST_RELEASE:-"true"} + +rcd_name=$(jq -r '.name' package.json | sed 's/null//') +rcd_desc=$(jq -r '.description' package.json | sed 's/null//') +rcd_repository=$(jq -r '.repository' package.json | sed 's/null//') +rcd_homepage=$(jq -r '.homepage' package.json | sed 's/null//') +rcd_license=$(jq -r '.license' package.json | sed 's/null//') +rcd_author=$(jq -r '.author' package.json | sed 's/null//') +rcd_app_version=$(jq -r '.version' package.json | sed 's/null//') + +cat < "$CONFIG_FILE" +services: + registry: + rpcEndpoint: '${CERC_REGISTRY_RPC_ENDPOINT:-https://laconicd.laconic.com}' + gqlEndpoint: '${CERC_REGISTRY_GQL_ENDPOINT:-https://laconicd.laconic.com/api}' + chainId: ${CERC_REGISTRY_CHAIN_ID:-laconic_9000-1} + gas: 900000 + fees: 1900000alnt +EOF + +next_ver=$(laconic -c $CONFIG_FILE registry record list --type ApplicationRecord --all --name "$rcd_name" 2>/dev/null | jq -r -s ".[] | sort_by(.createTime) | reverse | [ .[] | select(.bondId == \"$CERC_REGISTRY_BOND_ID\") ] | .[0].attributes.version" | awk -F. -v OFS=. '{$NF += 1 ; print}') + +if [ -z "$next_ver" ] || [ "1" == "$next_ver" ]; then + next_ver=0.0.1 +fi + +cat < "$RECORD_FILE" +record: + type: ApplicationRecord + version: ${next_ver} + name: "$rcd_name" + description: "$rcd_desc" + homepage: "$rcd_homepage" + license: "$rcd_license" + author: "$rcd_author" + repository: + - "$rcd_repository" + repository_ref: "$CERC_REPO_REF" + app_version: "$rcd_app_version" + app_type: "$CERC_APP_TYPE" +EOF + + +cat $RECORD_FILE +RECORD_ID=$(laconic -c $CONFIG_FILE registry record publish --filename $RECORD_FILE --user-key "${CERC_REGISTRY_USER_KEY}" --bond-id ${CERC_REGISTRY_BOND_ID} | jq -r '.id') +echo $RECORD_ID + +if [ -z "$CERC_REGISTRY_APP_LRN" ]; then + authority=$(echo "$rcd_name" | cut -d'/' -f1 | sed 's/@//') + app=$(echo "$rcd_name" | cut -d'/' -f2-) + CERC_REGISTRY_APP_LRN="lrn://$authority/applications/$app" +fi + +laconic -c $CONFIG_FILE registry name set --user-key "${CERC_REGISTRY_USER_KEY}" --bond-id ${CERC_REGISTRY_BOND_ID} "$CERC_REGISTRY_APP_LRN@${rcd_app_version}" "$RECORD_ID" +laconic -c $CONFIG_FILE registry name set --user-key "${CERC_REGISTRY_USER_KEY}" --bond-id ${CERC_REGISTRY_BOND_ID} "$CERC_REGISTRY_APP_LRN@${CERC_REPO_REF}" "$RECORD_ID" +if [ "true" == "$CERC_IS_LATEST_RELEASE" ]; then + laconic -c $CONFIG_FILE registry name set --user-key "${CERC_REGISTRY_USER_KEY}" --bond-id ${CERC_REGISTRY_BOND_ID} "$CERC_REGISTRY_APP_LRN" "$RECORD_ID" +fi + +rm -f $RECORD_FILE $CONFIG_FILE diff --git a/scripts/request-app-deployment.sh b/scripts/request-app-deployment.sh new file mode 100755 index 00000000..bf44da3d --- /dev/null +++ b/scripts/request-app-deployment.sh @@ -0,0 +1,67 @@ +#!/bin/bash + +set -e + +RECORD_FILE=tmp.rf.$$ +CONFIG_FILE=`mktemp` + +rcd_name=$(jq -r '.name' package.json | sed 's/null//' | sed 's/^@//') +rcd_app_version=$(jq -r '.version' package.json | sed 's/null//') + +cat < "$CONFIG_FILE" +services: + registry: + rpcEndpoint: '${CERC_REGISTRY_RPC_ENDPOINT:-https://laconicd.laconic.com}' + gqlEndpoint: '${CERC_REGISTRY_GQL_ENDPOINT:-https://laconicd.laconic.com/api}' + chainId: ${CERC_REGISTRY_CHAIN_ID:-laconic_9000-1} + gas: 900000 + fees: 900000alnt +EOF + +if [ -z "$CERC_REGISTRY_APP_LRN" ]; then + authority=$(echo "$rcd_name" | cut -d'/' -f1 | sed 's/@//') + app=$(echo "$rcd_name" | cut -d'/' -f2-) + CERC_REGISTRY_APP_LRN="lrn://$authority/applications/$app" +fi + +PAYMENT_TX=$(laconic -c $CONFIG_FILE registry tokens send \ + --address laconic13eq42rat3aurnfj6pu32yl00zyhl8sent97efe \ + --user-key "${CERC_REGISTRY_DEPLOYMENT_REQUEST_USER_KEY}" \ + --bond-id "${CERC_REGISTRY_DEPLOYMENT_REQUEST_BOND_ID}" \ + --type alnt \ + --quantity ${CERC_REGISTRY_DEPLOYMENT_REQUEST_PAYMENT_AMOUNT:-10000} | jq '.tx.hash') + +APP_RECORD=$(laconic -c $CONFIG_FILE registry name resolve "$CERC_REGISTRY_APP_LRN" | jq '.[0]') +if [ -z "$APP_RECORD" ] || [ "null" == "$APP_RECORD" ]; then + echo "No record found for $CERC_REGISTRY_APP_LRN." + exit 1 +fi + +cat < "$RECORD_FILE" +record: + type: ApplicationDeploymentRequest + version: 1.0.0 + name: "$rcd_name@$rcd_app_version" + application: "$CERC_REGISTRY_APP_LRN@$rcd_app_version" + dns: "$CERC_REGISTRY_DEPLOYMENT_HOSTNAME" + deployment: "$CERC_REGISTRY_DEPLOYMENT_LRN" + to: laconic13eq42rat3aurnfj6pu32yl00zyhl8sent97efe + payment: $PAYMENT_TX + config: + env: + CERC_WEBAPP_DEBUG: "$rcd_app_version" + meta: + note: "Added by CI @ `date`" + repository: "`git remote get-url origin`" + repository_ref: "${GITHUB_SHA:-`git log -1 --format="%H"`}" +EOF + + +cat $RECORD_FILE +RECORD_ID=$(laconic -c $CONFIG_FILE registry record publish \ + --filename $RECORD_FILE \ + --user-key "${CERC_REGISTRY_DEPLOYMENT_REQUEST_USER_KEY}" \ + --bond-id ${CERC_REGISTRY_DEPLOYMENT_REQUEST_BOND_ID} | jq -r '.id') +echo $RECORD_ID + +rm -f $RECORD_FILE $CONFIG_FILE