webapp-hello-world-payment/scripts/request-app-deployment.sh

68 lines
2.1 KiB
Bash
Raw Normal View History

2024-08-14 21:24:45 +00:00
#!/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 <<EOF > "$CONFIG_FILE"
services:
2024-08-14 21:31:12 +00:00
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}
2024-08-14 21:31:12 +00:00
gas: 900000
fees: 900000alnt
2024-08-14 21:24:45 +00:00
EOF
2024-08-14 21:31:12 +00:00
if [ -z "$CERC_REGISTRY_APP_LRN" ]; then
2024-08-14 21:24:45 +00:00
authority=$(echo "$rcd_name" | cut -d'/' -f1 | sed 's/@//')
app=$(echo "$rcd_name" | cut -d'/' -f2-)
2024-08-14 21:31:12 +00:00
CERC_REGISTRY_APP_LRN="lrn://$authority/applications/$app"
2024-08-14 21:24:45 +00:00
fi
2024-08-20 19:17:44 +00:00
PAYMENT_TX=$(laconic -c $CONFIG_FILE registry tokens send \
--address laconic13eq42rat3aurnfj6pu32yl00zyhl8sent97efe \
2024-08-20 19:17:44 +00:00
--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')
2024-08-15 02:16:23 +00:00
APP_RECORD=$(laconic -c $CONFIG_FILE registry name resolve "$CERC_REGISTRY_APP_LRN" | jq '.[0]')
2024-08-14 21:24:45 +00:00
if [ -z "$APP_RECORD" ] || [ "null" == "$APP_RECORD" ]; then
2024-08-14 21:31:12 +00:00
echo "No record found for $CERC_REGISTRY_APP_LRN."
2024-08-14 21:24:45 +00:00
exit 1
fi
cat <<EOF | sed '/.*: ""$/d' > "$RECORD_FILE"
record:
type: ApplicationDeploymentRequest
version: 1.0.0
name: "$rcd_name@$rcd_app_version"
2024-08-14 21:31:12 +00:00
application: "$CERC_REGISTRY_APP_LRN@$rcd_app_version"
2024-08-15 02:16:23 +00:00
dns: "$CERC_REGISTRY_DEPLOYMENT_HOSTNAME"
2024-08-14 21:31:12 +00:00
deployment: "$CERC_REGISTRY_DEPLOYMENT_LRN"
to: laconic13eq42rat3aurnfj6pu32yl00zyhl8sent97efe
2024-08-20 19:17:44 +00:00
payment: $PAYMENT_TX
2024-08-14 21:24:45 +00:00
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
2024-08-20 19:17:44 +00:00
2024-08-14 21:24:45 +00:00
cat $RECORD_FILE
2024-08-20 19:17:44 +00:00
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')
2024-08-14 21:24:45 +00:00
echo $RECORD_ID
rm -f $RECORD_FILE $CONFIG_FILE