Skip to content

Feature/chart summary sentences #432

Feature/chart summary sentences

Feature/chart summary sentences #432

name: Build And Deploy to Sandbox in Dev namespace
on:
pull_request:
branches:
- main
concurrency:
# PR open and close use the same group, allowing only one at a time
group: pr-${{ github.workflow }}-${{ github.event.number }}
cancel-in-progress: true
jobs:
pr-description-add:
name: PR Description Add
runs-on: ubuntu-22.04
permissions:
pull-requests: write
timeout-minutes: 1
steps:
- uses: bcgov-nr/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
add_markdown: |
---
Thanks for the PR!
Deployments, as required, will be available below:
- [Frontend](https://pay-transparency-pr-${{ github.event.number }}-frontend.apps.silver.devops.gov.bc.ca)
builds:
if: '!github.event.pull_request.head.repo.fork'
name: Build Containers for OpenShift Deployment
runs-on: ubuntu-22.04
permissions:
packages: write
strategy:
matrix:
package: [backend, database, database-migrations, frontend, doc-gen-service]
include:
- package: backend
triggers: ('backend/')
build_file: ./backend/Dockerfile
build_context: ./backend
- package: database
triggers: ('database/')
build_file: ./database/Dockerfile
build_context: ./database
- package: frontend
triggers: ('frontend/')
build_file: ./frontend/Dockerfile
build_context: ./frontend
- package: database-migrations
triggers: ('backend/db')
build_file: ./backend/db/Dockerfile
build_context: ./backend/db
- package: doc-gen-service
triggers: ('doc-gen-service/')
build_file: ./doc-gen-service/Dockerfile
build_context: ./doc-gen-service
steps:
- uses: actions/checkout@v4
- uses: bcgov-nr/[email protected]
with:
package: ${{ matrix.package }}
tag: ${{ github.event.number }}
tag_fallback: test
build_context: ${{ matrix.build_context }}
- uses: shrink/actions-docker-registry-tag@v3
with:
registry: ghcr.io
repository: ${{ github.repository }}/${{ matrix.package }}
target: ${{ github.event.number }}
tags: |
pr-${{ github.event.number }}
${{ github.sha }}
${{ github.event.number }}
check-quota:
name: Check Quota
runs-on: ubuntu-22.04
environment: dev
steps:
- name: Check Quota For Deployment
shell: bash
run: |
# Allow pipefail, since we could be catching oc create errors
set +o pipefail
# Login to OpenShift (NOTE: project command is a safeguard)
oc login --token=${{ secrets.oc_token }} --server=${{ vars.oc_server }}
oc project ${{ vars.oc_namespace }}
#check helm status to see if this is an already deployed PR or a new PR
DEPLOYMENT_STATUS=$(helm status pay-transparency-pr-${{ github.event.number }} -o json | jq .info.status || false)
echo "DEPLOYMENT_STATUS is '$DEPLOYMENT_STATUS'"
# if deployment status is false or blank, then this is a new PR and we need to check quota
if [[ $DEPLOYMENT_STATUS == "" ]] || [[ $DEPLOYMENT_STATUS == "false" ]]; then
echo "This is a new PR, checking quota"
# PRINT QUOTA
oc describe quota compute-long-running-quota
QUOTA=$(oc get quota compute-long-running-quota -o json | jq -r '.status.used."limits.cpu"')
# if quota contains 'm' get only the number by removing the last character
if [[ $QUOTA == *"m"* ]]; then
QUOTA=${QUOTA::-1}
fi
echo "USED QUOTA: $QUOTA"
# find available quota by subtracting from the total quota
AVL_QUOTA=$((4000-$QUOTA))
echo "AVL_QUOTA: $AVL_QUOTA"
#Total quota required for PR to deploy is backend + database + frontend = 480 milli cores.
if [[ $AVL_QUOTA -lt 500 ]]; then
echo "Not Enough Resource(CPU Limits) Quota not available to deploy PR"
exit 1
else
echo "Quota available for deployment."
exit 0
fi
else
echo "This is an already deployed PR, skipping quota check"
exit 0
fi
deploys:
name: Deploys
needs: [builds, check-quota]
uses: ./.github/workflows/.deploy.yml
secrets: inherit
with:
autoscaling: false
penetration-test: false
target: pr-${{ github.event.number }}
tag: ${{ github.sha }}
values: 'values-pr.yaml'
frontend-url: https://pay-transparency-pr-${{ github.event.number }}-frontend.apps.silver.devops.gov.bc.ca