From 72f1abcdf6778b06dad01dea2af2f154c41b6cbc Mon Sep 17 00:00:00 2001 From: Nabarun Gogoi Date: Mon, 15 Apr 2024 14:10:59 +0530 Subject: [PATCH] Add CI to test web app deployment and undeployment (#174) * Add a script to deploy test records * Add checks for ApplicationDeploymentRecord and the deployment URL * Add a CI workflow to run the app deployment test * Update test deployment request record config * Add test for deployment removal * Update test deployment request record * Increase max retries * Add retries when checking if URL is up or down * Rename test script * Run webapp deployment test CI on PR * Remove unnecessary jq installation step from CI * Revert "Run webapp deployment test CI on PR" This reverts commit 01f373501a95b95cf0abc1dee8fed639ec62daf5. * Add a step for Slack alerts on a CI failure * Add a workflow dispatch for manual trigger * Update workflow title and remove trigger on main * Document deployment test setup --------- Co-authored-by: Prathamesh Musale --- .github/workflows/test-app-deployment.yaml | 39 +++ packages/deployer/test/README.md | 23 ++ ...application-deployment-removal-request.yml | 4 + .../application-deployment-request.yml | 15 ++ .../test/records/application-record.yml | 8 + .../test-webapp-deployment-undeployment.sh | 225 ++++++++++++++++++ 6 files changed, 314 insertions(+) create mode 100644 .github/workflows/test-app-deployment.yaml create mode 100644 packages/deployer/test/README.md create mode 100644 packages/deployer/test/records/application-deployment-removal-request.yml create mode 100644 packages/deployer/test/records/application-deployment-request.yml create mode 100644 packages/deployer/test/records/application-record.yml create mode 100755 packages/deployer/test/test-webapp-deployment-undeployment.sh diff --git a/.github/workflows/test-app-deployment.yaml b/.github/workflows/test-app-deployment.yaml new file mode 100644 index 00000000..d1c736a8 --- /dev/null +++ b/.github/workflows/test-app-deployment.yaml @@ -0,0 +1,39 @@ +name: Test webapp deployment + +on: + schedule: + - cron: '0 3 * * *' + workflow_dispatch: + +jobs: + test_app_deployment: + runs-on: ubuntu-latest + strategy: + matrix: + node-version: [20.x] + steps: + - uses: actions/checkout@v3 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + - name: Install dependencies + run: yarn + - name: Test webapp deployment + run: ./packages/deployer/test/test-webapp-deployment-undeployment.sh + - name: Notify Vulcanize Slack on CI failure + if: ${{ always() && github.ref_name == 'main' }} + uses: ravsamhq/notify-slack-action@v2 + with: + status: ${{ job.status }} + notify_when: 'failure' + env: + SLACK_WEBHOOK_URL: ${{ secrets.VULCANIZE_SLACK_CI_ALERTS_WEBHOOK }} + - name: Notify DeepStack Slack on CI failure + if: ${{ always() && github.ref_name == 'main' }} + uses: ravsamhq/notify-slack-action@v2 + with: + status: ${{ job.status }} + notify_when: 'failure' + env: + SLACK_WEBHOOK_URL: ${{ secrets.DEEPSTACK_SLACK_CI_ALERTS_WEBHOOK }} diff --git a/packages/deployer/test/README.md b/packages/deployer/test/README.md new file mode 100644 index 00000000..88c43cfb --- /dev/null +++ b/packages/deployer/test/README.md @@ -0,0 +1,23 @@ +# deployer test + +Check if the live web app deployer is in a working state + +- Web app repo used: https://github.com/snowball-tools-platform/test-progressive-web-app (main branch) +- Config used: [../config.yml](../config.yml) +- The script [test-webapp-deployment-undeployment.sh](./test-webapp-deployment-undeployment.sh) performs the following: + - Create / update [`ApplicationRecord`](./records/application-record.yml) and [`ApplicationDeploymentRequest`](./records/application-deployment-request.yml) records with latest meta data from the repo + - Fetch the latest version of `deployment-test-app` from registry and increment `ApplicationRecord` version + - Publish the resulting `ApplicationRecord` record + - Set names to the record and check name resolution + - Publish the `ApplicationDeploymentRequest` record + - Check that the deployment occurs + - Check that a `ApplicationDeploymentRecord` is created + - Check that the deployment record has correct `ApplicationRecord` id + - Check that the URL present in deployment record is active + - Create and publish a [`ApplicationDeploymentRemovalRequest`](./records/application-deployment-removal-request.yml) record + - Check that the deployment is removed + - Check that a `ApplicationDeploymentRemovalRecord` is created + - Check that the deployment URL goes down +- The test script is run in a GitHub CI [workflow](../../../.github/workflows/test-app-deployment.yaml) that: + - Is scheduled to run everyday on the default (`main`) branch or can be triggered manually + - Sends Slack alerts to configured channels on failure diff --git a/packages/deployer/test/records/application-deployment-removal-request.yml b/packages/deployer/test/records/application-deployment-removal-request.yml new file mode 100644 index 00000000..b0082da8 --- /dev/null +++ b/packages/deployer/test/records/application-deployment-removal-request.yml @@ -0,0 +1,4 @@ +record: + deployment: + type: ApplicationDeploymentRemovalRequest + version: 1.0.0 diff --git a/packages/deployer/test/records/application-deployment-request.yml b/packages/deployer/test/records/application-deployment-request.yml new file mode 100644 index 00000000..17fee5fa --- /dev/null +++ b/packages/deployer/test/records/application-deployment-request.yml @@ -0,0 +1,15 @@ +record: + type: ApplicationDeploymentRequest + version: '1.0.0' + name: deployment-test-app@0.1.24 + application: crn://snowballtools/applications/deployment-test-app@0.1.24 + dns: deployment-ci-test + config: + env: + CERC_TEST_WEBAPP_CONFIG1: "deployment test config 1" + CERC_TEST_WEBAPP_CONFIG2: "deployment test config 2" + CERC_WEBAPP_DEBUG: 0 + meta: + note: Deployment test @ Thu 11 Apr 2024 07:29:19 AM UTC + repository: "https://github.com/snowball-tools-platform/test-progressive-web-app" + repository_ref: 05819619487a0d2dbc5453b6d1ccff3044c0dd26 diff --git a/packages/deployer/test/records/application-record.yml b/packages/deployer/test/records/application-record.yml new file mode 100644 index 00000000..f6c24d39 --- /dev/null +++ b/packages/deployer/test/records/application-record.yml @@ -0,0 +1,8 @@ +record: + type: ApplicationRecord + version: 0.0.1 + repository_ref: 05819619487a0d2dbc5453b6d1ccff3044c0dd26 + repository: ["https://github.com/snowball-tools-platform/test-progressive-web-app"] + app_type: webapp + name: deployment-test-app + app_version: 0.1.24 diff --git a/packages/deployer/test/test-webapp-deployment-undeployment.sh b/packages/deployer/test/test-webapp-deployment-undeployment.sh new file mode 100755 index 00000000..4817fb9b --- /dev/null +++ b/packages/deployer/test/test-webapp-deployment-undeployment.sh @@ -0,0 +1,225 @@ +#!/bin/bash + +# Repository URL +REPO_URL="https://github.com/snowball-tools-platform/test-progressive-web-app" + +# Get the latest commit hash from the repository +LATEST_HASH=$(git ls-remote $REPO_URL HEAD | awk '{print $1}') + +# Fetch the package.json file content +# Extract version from package.json content +package_json=$(wget -qO- "$REPO_URL/raw/$LATEST_HASH/package.json") +PACKAGE_VERSION=$(echo "$package_json" | jq -r '.version') + +# Current date and time for note +CURRENT_DATE_TIME=$(date -u) + +CONFIG_FILE=packages/deployer/config.yml +REGISTRY_BOND_ID="99c0e9aec0ac1b8187faa579be3b54f93fafb6060ac1fd29170b860df605be32" + +# Reference: https://git.vdb.to/cerc-io/test-progressive-web-app/src/branch/main/scripts + +APP_NAME=deployment-test-app + +# Get latest version from registry and increment application-record version +NEW_APPLICATION_VERSION=$(yarn --silent laconic -c $CONFIG_FILE cns record list --type ApplicationRecord --all --name "$APP_NAME" 2>/dev/null | jq -r -s ".[] | sort_by(.createTime) | reverse | [ .[] | select(.bondId == \"$REGISTRY_BOND_ID\") ] | .[0].attributes.version" | awk -F. -v OFS=. '{$NF += 1 ; print}') + +if [ -z "$NEW_APPLICATION_VERSION" ] || [ "1" == "$NEW_APPLICATION_VERSION" ]; then + # Set application-record version if no previous records were found + NEW_APPLICATION_VERSION=0.0.1 +fi + +# Generate application-record.yml with incremented version +RECORD_FILE=packages/deployer/test/records/application-record.yml + +cat > $RECORD_FILE < $REQUEST_RECORD_FILE < $REMOVAL_REQUEST_RECORD_FILE <