From 885d71a20887bcde12d75f6060e9f4cb4ed68217 Mon Sep 17 00:00:00 2001 From: Derek Roberts Date: Wed, 7 Feb 2024 16:47:17 -0800 Subject: [PATCH] chore(ci): load tests (#1793) --- .github/workflows/.deploy.yml | 2 +- .github/workflows/.tests.yml | 40 ++++++++---- .github/workflows/load-test.yml | 42 ------------ .github/workflows/merge.yml | 17 +++-- .github/workflows/pr-open.yml | 1 - .github/workflows/scheduled.yml | 110 +++++++++++++++++--------------- 6 files changed, 94 insertions(+), 118 deletions(-) delete mode 100644 .github/workflows/load-test.yml diff --git a/.github/workflows/.deploy.yml b/.github/workflows/.deploy.yml index 3f4d78e3b..45b4e85bc 100644 --- a/.github/workflows/.deploy.yml +++ b/.github/workflows/.deploy.yml @@ -14,7 +14,7 @@ on: description: Autoscaling enabled or not for the deployments required: false type: string - default: true + default: false environment: description: Environment name; omit for PRs required: false diff --git a/.github/workflows/.tests.yml b/.github/workflows/.tests.yml index 369293dc6..59e148dad 100644 --- a/.github/workflows/.tests.yml +++ b/.github/workflows/.tests.yml @@ -3,15 +3,20 @@ name: .Tests on: workflow_call: inputs: - ### Required + ### Typical / recommended target: description: PR number, test or prod required: true type: string + default: test + +env: + DOMAIN: apps.silver.devops.gov.bc.ca + PREFIX: ${{ github.event.repository.name }}-${{ inputs.target }} jobs: integration-tests: - name: Integration Tests + name: Integration runs-on: ubuntu-22.04 timeout-minutes: 1 steps: @@ -26,21 +31,17 @@ jobs: ${{ runner.os }}-build- ${{ runner.os }}- - - name: Integration tests - env: + - env: API_NAME: nest - BASE_URL: https://${{ github.event.repository.name }}-${{ inputs.target }}-frontend.apps.silver.devops.gov.bc.ca + BASE_URL: https://${{ github.event.repository.name }}-${{ inputs.target }}-frontend.${{ env.DOMAIN }} run: | cd integration-tests npm ci node src/main.js - cypress-e2e: - name: E2E Tests + cypress-e2e-tests: + name: E2E runs-on: ubuntu-22.04 - defaults: - run: - working-directory: frontend strategy: matrix: browser: [chrome, firefox, edge] @@ -58,9 +59,8 @@ jobs: ${{ runner.os }}- - uses: cypress-io/github-action@v6 - name: Cypress run env: - CYPRESS_baseUrl: https://${{ github.event.repository.name }}-${{ inputs.target }}-frontend.apps.silver.devops.gov.bc.ca/ + CYPRESS_baseUrl: https://${{ github.event.repository.name }}-${{ inputs.target }}-frontend.${{ env.DOMAIN }}/ with: config: pageLoadTimeout=10000 working-directory: ./frontend @@ -72,3 +72,19 @@ jobs: name: cypress-screenshots path: ./cypress/screenshots if-no-files-found: ignore # 'warn' or 'error' are also available, defaults to `warn` + + load-tests: + runs-on: ubuntu-latest + name: Load + strategy: + matrix: + name: [backend, frontend] + steps: + - uses: actions/checkout@v4 + - uses: grafana/k6-action@v0.3.1 + env: + BACKEND_URL: https://${{ env.PREFIX }}-frontend.${{ env.DOMAIN }}/api + FRONTEND_URL: https://${{ env.PREFIX }}-frontend.${{ env.DOMAIN }} + with: + filename: ./load-test/${{ matrix.name }}-test.js + flags: --vus 10 --duration 30s diff --git a/.github/workflows/load-test.yml b/.github/workflows/load-test.yml deleted file mode 100644 index 150046ddb..000000000 --- a/.github/workflows/load-test.yml +++ /dev/null @@ -1,42 +0,0 @@ -# Run the Load Test with manual workflow dispatch. -name: Load Test - -on: - workflow_dispatch: - inputs: - vu: - description: 'Number of virtual users to simulate' - required: false - type: number - default: 10 - duration: - description: 'Duration of the test in seconds' - required: false - type: number - default: 30 - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -jobs: - load-test: - runs-on: ubuntu-latest - name: Load Test - env: - DOMAIN: apps.silver.devops.gov.bc.ca - PREFIX: ${{ github.event.repository.name }}-test - strategy: - matrix: - name: [backend, frontend] - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Run k6 local test - uses: grafana/k6-action@v0.3.1 - with: - filename: ./load-test/${{ matrix.name }}-test.js - flags: --vus ${{ github.event.inputs.vu }} --duration ${{ github.event.inputs.duration }}s - env: - BACKEND_URL: https://${{ env.PREFIX }}-frontend.${{ env.DOMAIN }}/api - FRONTEND_URL: https://${{ env.PREFIX }}-frontend.${{ env.DOMAIN }} diff --git a/.github/workflows/merge.yml b/.github/workflows/merge.yml index af6d02858..1cd1c9089 100644 --- a/.github/workflows/merge.yml +++ b/.github/workflows/merge.yml @@ -7,8 +7,7 @@ on: - '*.md' - '.github/**' - '.graphics/**' - - '!.github/workflows/.deploy.yml' - - '!.github/workflows/merge.yml' + - '!.github/workflows/**' workflow_dispatch: inputs: pr_no: @@ -35,28 +34,28 @@ jobs: uses: ./.github/workflows/.deploy.yml secrets: inherit with: - autoscaling: false environment: test tag: ${{ needs.vars.outputs.pr }} release: test - integration-e2e: - name: Integration and E2E Tests + tests: + name: Tests needs: [deploy-test, vars] uses: ./.github/workflows/.tests.yml - with: - target: test deploy-prod: name: Deploy (prod) - needs: [integration-e2e, vars] + needs: [tests, vars] uses: ./.github/workflows/.deploy.yml secrets: inherit with: + autoscaling: true environment: prod tag: ${{ needs.vars.outputs.pr }} release: prod - params: --set backend.deploymentStrategy.type=RollingUpdate --set frontend.deploymentStrategy.type=RollingUpdate + params: + --set backend.deploymentStrategy.type=RollingUpdate + --set frontend.deploymentStrategy.type=RollingUpdate promote: name: Promote Images diff --git a/.github/workflows/pr-open.yml b/.github/workflows/pr-open.yml index f7cfc3155..16160fc0f 100644 --- a/.github/workflows/pr-open.yml +++ b/.github/workflows/pr-open.yml @@ -35,7 +35,6 @@ jobs: uses: ./.github/workflows/.deploy.yml secrets: inherit with: - autoscaling: false tag: ${{ github.event.number }} release: ${{ github.event.number }} triggers: ('backend/' 'frontend/' 'migrations/' 'charts/') diff --git a/.github/workflows/scheduled.yml b/.github/workflows/scheduled.yml index 5e2f2e492..f7d688bd0 100644 --- a/.github/workflows/scheduled.yml +++ b/.github/workflows/scheduled.yml @@ -9,24 +9,45 @@ concurrency: cancel-in-progress: true jobs: - zap_scan: - runs-on: ubuntu-latest - name: Penetration Tests + ageOutPRs: + name: PR Env Purge env: - DOMAIN: apps.silver.devops.gov.bc.ca - PREFIX: ${{ github.event.repository.name }}-test - strategy: - matrix: - name: [backend, frontend] + # https://tecadmin.net/getting-yesterdays-date-in-bash/ + CUTOFF: "1 week ago" + runs-on: ubuntu-latest + timeout-minutes: 10 steps: - - name: ZAP Scan - uses: zaproxy/action-full-scan@v0.9.0 - with: - allow_issue_writing: true - artifact_name: "zap_${{ matrix.name }}" - cmd_options: "-a" - issue_title: "ZAP: ${{ matrix.name }}" - target: https://${{ env.PREFIX }}-${{ matrix.name }}.${{ env.DOMAIN }} + - name: Clean up Helm Releases + run: | + oc login --token=${{ secrets.OC_TOKEN }} --server=${{ vars.OC_SERVER }} + oc project ${{ vars.OC_NAMESPACE }} # Safeguard! + + # Catch errors, unset variables, and pipe failures (e.g. grep || true ) + set -euo pipefail + + # Echos + echo "Delete stale Helm releases" + echo "Cutoff: ${{ env.CUTOFF }}" + + # Before date, list of releases + BEFORE=$(date +%s -d "${{ env.CUTOFF }}") + RELEASES=$(helm ls -aq | grep ${{ github.event.repository.name }} || :) + + # If releases, then iterate + [ -z "${RELEASES}" ]|| for r in ${RELEASES[@]}; do + + # Get last update and convert the date + UPDATED=$(date "+%s" -d <<< echo $(helm status $r -o json | jq -r .info.last_deployed)) + + # Compare to cutoff and delete as necessary + if [[ ${UPDATED} < ${BEFORE} ]]; then + echo -e "\nOlder than cutoff: ${r}" + helm uninstall --no-hooks ${r} + else + echo -e "\nNewer than cutoff: ${r}" + echo "No need to delete" + fi + done generate-schema-spy: name: Generate SchemaSpy Documentation @@ -71,42 +92,25 @@ jobs: folder: output target-folder: schemaspy - ageOutPRs: - name: PR Env Purge - env: - # https://tecadmin.net/getting-yesterdays-date-in-bash/ - CUTOFF: "1 week ago" + tests: + name: Tests + uses: ./.github/workflows/.tests.yml + + zap_scan: runs-on: ubuntu-latest - timeout-minutes: 10 + name: Penetration Tests + env: + DOMAIN: apps.silver.devops.gov.bc.ca + PREFIX: ${{ github.event.repository.name }}-test + strategy: + matrix: + name: [backend, frontend] steps: - - name: Clean up Helm Releases - run: | - oc login --token=${{ secrets.OC_TOKEN }} --server=${{ vars.OC_SERVER }} - oc project ${{ vars.OC_NAMESPACE }} # Safeguard! - - # Catch errors, unset variables, and pipe failures (e.g. grep || true ) - set -euo pipefail - - # Echos - echo "Delete stale Helm releases" - echo "Cutoff: ${{ env.CUTOFF }}" - - # Before date, list of releases - BEFORE=$(date +%s -d "${{ env.CUTOFF }}") - RELEASES=$(helm ls -aq | grep ${{ github.event.repository.name }} || :) - - # If releases, then iterate - [ -z "${RELEASES}" ]|| for r in ${RELEASES[@]}; do - - # Get last update and convert the date - UPDATED=$(date "+%s" -d <<< echo $(helm status $r -o json | jq -r .info.last_deployed)) - - # Compare to cutoff and delete as necessary - if [[ ${UPDATED} < ${BEFORE} ]]; then - echo -e "\nOlder than cutoff: ${r}" - helm uninstall --no-hooks ${r} - else - echo -e "\nNewer than cutoff: ${r}" - echo "No need to delete" - fi - done + - name: ZAP Scan + uses: zaproxy/action-full-scan@v0.9.0 + with: + allow_issue_writing: true + artifact_name: "zap_${{ matrix.name }}" + cmd_options: "-a" + issue_title: "ZAP: ${{ matrix.name }}" + target: https://${{ env.PREFIX }}-${{ matrix.name }}.${{ env.DOMAIN }}