Skip to content

Commit

Permalink
chore(ci): common deployer (#746)
Browse files Browse the repository at this point in the history
  • Loading branch information
DerekRoberts authored Jan 8, 2025
1 parent d76492a commit 5b9f621
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 70 deletions.
94 changes: 94 additions & 0 deletions .github/workflows/.deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
name: .Deploys

on:
workflow_call:
inputs:
### Required
# Nothing! Only `secrets: inherit` is required

### Typical / recommended
environment:
description: GitHub/OpenShift environment; usually PR number, test or prod
type: string
tag:
description: Container tag; usually PR number
default: ${{ github.event.number }}
type: string
target:
description: Deployment target; usually PR number, test or prod
default: ${{ github.event.number }}
type: string
triggers:
description: Paths to check for changes
type: string
url:
description: URL for deployment, does not include path
type: string

permissions: {}

jobs:
init:
name: Init
environment: ${{ inputs.environment }}
outputs:
url: ${{ steps.url.outputs.url }}
runs-on: ubuntu-24.04
steps:
- name: Create URL
id: url
run: |
if [ -z "${{ inputs.url }}" ]; then
echo "Creating URL"
echo "url=fom-$(( ${{ inputs.target }} % 50 )).apps.silver.devops.gov.bc.ca" >> $GITHUB_OUTPUT
else
echo "Using URL parameter"
echo "url=${{ inputs.url }}" >> $GITHUB_OUTPUT
fi
- name: OpenShift Init
uses: bcgov-nr/[email protected]
with:
oc_namespace: ${{ vars.OC_NAMESPACE }}
oc_server: ${{ vars.OC_SERVER }}
oc_token: ${{ secrets.OC_TOKEN }}
file: libs/openshift.init.yml
overwrite: false
parameters: -p ZONE=${{ inputs.target }}
triggers: ${{ inputs.triggers }}

deploy:
name: Deploy
needs: [init]
runs-on: ubuntu-24.04
timeout-minutes: 10
strategy:
matrix:
name: [api, admin, db, public]
include:
- name: api
overwrite: true
parameters:
-p [email protected]
-p DB_TESTDATA=true
-p AWS_USER_POOLS_WEB_CLIENT_ID="7hpo4qa7j0hs0rkfl2pm0sto5k"
-p LOGOUT_CHAIN_URL="https://logontest7.gov.bc.ca/clp-cgi/logoff.cgi?retnow=1&returl=https://dev.loginproxy.gov.bc.ca/auth/realms/standard/protocol/openid-connect/logout?redirect_uri="
- name: admin
overwrite: true
- name: db
overwrite: false
- name: public
overwrite: true
steps:
- uses: bcgov-nr/[email protected]
with:
file: ${{ matrix.name }}/openshift.deploy.yml
oc_namespace: ${{ vars.OC_NAMESPACE }}
oc_server: ${{ vars.OC_SERVER }}
oc_token: ${{ secrets.OC_TOKEN }}
overwrite: ${{ matrix.overwrite }}
parameters:
-p ZONE=${{ inputs.target }} -p TAG=${{ inputs.tag }}
-p URL=${{ needs.init.outputs.url }} -p REPLICA_COUNT=1
${{ matrix.parameters }}
triggers: ${{ inputs.triggers }}
80 changes: 10 additions & 70 deletions .github/workflows/pr-open.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,8 @@ concurrency:
permissions: {}

jobs:
init:
name: Init
permissions:
pull-requests: write
runs-on: ubuntu-24.04
outputs:
route_number: ${{ steps.calculate.outputs.route_number }}
steps:
- name: Calculate the deployment number
id: calculate
run: |
echo "route_number=$((${{ github.event.number }} % 50))" >> $GITHUB_OUTPUT
- name: OpenShift Init
uses: bcgov-nr/[email protected]
with:
oc_namespace: ${{ vars.OC_NAMESPACE }}
oc_server: ${{ vars.OC_SERVER }}
oc_token: ${{ secrets.OC_TOKEN }}
file: libs/openshift.init.yml
overwrite: false
parameters: -p ZONE=${{ github.event.number }}
triggers: ('db/' 'libs/' 'api/' 'admin/' 'public/')

builds:
name: Builds
build:
name: Build
runs-on: ubuntu-24.04
permissions:
packages: write
Expand Down Expand Up @@ -70,53 +46,17 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}
triggers: ${{ matrix.triggers }}

deploys:
name: Deploys
needs: [builds, init]
runs-on: ubuntu-24.04
timeout-minutes: 10
strategy:
matrix:
name: [api, admin, db, public]
include:
- name: api
file: api/openshift.deploy.yml
overwrite: true
parameters:
-p REPLICA_COUNT=1
-p [email protected]
-p DB_TESTDATA=true
-p AWS_USER_POOLS_WEB_CLIENT_ID="7hpo4qa7j0hs0rkfl2pm0sto5k"
-p LOGOUT_CHAIN_URL="https://logontest7.gov.bc.ca/clp-cgi/logoff.cgi?retnow=1&returl=https://dev.loginproxy.gov.bc.ca/auth/realms/standard/protocol/openid-connect/logout?redirect_uri="
- name: admin
file: admin/openshift.deploy.yml
overwrite: true
parameters: -p REPLICA_COUNT=1
- name: db
file: db/openshift.deploy.yml
overwrite: false
- name: public
file: public/openshift.deploy.yml
overwrite: true
parameters: -p REPLICA_COUNT=1
steps:
- uses: bcgov-nr/[email protected]
with:
file: ${{ matrix.file }}
oc_namespace: ${{ vars.OC_NAMESPACE }}
oc_server: ${{ vars.OC_SERVER }}
oc_token: ${{ secrets.OC_TOKEN }}
overwrite: ${{ matrix.overwrite }}
penetration_test: false
parameters:
-p URL=fom-${{ needs.init.outputs.route_number }}.apps.silver.devops.gov.bc.ca
-p ZONE=${{ github.event.number }} -p TAG=${{ github.event.number }}
${{ matrix.parameters }}
triggers: ('db/' 'libs/' 'api/' 'admin/' 'public/')
deploy:
name: Deploy (${{ github.event.number }})
needs: [build]
secrets: inherit
uses: ./.github/workflows/.deploy.yml
with:
triggers: ('db/' 'libs/' 'api/' 'admin/' 'public/')

results:
name: PR Results
needs: [builds, deploys]
needs: [build, deploy]
if: always()
runs-on: ubuntu-24.04
steps:
Expand Down
2 changes: 2 additions & 0 deletions db/openshift.deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ parameters:
value: 1Gi
- name: URL
description: Dummy parameter to make workflows easier
- name: REPLICA_COUNT
description: Dummy parameter to make workflows easier
### Backup-Container starts here ###
- name: BACKUP_COMPONENT
description: BACKUP_COMPONENT name
Expand Down

0 comments on commit 5b9f621

Please sign in to comment.