-
Notifications
You must be signed in to change notification settings - Fork 10
233 lines (224 loc) · 8.29 KB
/
delivery-ci.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
name: Delivery CI
on:
push:
branches:
- main
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
inputs:
AFFECTED_BASE:
description: Value for --base= in nx affected commands
required: false
jobs:
build:
runs-on: ubuntu-22.04
outputs:
affected_apps: ${{ steps.set_outputs.outputs.affected_apps }}
affected_apps_array: ${{ steps.set_outputs.outputs.affected_apps_array }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
- uses: actions/setup-dotnet@v4
with:
dotnet-version: '9'
- uses: actions/setup-java@v4
with:
java-version: '17'
distribution: temurin
cache: maven
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- uses: snok/install-poetry@v1
with:
version: '1.6.1'
- run: npm ci
- name: Get last successful commit
id: last_successful_commit
uses: nrwl/nx-set-shas@v3
- name: Build
id: production-build
uses: ./.github/actions/nx-production-build
with:
affected-base: ${{ github.event.inputs.AFFECTED_BASE || steps.last_successful_commit.outputs.base }}
github_token: ${{ secrets.GITHUB_TOKEN }}
npm_token: ${{ secrets.NPM_TOKEN }}
- run: npm prune --production
- if: steps.production-build.outputs.affected-apps
run: tar czf adsp-build-dist.tar.gz node_modules/ dist/
- if: steps.production-build.outputs.affected-apps
uses: actions/upload-artifact@v4
with:
name: build-dist
path: adsp-build-dist.tar.gz
# Set build job outputs for subsequent jobs.
- id: set_outputs
run: |
echo "affected_apps=${{ steps.production-build.outputs.affected-apps }}" >> $GITHUB_OUTPUT
echo "affected_apps_array=$(echo ${{ steps.production-build.outputs.affected-apps }} | sed -e "s/ /\",\"/g" -e "s/^/[\"/" -e "s/$/\"]/")" >> $GITHUB_OUTPUT
buildContainers:
runs-on: ubuntu-24.04
needs: build
if: needs.build.outputs.affected_apps
strategy:
fail-fast: false
matrix:
app: ${{ fromJson(needs.build.outputs.affected_apps_array) }}
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: build-dist
path: ./
- run: tar -xf adsp-build-dist.tar.gz
- name: Build container
uses: ./.github/actions/build-publish-container
with:
app: ${{ matrix.app }}
redhat-io-username: ${{ secrets.REGISTRY_REDHAT_IO_USER }}
redhat-io-password: ${{ secrets.REGISTRY_REDHAT_IO_PASSWORD }}
build-context: ${{ hashFiles(format('./dist/apps/{0}/nginx.conf', matrix.app)) && format('./dist/apps/{0}', matrix.app) || './' }}
container-file: ${{ hashFiles(format('./apps/{0}/Dockerfile', matrix.app)) && format('./apps/{0}/Dockerfile', matrix.app) || './.openshift/service/Dockerfile' }}
ghcr-token: ${{ secrets.GITHUB_TOKEN }}
deployDev:
runs-on: ubuntu-22.04
needs: [build, buildContainers]
strategy:
fail-fast: true
max-parallel: 2
matrix:
app: ${{ fromJson(needs.build.outputs.affected_apps_array) }}
environment:
name: Dev
steps:
- uses: actions/checkout@v4
- name: Oc login
uses: redhat-actions/oc-login@v1
with:
openshift_server_url: ${{ secrets.ARO_SERVER }}
openshift_token: ${{ secrets.ARO_TOKEN }}
namespace: adsp-build
insecure_skip_tls_verify: true
- name: Tag Dev
run: |
oc import-image ghcr.io/govalta/${{ matrix.app }}:latest --reference-policy='local' --confirm
oc tag ${{ matrix.app }}:latest ${{ matrix.app }}:dev --reference-policy='local'
- run: oc project adsp-dev
- name: Apply Manifests
run: |
oc process -f .openshift/managed/${{ matrix.app }}.yml -p INFRA_NAMESPACE=adsp-build -p NAMESPACE=adsp-dev -p DEPLOY_TAG=dev > ${{ matrix.app }}.dev.json
oc apply -f ${{ matrix.app }}.dev.json -l apply-dev=true,component!=database
- name: Deploy Dev
run: |
if oc get dc/${{ matrix.app }} ; then
oc rollout latest dc/${{ matrix.app }}
oc rollout status dc/${{ matrix.app }}
elif oc get deployment/${{ matrix.app }} ; then
oc set triggers deployment/${{ matrix.app }} --auto
oc rollout status deployment/${{ matrix.app }}
oc set triggers deployment/${{ matrix.app }} --manual
else
echo 'No DeploymentConfig or Deployment found for ${{ matrix.app }}.'
fi
devSmokeTest:
runs-on: ubuntu-22.04
needs: [build, deployDev]
environment:
name: Dev-e2e
strategy:
matrix:
app: [tenant-management-webapp, status-app, subscriber-app]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
- name: E2E Test
uses: ./.github/actions/nx-cypress-e2e
with:
app: ${{ matrix.app }}
environment: dev
tags: '@smoke-test and not @ignore'
core-api-client-secret: ${{ secrets.CY_CORE_API_CLIENT_SECRET }}
core-api-user-password: ${{ secrets.CY_CORE_API_USER_PASSWORD }}
api-client-secret: ${{ secrets.CY_CLIENT_SECRET }}
cy-password: ${{ secrets.CY_PASSWORD }}
cy-password-2: ${{ secrets.CY_PASSWORD2 }}
cy-password-3: ${{ secrets.CY_PASSWORD3 }}
deployStagingApproval:
runs-on: ubuntu-22.04
needs: [build, devSmokeTest]
environment:
name: Staging-gate
steps:
- run: echo "Staging deployment approved"
deployStaging:
runs-on: ubuntu-22.04
needs: [build, deployStagingApproval]
strategy:
fail-fast: true
max-parallel: 2
matrix:
app: ${{ fromJson(needs.build.outputs.affected_apps_array) }}
environment:
name: Staging
steps:
- uses: actions/checkout@v4
- name: Oc login
uses: redhat-actions/oc-login@v1
with:
openshift_server_url: ${{ secrets.ARO_SERVER }}
openshift_token: ${{ secrets.ARO_TOKEN }}
namespace: adsp-build
insecure_skip_tls_verify: true
- name: Tag Staging
run: oc tag ${{ matrix.app }}:dev ${{ matrix.app }}:uat --reference-policy='local'
- run: oc project adsp-uat
- name: Apply Manifests
run: |
oc process -f .openshift/managed/${{ matrix.app }}.yml -p INFRA_NAMESPACE=adsp-build -p NAMESPACE=adsp-uat -p DEPLOY_TAG=uat > ${{ matrix.app }}.uat.json
oc apply -f ${{ matrix.app }}.uat.json -l apply-staging=true,component!=database
- name: Deploy Staging
run: |
if oc get dc/${{ matrix.app }} ; then
oc rollout latest dc/${{ matrix.app }}
oc rollout status dc/${{ matrix.app }}
elif oc get deployment/${{ matrix.app }} ; then
oc set triggers deployment/${{ matrix.app }} --auto
oc rollout status deployment/${{ matrix.app }}
oc set triggers deployment/${{ matrix.app }} --manual
else
echo 'No DeploymentConfig or Deployment found for ${{ matrix.app }}.'
fi
stagingSmokeTest:
runs-on: ubuntu-22.04
needs: [build, deployStaging]
environment:
name: Staging-e2e
strategy:
matrix:
app: [tenant-management-webapp, status-app, subscriber-app]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
- name: E2E Test
uses: ./.github/actions/nx-cypress-e2e
with:
app: ${{ matrix.app }}
environment: staging
tags: '@smoke-test and not @ignore'
core-api-client-secret: ${{ secrets.CY_CORE_API_CLIENT_SECRET }}
core-api-user-password: ${{ secrets.CY_CORE_API_USER_PASSWORD }}
api-client-secret: ${{ secrets.CY_CLIENT_SECRET }}
cy-password: ${{ secrets.CY_PASSWORD }}
cy-password-2: ${{ secrets.CY_PASSWORD2 }}
cy-password-3: ${{ secrets.CY_PASSWORD3 }}