generated from bcgov/quickstart-openshift
-
Notifications
You must be signed in to change notification settings - Fork 1
116 lines (106 loc) · 3.75 KB
/
.deploy.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
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-24.04
timeout-minutes: ${{ inputs.timeout-minutes }}
steps:
- uses: actions/checkout@v4
- uses: redhat-actions/openshift-tools-installer@v1
with:
oc: "4.14"
- 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
# Remove Bitnami Postgres PVCs
oc delete pvc data-${{ env.repo_release }}-bitnami-pg-0 || \
echo "Not found: pvc data-${{ env.repo_release }}-bitnami-pg-0"
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.tag=${{ inputs.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