From 8589bf4094e68f76dab35172742a36df393cdc25 Mon Sep 17 00:00:00 2001 From: David Boreham Date: Tue, 18 Jun 2024 11:15:31 -0600 Subject: [PATCH] Make deployment scripts more robust --- packages/deployer/deploy-frontend.sh | 38 ++++++++++++++++++-- packages/deployer/deploy-frontend.staging.sh | 38 ++++++++++++++++++-- 2 files changed, 70 insertions(+), 6 deletions(-) diff --git a/packages/deployer/deploy-frontend.sh b/packages/deployer/deploy-frontend.sh index 23a1abf..cb87f27 100755 --- a/packages/deployer/deploy-frontend.sh +++ b/packages/deployer/deploy-frontend.sh @@ -64,7 +64,13 @@ echo "Files generated successfully." RECORD_FILE=records/application-record.yml # Publish ApplicationRecord -RECORD_ID=$(yarn --silent laconic -c $CONFIG_FILE cns record publish --filename $RECORD_FILE | jq -r '.id') +publish_response=$(yarn --silent laconic -c $CONFIG_FILE cns record publish --filename $RECORD_FILE) +rc=$? +if [ $rc -ne 0 ]; then + echo "FATAL: Failed to publish record" + exit $rc +fi +RECORD_ID=$(echo $publish_response | jq -r '.id') echo "ApplicationRecord published" echo $RECORD_ID @@ -73,15 +79,36 @@ REGISTRY_APP_CRN="crn://snowballtools/applications/snowballtools-base-frontend" sleep 2 yarn --silent laconic -c $CONFIG_FILE cns name set "$REGISTRY_APP_CRN@${PACKAGE_VERSION}" "$RECORD_ID" +rc=$? +if [ $rc -ne 0 ]; then + echo "FATAL: Failed to set name: $REGISTRY_APP_CRN@${PACKAGE_VERSION}" + exit $rc +fi sleep 2 yarn --silent laconic -c $CONFIG_FILE cns name set "$REGISTRY_APP_CRN@${LATEST_HASH}" "$RECORD_ID" +rc=$? +if [ $rc -ne 0 ]; then + echo "FATAL: Failed to set hash" + exit $rc +fi sleep 2 # Set name if latest release yarn --silent laconic -c $CONFIG_FILE cns name set "$REGISTRY_APP_CRN" "$RECORD_ID" +rc=$? +if [ $rc -ne 0 ]; then + echo "FATAL: Failed to set release" + exit $rc +fi echo "$REGISTRY_APP_CRN set for ApplicationRecord" # Check if record found for REGISTRY_APP_CRN -APP_RECORD=$(yarn --silent laconic -c $CONFIG_FILE cns name resolve "$REGISTRY_APP_CRN" | jq '.[0]') +query_response=$(yarn --silent laconic -c $CONFIG_FILE cns name resolve "$REGISTRY_APP_CRN") +rc=$? +if [ $rc -ne 0 ]; then + echo "FATAL: Failed to query name" + exit $rc +fi +APP_RECORD=$(echo $query_response | jq '.[0]') if [ -z "$APP_RECORD" ] || [ "null" == "$APP_RECORD" ]; then echo "No record found for $REGISTRY_APP_CRN." exit 1 @@ -90,6 +117,11 @@ fi RECORD_FILE=records/application-deployment-request.yml sleep 2 -DEPLOYMENT_REQUEST_ID=$(yarn --silent laconic -c $CONFIG_FILE cns record publish --filename $RECORD_FILE | jq -r '.id') +deployment_response=$(yarn --silent laconic -c $CONFIG_FILE cns record publish --filename $RECORD_FILE) +if [ $rc -ne 0 ]; then + echo "FATAL: Failed to query deployment request" + exit $rc +fi +DEPLOYMENT_REQUEST_ID=$(echo $deployment_response | jq -r '.id') echo "ApplicationDeploymentRequest published" echo $DEPLOYMENT_REQUEST_ID diff --git a/packages/deployer/deploy-frontend.staging.sh b/packages/deployer/deploy-frontend.staging.sh index a0cc396..649b91b 100755 --- a/packages/deployer/deploy-frontend.staging.sh +++ b/packages/deployer/deploy-frontend.staging.sh @@ -70,7 +70,13 @@ echo "Files generated successfully." RECORD_FILE=staging-records/application-record.yml # Publish ApplicationRecord -RECORD_ID=$(yarn --silent laconic -c $CONFIG_FILE cns record publish --filename $RECORD_FILE | jq -r '.id') +publish_response=$(yarn --silent laconic -c $CONFIG_FILE cns record publish --filename $RECORD_FILE) +rc=$? +if [ $rc -ne 0 ]; then + echo "FATAL: Failed to publish record" + exit $rc +fi +RECORD_ID=$(echo $publish_response | jq -r '.id') echo "ApplicationRecord published" echo $RECORD_ID @@ -79,15 +85,36 @@ REGISTRY_APP_CRN="crn://staging-snowballtools/applications/staging-snowballtools sleep 2 yarn --silent laconic -c $CONFIG_FILE cns name set "$REGISTRY_APP_CRN@${PACKAGE_VERSION}" "$RECORD_ID" +rc=$? +if [ $rc -ne 0 ]; then + echo "FATAL: Failed to set name: $REGISTRY_APP_CRN@${PACKAGE_VERSION}" + exit $rc +fi sleep 2 yarn --silent laconic -c $CONFIG_FILE cns name set "$REGISTRY_APP_CRN@${LATEST_HASH}" "$RECORD_ID" +rc=$? +if [ $rc -ne 0 ]; then + echo "FATAL: Failed to set hash" + exit $rc +fi sleep 2 # Set name if latest release yarn --silent laconic -c $CONFIG_FILE cns name set "$REGISTRY_APP_CRN" "$RECORD_ID" +rc=$? +if [ $rc -ne 0 ]; then + echo "FATAL: Failed to set release" + exit $rc +fi echo "$REGISTRY_APP_CRN set for ApplicationRecord" # Check if record found for REGISTRY_APP_CRN -APP_RECORD=$(yarn --silent laconic -c $CONFIG_FILE cns name resolve "$REGISTRY_APP_CRN" | jq '.[0]') +query_response=$(yarn --silent laconic -c $CONFIG_FILE cns name resolve "$REGISTRY_APP_CRN") +rc=$? +if [ $rc -ne 0 ]; then + echo "FATAL: Failed to query name" + exit $rc +fi +APP_RECORD=$(echo $query_response | jq '.[0]') if [ -z "$APP_RECORD" ] || [ "null" == "$APP_RECORD" ]; then echo "No record found for $REGISTRY_APP_CRN." exit 1 @@ -96,6 +123,11 @@ fi RECORD_FILE=staging-records/application-deployment-request.yml sleep 2 -DEPLOYMENT_REQUEST_ID=$(yarn --silent laconic -c $CONFIG_FILE cns record publish --filename $RECORD_FILE | jq -r '.id') +deployment_response=$(yarn --silent laconic -c $CONFIG_FILE cns record publish --filename $RECORD_FILE) +if [ $rc -ne 0 ]; then + echo "FATAL: Failed to query deployment request" + exit $rc +fi +DEPLOYMENT_REQUEST_ID=$(echo $deployment_response | jq -r '.id') echo "ApplicationDeploymentRequest published" echo $DEPLOYMENT_REQUEST_ID