Add request-app-deployment.sh
This commit is contained in:
parent
0ff8d56d21
commit
c0ab9c7b19
77
scripts/request-app-deployment.sh
Executable file
77
scripts/request-app-deployment.sh
Executable file
@ -0,0 +1,77 @@
|
||||
#!/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:
|
||||
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: 550000
|
||||
fees: 200000aphoton
|
||||
EOF
|
||||
|
||||
if [ -z "$CERC_REGISTRY_DEPLOYMENT_CRN" ] || [ -z "$CERC_REGISTRY_DEPLOYMENT_DNS_CRN" ] || [ -z "$CERC_REGISTRY_APP_CRN" ] || [ -z "$CERC_REGISTRY_REQUEST_CRN" ]; then
|
||||
echo "CERC_REGISTRY_DEPLOYMENT_CRN, CERC_REGISTRY_DEPLOYMENT_DNS_CRN, CERC_REGISTRY_APP_CRN, and CERC_REGISTRY_REQUEST_CRN are all required." 1>&2
|
||||
exit 1
|
||||
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
|
||||
|
||||
DNS_RECORD=$(laconic -c $CONFIG_FILE cns name resolve "$CERC_REGISTRY_DEPLOYMENT_DNS_CRN" | jq '.[0]')
|
||||
if [ -z "$DNS_RECORD" ] || [ "null" == "$DNS_RECORD" ] ; then
|
||||
if [ -z "$CERC_REGISTRY_DEPLOYMENT_DNS_NAME" ]; then
|
||||
APP_NAME=$(echo $rcd_name | rev | cut -d'/' -f1 | rev)
|
||||
ORIGIN_HASH=$(git remote get-url origin | sha256sum | head -c 10)
|
||||
CERC_REGISTRY_DEPLOYMENT_DNS_NAME="$APP_NAME-$ORIGIN_HASH"
|
||||
fi
|
||||
cat <<EOF | sed '/.*: ""$/d' > "$RECORD_FILE"
|
||||
record:
|
||||
type: DnsRecord
|
||||
version: 1.0.0
|
||||
name: "$CERC_REGISTRY_DEPLOYMENT_DNS_NAME"
|
||||
resource_type: "SHORT"
|
||||
meta:
|
||||
note: "Added by CI"
|
||||
repository: "`git remote get-url origin`"
|
||||
repository_ref: "`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')
|
||||
laconic -c $CONFIG_FILE cns name set --user-key "${CERC_REGISTRY_USER_KEY}" --bond-id ${CERC_REGISTRY_BOND_ID} "$CERC_REGISTRY_DEPLOYMENT_DNS_CRN" "$RECORD_ID"
|
||||
DNS_RECORD=$(laconic -c $CONFIG_FILE cns name resolve "$CERC_REGISTRY_DEPLOYMENT_DNS_CRN" | jq '.[0]')
|
||||
fi
|
||||
|
||||
|
||||
cat <<EOF | sed '/.*: ""$/d' > "$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_DNS_CRN"
|
||||
deployment: "$CERC_REGISTRY_DEPLOYMENT_CRN"
|
||||
meta:
|
||||
note: "Added by CI"
|
||||
repository: "`git remote get-url origin`"
|
||||
repository_ref: "`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
|
||||
laconic -c $CONFIG_FILE cns name set --user-key "${CERC_REGISTRY_USER_KEY}" --bond-id ${CERC_REGISTRY_BOND_ID} "$CERC_REGISTRY_REQUEST_CRN" "$RECORD_ID"
|
||||
|
||||
rm -f $RECORD_FILE $CONFIG_FILE
|
Loading…
Reference in New Issue
Block a user