From 8959364dee091bb73731d9649c70174763d5d769 Mon Sep 17 00:00:00 2001 From: zramsay Date: Tue, 27 Feb 2024 17:50:12 -0500 Subject: [PATCH 1/7] publish to registry --- .github/workflows/publish-to-registry.yml | 35 ++++++++++++ package.json | 3 +- scripts/publish-app-record.sh | 70 +++++++++++++++++++++++ scripts/request-app-deployment.sh | 57 ++++++++++++++++++ 4 files changed, 164 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/publish-to-registry.yml create mode 100755 scripts/publish-app-record.sh create mode 100755 scripts/request-app-deployment.sh diff --git a/.github/workflows/publish-to-registry.yml b/.github/workflows/publish-to-registry.yml new file mode 100644 index 0000000..c6bcba2 --- /dev/null +++ b/.github/workflows/publish-to-registry.yml @@ -0,0 +1,35 @@ +name: Publish ApplicationRecord to Registry +on: + release: + types: [published] + push: + branches: + - registry + +env: + CERC_REGISTRY_USER_KEY: ${{ secrets.CICD_LACONIC_USER_KEY }} + CERC_REGISTRY_BOND_ID: ${{ secrets.CICD_LACONIC_BOND_ID }} + +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: "Install Yarn" + run: npm install -g yarn + - name: "Install registry CLI" + run: | + npm config set @cerc-io:registry https://git.vdb.to/api/packages/cerc-io/npm/ + yarn global add @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/package.json b/package.json index 247f5e1..efe0c1c 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,6 @@ { - "name": "dydx-chain-web", + "name": "@lx-mars/dydx-chain-web", + "reppository": "https://git.vdb.to/LaconicNetwork/dydx-v4-web", "private": true, "version": "1.0.0", "type": "module", diff --git a/scripts/publish-app-record.sh b/scripts/publish-app-record.sh new file mode 100755 index 0000000..b830540 --- /dev/null +++ b/scripts/publish-app-record.sh @@ -0,0 +1,70 @@ +#!/bin/bash + +set -e + +RECORD_FILE=tmp.rf.$$ +CONFIG_FILE=`mktemp` + +CERC_APP_TYPE=${CERC_APP_TYPE:-"webapp"} +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: + cns: + restEndpoint: '${CERC_REGISTRY_REST_ENDPOINT:-http://console.laconic.com:1317}' + gqlEndpoint: '${CERC_REGISTRY_GQL_ENDPOINT:-http://console.laconic.com:9473/api}' + chainId: ${CERC_REGISTRY_CHAIN_ID:-laconic_9000-1} + gas: 1750000 + fees: 20000aphoton +EOF + +next_ver=$(laconic -c $CONFIG_FILE cns 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 cns 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_CRN" ]; then + authority=$(echo "$rcd_name" | cut -d'/' -f1 | sed 's/@//') + app=$(echo "$rcd_name" | cut -d'/' -f2-) + CERC_REGISTRY_APP_CRN="crn://$authority/applications/$app" +fi + +laconic -c $CONFIG_FILE cns name set --user-key "${CERC_REGISTRY_USER_KEY}" --bond-id ${CERC_REGISTRY_BOND_ID} "$CERC_REGISTRY_APP_CRN@${rcd_app_version}" "$RECORD_ID" +laconic -c $CONFIG_FILE cns name set --user-key "${CERC_REGISTRY_USER_KEY}" --bond-id ${CERC_REGISTRY_BOND_ID} "$CERC_REGISTRY_APP_CRN@${CERC_REPO_REF}" "$RECORD_ID" +if [ "true" == "$CERC_IS_LATEST_RELEASE" ]; then + laconic -c $CONFIG_FILE cns name set --user-key "${CERC_REGISTRY_USER_KEY}" --bond-id ${CERC_REGISTRY_BOND_ID} "$CERC_REGISTRY_APP_CRN" "$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 0000000..965606b --- /dev/null +++ b/scripts/request-app-deployment.sh @@ -0,0 +1,57 @@ +#!/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: + cns: + restEndpoint: '${CERC_REGISTRY_REST_ENDPOINT:-http://console.laconic.com:1317}' + gqlEndpoint: '${CERC_REGISTRY_GQL_ENDPOINT:-http://console.laconic.com:9473/api}' + chainId: ${CERC_REGISTRY_CHAIN_ID:-laconic_9000-1} + gas: 1550000 + fees: 20000aphoton +EOF + +if [ -z "$CERC_REGISTRY_APP_CRN" ]; then + authority=$(echo "$rcd_name" | cut -d'/' -f1 | sed 's/@//') + app=$(echo "$rcd_name" | cut -d'/' -f2-) + CERC_REGISTRY_APP_CRN="crn://$authority/applications/$app" +fi + +APP_RECORD=$(laconic -c $CONFIG_FILE cns name resolve "$CERC_REGISTRY_APP_CRN" | jq '.[0]') +if [ -z "$APP_RECORD" ] || [ "null" == "$APP_RECORD" ]; then + echo "No record found for $CERC_REGISTRY_APP_CRN." + exit 1 +fi + +cat < "$RECORD_FILE" +record: + type: ApplicationDeploymentRequest + version: 1.0.0 + name: "$rcd_name@$rcd_app_version" + application: "$CERC_REGISTRY_APP_CRN@$rcd_app_version" + dns: "$CERC_REGISTRY_DEPLOYMENT_SHORT_HOSTNAME" + deployment: "$CERC_REGISTRY_DEPLOYMENT_CRN" + config: + env: + CERC_WEBAPP_DEBUG: "$rcd_app_version" + CERC_MAX_GENERATE_TIME: 180 + CERC_NEXT_VERSION: 13.4.2 + 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 cns record publish --filename $RECORD_FILE --user-key "${CERC_REGISTRY_USER_KEY}" --bond-id ${CERC_REGISTRY_BOND_ID} | jq -r '.id') +echo $RECORD_ID + +rm -f $RECORD_FILE $CONFIG_FILE + -- 2.45.2 From 37ca83b29fafa76c9688453bfc63c68cc2f3480e Mon Sep 17 00:00:00 2001 From: zramsay Date: Tue, 27 Feb 2024 17:55:34 -0500 Subject: [PATCH 2/7] ok --- .github/workflows/publish-to-registry.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/publish-to-registry.yml b/.github/workflows/publish-to-registry.yml index c6bcba2..cb5f4b4 100644 --- a/.github/workflows/publish-to-registry.yml +++ b/.github/workflows/publish-to-registry.yml @@ -5,6 +5,7 @@ on: push: branches: - registry + - test env: CERC_REGISTRY_USER_KEY: ${{ secrets.CICD_LACONIC_USER_KEY }} -- 2.45.2 From 3b4af29bd58c2fccbf6c72e6442e070383a5e551 Mon Sep 17 00:00:00 2001 From: zramsay Date: Tue, 27 Feb 2024 18:11:37 -0500 Subject: [PATCH 3/7] install corepack --- .github/workflows/publish-to-registry.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/publish-to-registry.yml b/.github/workflows/publish-to-registry.yml index cb5f4b4..6eaf498 100644 --- a/.github/workflows/publish-to-registry.yml +++ b/.github/workflows/publish-to-registry.yml @@ -23,6 +23,10 @@ jobs: node-version: 18 - name: "Install Yarn" run: npm install -g yarn + - name: "Install Corepack" + run: npm install -g corepack + - name: "Enable Corepack" + run: corepack enable - name: "Install registry CLI" run: | npm config set @cerc-io:registry https://git.vdb.to/api/packages/cerc-io/npm/ -- 2.45.2 From e2b2af66809aa6b473f0fea8d6d173682145e497 Mon Sep 17 00:00:00 2001 From: zramsay Date: Tue, 27 Feb 2024 18:14:18 -0500 Subject: [PATCH 4/7] hrm --- .github/workflows/publish-to-registry.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish-to-registry.yml b/.github/workflows/publish-to-registry.yml index 6eaf498..ad382a1 100644 --- a/.github/workflows/publish-to-registry.yml +++ b/.github/workflows/publish-to-registry.yml @@ -29,7 +29,7 @@ jobs: run: corepack enable - name: "Install registry CLI" run: | - npm config set @cerc-io:registry https://git.vdb.to/api/packages/cerc-io/npm/ + pnpm config set @cerc-io:registry https://git.vdb.to/api/packages/cerc-io/npm/ yarn global add @cerc-io/laconic-registry-cli - name: "Install jq" run: apt -y update && apt -y install jq -- 2.45.2 From d2020664d5c49fd4cd27e3843778570a965addd2 Mon Sep 17 00:00:00 2001 From: zramsay Date: Tue, 27 Feb 2024 18:20:06 -0500 Subject: [PATCH 5/7] https://github.com/nodejs/corepack/issues/157 --- .github/workflows/publish-to-registry.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/publish-to-registry.yml b/.github/workflows/publish-to-registry.yml index ad382a1..623a989 100644 --- a/.github/workflows/publish-to-registry.yml +++ b/.github/workflows/publish-to-registry.yml @@ -10,6 +10,7 @@ on: env: CERC_REGISTRY_USER_KEY: ${{ secrets.CICD_LACONIC_USER_KEY }} CERC_REGISTRY_BOND_ID: ${{ secrets.CICD_LACONIC_BOND_ID }} + COREPACK_ENABLE_STRICT: 0 jobs: cns_publish: -- 2.45.2 From a50ff841a068543273c142d16d14d2ce0084f2af Mon Sep 17 00:00:00 2001 From: zramsay Date: Tue, 27 Feb 2024 18:23:54 -0500 Subject: [PATCH 6/7] use npm not pnpm for install reg-cli --- .github/workflows/publish-to-registry.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish-to-registry.yml b/.github/workflows/publish-to-registry.yml index 623a989..3b7dba2 100644 --- a/.github/workflows/publish-to-registry.yml +++ b/.github/workflows/publish-to-registry.yml @@ -30,7 +30,7 @@ jobs: run: corepack enable - name: "Install registry CLI" run: | - pnpm config set @cerc-io:registry https://git.vdb.to/api/packages/cerc-io/npm/ + npm config set @cerc-io:registry https://git.vdb.to/api/packages/cerc-io/npm/ yarn global add @cerc-io/laconic-registry-cli - name: "Install jq" run: apt -y update && apt -y install jq -- 2.45.2 From 2212e607cf30ee4523a8630c2425baa5b33d3f16 Mon Sep 17 00:00:00 2001 From: zramsay Date: Tue, 27 Feb 2024 18:26:06 -0500 Subject: [PATCH 7/7] critical typo --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index efe0c1c..e5c420b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@lx-mars/dydx-chain-web", - "reppository": "https://git.vdb.to/LaconicNetwork/dydx-v4-web", + "repository": "https://git.vdb.to/LaconicNetwork/dydx-v4-web", "private": true, "version": "1.0.0", "type": "module", -- 2.45.2