Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: CE-436-New pipeline #29

Merged
merged 13 commits into from
Feb 29, 2024
119 changes: 119 additions & 0 deletions .github/workflows/.deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
name: .Deploys

on:
workflow_call:
inputs:
### Required
release:
description: Deployment release; usually PR number, test or prod
required: true
type: string

### Typical / recommended
autoscaling:
description: Autoscaling enabled or not for the deployments
required: false
type: string
default: false
build_outputs:
description: Build outputs
required: false
type: string
default: 'true'
environment:
description: Environment name; omit for PRs
required: false
type: string
tag:
description: Container tag; usually PR number
required: false
type: string
default: ${{ github.event.number }}
test:
description: Run tests after deployment?
required: false
type: string
default: "true"

### Usually a bad idea / not recommended
directory:
description: 'Chart directory'
default: 'charts/${{ github.event.repository.name }}'
required: false
type: string
timeout-minutes:
description: 'Timeout minutes'
default: 10
required: false
type: number
values:
description: 'Values file'
default: 'values.yaml'
required: false
type: string
params:
description: 'Extra parameters to pass to helm upgrade'
default: ''
required: false
type: string

env:
repo_release: ${{ github.event.repository.name }}-${{ inputs.release }}
package_tag: ${{ inputs.tag }}

jobs:
deploys:
name: Helm
if: ${{ inputs.build_outputs != '' }}
environment: ${{ inputs.environment }}
runs-on: ubuntu-22.04
timeout-minutes: ${{ inputs.timeout-minutes }}
steps:
- uses: actions/checkout@v4
- name: Deploy
working-directory: ${{ inputs.directory }}
shell: bash
run: |
oc login --token=${{ secrets.oc_token }} --server=${{ vars.oc_server }}
oc project ${{ vars.OC_NAMESPACE }} # Safeguard!

# Interrupt any previous jobs (status = pending-upgrade)
PREVIOUS=$(helm status ${{ env.repo_release }} -o json | jq .info.status || true)
if [[ ${PREVIOUS} =~ pending ]]; then
echo "Rollback triggered"
helm rollback ${{ env.repo_release }} || \
helm uninstall ${{ env.repo_release }}
fi
# Clean previous deployments for PR pipeline, if any
if [[ '${{inputs.environment}}' == '' ]]; then
helm uninstall ${{ env.repo_release }} || true
fi
# Deploy Helm Chart
helm dependency update
helm package --app-version="${{ env.package_tag }}" --version=${{ inputs.tag }} .

helm upgrade \
--set global.autoscaling=${{ inputs.autoscaling }} \
--set-string global.repository=${{ github.repository }} \
--set-string global.secrets.databasePassword=${{ secrets.DB_PASSWORD }} \
--set-string backend.containers[0].tag="${{ env.package_tag }}" \
--set-string backend.initContainers[0].tag="${{ env.package_tag }}" \
${{ inputs.params }} \
--install --wait --atomic ${{ env.repo_release }} \
--timeout ${{ inputs.timeout-minutes }}m \
--values ${{ inputs.values }} \
./${{ github.event.repository.name }}-${{ inputs.tag }}.tgz

# print history
helm history ${{ env.repo_release }}

# Remove old build runs, build pods and deployment pods
oc delete po --field-selector=status.phase==Succeeded

tests:
name: Tests
needs: [deploys]
if: ${{ inputs.test == 'true' && inputs.build_outputs != '' }}
uses: ./.github/workflows/.tests.yml
with:
target: ${{ inputs.release }}
126 changes: 0 additions & 126 deletions .github/workflows/.push-helm-chart.yml

This file was deleted.

32 changes: 32 additions & 0 deletions .github/workflows/.tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: .Tests

on:
workflow_call:
inputs:
### Typical / recommended
target:
description: PR number, test or prod
required: false
type: string
default: test

env:
DOMAIN: apps.silver.devops.gov.bc.ca
PREFIX: ${{ github.event.repository.name }}-${{ inputs.target }}

jobs:

load-tests:
name: Load
runs-on: ubuntu-22.04
strategy:
matrix:
name: [backend]
steps:
- uses: actions/checkout@v4
- uses: grafana/k6-action@v0.3.1
env:
BACKEND_URL: https://${{ env.PREFIX }}-backend.${{ env.DOMAIN }}/api
with:
filename: ./load-test/${{ matrix.name }}-test.js
flags: --vus 10 --duration 30s
Loading
Loading