Skip to content

Commit

Permalink
[NR-BCMI-1] Copy files, update config (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
sggerard authored Oct 31, 2024
1 parent 8fba0bb commit 9396eca
Show file tree
Hide file tree
Showing 400 changed files with 59,538 additions and 29,914 deletions.
Binary file added .DS_Store
Binary file not shown.
7 changes: 0 additions & 7 deletions .github/codeowners

This file was deleted.

82 changes: 41 additions & 41 deletions .github/workflows/.dbdeployer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,50 +95,50 @@ jobs:
oc login --token=$OC_TEMP_TOKEN --server=${{ inputs.oc_server }}
oc project ${{ secrets.oc_namespace }} # Safeguard!
- name: Deploy Database
working-directory: ${{ inputs.directory }}
shell: bash
run: |
echo 'Deploying crunchy helm chart'
if [ ${{ inputs.s3_enabled }} == true ]; then
helm upgrade --install --wait --set crunchy.pgBackRest.s3.enabled=true \
--set-string crunchy.pgBackRest.s3.accessKey=${{ secrets.s3_access_key }} \
--set-string crunchy.pgBackRest.s3.secretKey=${{ secrets.s3_secret_key }} \
--set-string crunchy.pgBackRest.s3.bucket=${{ secrets.s3_bucket }} \
--set-string crunchy.pgBackRest.s3.endpoint=${{ secrets.s3_endpoint }} \
--values ${{ inputs.values }} postgres .
else
helm upgrade --install --wait --values ${{ inputs.values }} postgres .
fi
# - name: Deploy Database
# working-directory: ${{ inputs.directory }}
# shell: bash
# run: |
# echo 'Deploying crunchy helm chart'
# if [ ${{ inputs.s3_enabled }} == true ]; then
# helm upgrade --install --wait --set crunchy.pgBackRest.s3.enabled=true \
# --set-string crunchy.pgBackRest.s3.accessKey=${{ secrets.s3_access_key }} \
# --set-string crunchy.pgBackRest.s3.secretKey=${{ secrets.s3_secret_key }} \
# --set-string crunchy.pgBackRest.s3.bucket=${{ secrets.s3_bucket }} \
# --set-string crunchy.pgBackRest.s3.endpoint=${{ secrets.s3_endpoint }} \
# --values ${{ inputs.values }} postgres .
# else
# helm upgrade --install --wait --values ${{ inputs.values }} postgres .
# fi

- name: Add PR specific user to Crunchy DB # only for PRs
shell: bash
if: github.event_name == 'pull_request'
run: |
echo 'Adding PR specific user to Crunchy DB'
NEW_USER='{"databases":["app-${{ github.event.number }}"],"name":"app-${{ github.event.number }}"}'
CURRENT_USERS=$(oc get PostgresCluster/postgres-crunchy -o json | jq '.spec.users')
echo "${CURRENT_USERS}"
# - name: Add PR specific user to Crunchy DB # only for PRs
# shell: bash
# if: github.event_name == 'pull_request'
# run: |
# echo 'Adding PR specific user to Crunchy DB'
# NEW_USER='{"databases":["app-${{ github.event.number }}"],"name":"app-${{ github.event.number }}"}'
# CURRENT_USERS=$(oc get PostgresCluster/postgres-crunchy -o json | jq '.spec.users')
# echo "${CURRENT_USERS}"

# check if current_users already contains the new_user
if echo "${CURRENT_USERS}" | jq -e ".[] | select(.name == \"app-${{ github.event.number }}\")" > /dev/null; then
echo "User already exists"
exit 0
fi
# # check if current_users already contains the new_user
# if echo "${CURRENT_USERS}" | jq -e ".[] | select(.name == \"app-${{ github.event.number }}\")" > /dev/null; then
# echo "User already exists"
# exit 0
# fi

UPDATED_USERS=$(echo "${CURRENT_USERS}" | jq --argjson NEW_USER "${NEW_USER}" '. + [$NEW_USER]')
PATCH_JSON=$(jq -n --argjson users "${UPDATED_USERS}" '{"spec": {"users": $users}}')
oc patch PostgresCluster/postgres-crunchy --type=merge -p "${PATCH_JSON}"
# UPDATED_USERS=$(echo "${CURRENT_USERS}" | jq --argjson NEW_USER "${NEW_USER}" '. + [$NEW_USER]')
# PATCH_JSON=$(jq -n --argjson users "${UPDATED_USERS}" '{"spec": {"users": $users}}')
# oc patch PostgresCluster/postgres-crunchy --type=merge -p "${PATCH_JSON}"

# wait for sometime as it takes time to create the user, query the secret and check if it is created, otherwise wait in a loop for 5 rounds
for i in {1..5}; do
if oc get secret postgres-crunchy-pguser-app-${{ github.event.number }} -o jsonpath='{.metadata.name}' > /dev/null; then
echo "Secret created"
break
else
echo "Secret not created, waiting for 60 seconds"
sleep 60
fi
done
# # wait for sometime as it takes time to create the user, query the secret and check if it is created, otherwise wait in a loop for 5 rounds
# for i in {1..5}; do
# if oc get secret postgres-crunchy-pguser-app-${{ github.event.number }} -o jsonpath='{.metadata.name}' > /dev/null; then
# echo "Secret created"
# break
# else
# echo "Secret not created, waiting for 60 seconds"
# sleep 60
# fi
# done


2 changes: 1 addition & 1 deletion .github/workflows/.deployer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ on:
required: false
type: string
triggers:
description: Paths used to trigger a deployment; e.g. ('./backend/' './frontend/)
description: Paths used to trigger a deployment; e.g. ('./cms/' './frontend/)
required: false
type: string
db_user:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/.tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ jobs:
runs-on: ubuntu-24.04
strategy:
matrix:
name: [backend, frontend]
name: [cms, frontend]
steps:
- uses: actions/checkout@v4
- uses: grafana/[email protected]
env:
BACKEND_URL: https://${{ env.PREFIX }}-frontend.${{ env.DOMAIN }}/api
CMS_URL: https://${{ env.PREFIX }}-frontend.${{ env.DOMAIN }}/api
FRONTEND_URL: https://${{ env.PREFIX }}-frontend.${{ env.DOMAIN }}
with:
filename: ./tests/load/${{ matrix.name }}-test.js
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ jobs:
- 5432:5432
strategy:
matrix:
dir: [backend, frontend]
dir: [cms, frontend]
include:
- dir: backend
token: SONAR_TOKEN_BACKEND
- dir: cms
token: SONAR_TOKEN_CMS
- dir: frontend
token: SONAR_TOKEN_FRONTEND
steps:
Expand Down
119 changes: 60 additions & 59 deletions .github/workflows/merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,63 +32,64 @@ jobs:
- name: PR Number
id: pr
uses: bcgov-nr/[email protected]
deploy_db:
name: Deploys Database
uses: ./.github/workflows/.dbdeployer.yml
secrets:
oc_namespace: ${{ secrets.OC_NAMESPACE }}
oc_token: ${{ secrets.OC_TOKEN }}
with:
environment: test
# https://github.com/bcgov/quickstart-openshift-helpers
deploy-test:
name: Deploy (test)
uses: ./.github/workflows/.deployer.yml
secrets:
oc_namespace: ${{ secrets.OC_NAMESPACE }}
oc_token: ${{ secrets.OC_TOKEN }}
with:
environment: test
db_user: app
# deploy_db:
# name: Deploys Database
# uses: ./.github/workflows/.dbdeployer.yml
# secrets:
# oc_namespace: ${{ secrets.OC_NAMESPACE }}
# oc_token: ${{ secrets.OC_TOKEN }}
# with:
# environment: test
# # https://github.com/bcgov/quickstart-openshift-helpers

# deploy-test:
# name: Deploy (test)
# uses: ./.github/workflows/.deployer.yml
# secrets:
# oc_namespace: ${{ secrets.OC_NAMESPACE }}
# oc_token: ${{ secrets.OC_TOKEN }}
# with:
# environment: test
# db_user: app

deploy_db_prod:
name: Deploys Database PROD
uses: ./.github/workflows/.dbdeployer.yml
secrets:
oc_namespace: ${{ secrets.OC_NAMESPACE }}
oc_token: ${{ secrets.OC_TOKEN }}
with:
environment: prod
deploy-prod:
name: Deploy (prod)
needs: [deploy-test, vars]
uses: ./.github/workflows/.deployer.yml
secrets:
oc_namespace: ${{ secrets.OC_NAMESPACE }}
oc_token: ${{ secrets.OC_TOKEN }}
with:
environment: prod
db_user: app
params:
--set backend.deploymentStrategy=RollingUpdate
--set frontend.deploymentStrategy=RollingUpdate
--set global.autoscaling=true
--set frontend.pdb.enabled=true
--set backend.pdb.enabled=true
promote:
name: Promote Images
needs: [deploy-prod, vars]
runs-on: ubuntu-24.04
permissions:
packages: write
strategy:
matrix:
package: [migrations, backend, frontend]
timeout-minutes: 1
steps:
- uses: shrink/actions-docker-registry-tag@v4
with:
registry: ghcr.io
repository: ${{ github.repository }}/${{ matrix.package }}
target: ${{ needs.vars.outputs.pr }}
tags: prod
# deploy_db_prod:
# name: Deploys Database PROD
# uses: ./.github/workflows/.dbdeployer.yml
# secrets:
# oc_namespace: ${{ secrets.OC_NAMESPACE }}
# oc_token: ${{ secrets.OC_TOKEN }}
# with:
# environment: prod
# deploy-prod:
# name: Deploy (prod)
# needs: [deploy-test, vars]
# uses: ./.github/workflows/.deployer.yml
# secrets:
# oc_namespace: ${{ secrets.OC_NAMESPACE }}
# oc_token: ${{ secrets.OC_TOKEN }}
# with:
# environment: prod
# db_user: app
# params:
# --set cms.deploymentStrategy=RollingUpdate
# --set frontend.deploymentStrategy=RollingUpdate
# --set global.autoscaling=true
# --set frontend.pdb.enabled=true
# --set cms.pdb.enabled=true
# promote:
# name: Promote Images
# needs: [deploy-prod, vars]
# runs-on: ubuntu-24.04
# permissions:
# packages: write
# strategy:
# matrix:
# package: [cms, frontend]
# timeout-minutes: 1
# steps:
# - uses: shrink/actions-docker-registry-tag@v4
# with:
# registry: ghcr.io
# repository: ${{ github.repository }}/${{ matrix.package }}
# target: ${{ needs.vars.outputs.pr }}
# tags: prod
4 changes: 2 additions & 2 deletions .github/workflows/pr-close.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
oc_token: ${{ secrets.OC_TOKEN }}
with:
cleanup: helm
packages: backend frontend migrations
packages: cms frontend
cleanup_db: # TODO move it off to another action later.
name: Remove DB User from crunchy.
runs-on: ubuntu-24.04
Expand Down Expand Up @@ -61,7 +61,7 @@ jobs:
echo "${CRUNCHY_PG_PRIMARY_POD_NAME}"
# Terminate all connections to the database before trying terminate
oc exec "${CRUNCHY_PG_PRIMARY_POD_NAME}" -- psql -c "SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = 'app-${{ github.event.number }}' AND pid <> pg_backend_pid();"
oc exec "${CRUNCHY_PG_PRIMARY_POD_NAME}" -- psql -c "SELECT pg_terminate_cms(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = 'app-${{ github.event.number }}' AND pid <> pg_cms_pid();"
# Drop the database and role
oc exec "${CRUNCHY_PG_PRIMARY_POD_NAME}" -- psql -c "DROP DATABASE \"app-${{ github.event.number }}\" --cascade"
Expand Down
32 changes: 16 additions & 16 deletions .github/workflows/pr-open.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-24.04
strategy:
matrix:
package: [backend, frontend, migrations]
package: [cms, frontend]
timeout-minutes: 10
steps:
- uses: bcgov-nr/[email protected]
Expand All @@ -26,12 +26,12 @@ jobs:
tag_fallback: latest
triggers: ('${{ matrix.package }}/')

deploy_db:
name: Deploys Database
uses: ./.github/workflows/.dbdeployer.yml
secrets:
oc_namespace: ${{ secrets.OC_NAMESPACE }}
oc_token: ${{ secrets.OC_TOKEN }}
# deploy_db:
# name: Deploys Database
# uses: ./.github/workflows/.dbdeployer.yml
# secrets:
# oc_namespace: ${{ secrets.OC_NAMESPACE }}
# oc_token: ${{ secrets.OC_TOKEN }}

# https://github.com/bcgov/quickstart-openshift-helpers
deploys:
Expand All @@ -42,21 +42,21 @@ jobs:
oc_namespace: ${{ secrets.OC_NAMESPACE }}
oc_token: ${{ secrets.OC_TOKEN }}
with:
triggers: ('backend/' 'frontend/' 'migrations/' 'charts/')
triggers: ('cms/' 'frontend/' 'charts/')
db_user: app-${{github.event.number}}
params: --set global.secrets.persist=false

tests:
name: Tests
if: needs.deploys.outputs.triggered == 'true'
needs: [deploys]
uses: ./.github/workflows/.tests.yml
with:
target: ${{ github.event.number }}
# tests:
# name: Tests
# if: needs.deploys.outputs.triggered == 'true'
# needs: [deploys]
# uses: ./.github/workflows/.tests.yml
# with:
# target: ${{ github.event.number }}

results:
name: PR Results
needs: [builds, deploys, tests]
needs: [builds, deploys]
if: always()
runs-on: ubuntu-24.04
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
with:
markdown_links: |
- [Frontend](https://${{ github.event.repository.name }}-${{ github.event.number }}-frontend.apps.silver.devops.gov.bc.ca)
- [Backend](https://${{ github.event.repository.name }}-${{ github.event.number }}-frontend.apps.silver.devops.gov.bc.ca/api)
- [CMS](https://${{ github.event.repository.name }}-${{ github.event.number }}-frontend.apps.silver.devops.gov.bc.ca/api)
results:
name: Validate Results
Expand Down
Loading

0 comments on commit 9396eca

Please sign in to comment.