-
Notifications
You must be signed in to change notification settings - Fork 0
239 lines (231 loc) · 8.99 KB
/
test.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
234
235
236
237
238
239
name: "Tests"
on:
push:
paths-ignore:
- "documentation/**"
- "templates/**"
jobs:
# Make data lists available across jobs for use in matrix.
matrix:
runs-on: "ubuntu-latest"
outputs:
all-apps: ${{ steps.set-apps.outputs.full-json }}
deploy-apps: ${{ steps.set-apps.outputs.deploy-json }}
all-environments: ${{ steps.set-environments.outputs.full-json }}
deploy-environments: ${{ steps.set-environments.outputs.deploy-json }}
steps:
- name: "Checkout repository"
uses: "actions/checkout@v3"
- id: "set-apps"
name: "Read apps into matrix"
uses: "./.github/actions/set-json-output"
with:
filename: "data/apps.json"
- id: "set-environments"
name: "Read environments into matrix"
uses: "./.github/actions/set-json-output"
with:
filename: "data/environments.json"
# Update the pip cache with new requirements.
update-pip-cache:
runs-on: "ubuntu-latest"
steps:
- name: "Checkout repository"
uses: "actions/checkout@v3"
- name: "Setup python cache"
uses: "actions/setup-python@v4"
with:
python-version: "3.13"
cache: "pip"
- name: "Fill python cache"
run: "pip install -r ./backend/requirements.txt -r ./backend/requirements-develop.txt"
# Generate the protos.
generate-protos:
runs-on: "ubuntu-latest"
needs: [ "update-pip-cache" ]
steps:
- name: "Checkout repository"
uses: "actions/checkout@v3"
- name: "Setup python cache"
uses: "actions/setup-python@v4"
with:
python-version: "3.13"
cache: "pip"
- name: "Generate protos"
run: "./scripts/generate_protos.sh"
- name: "Upload python protos"
uses: "actions/upload-artifact@v4"
with:
name: "protos-python"
path: "backend/khaleesi/proto/"
retention-days: 2
- name: "Upload typescript protos"
uses: "actions/upload-artifact@v4"
with:
name: "protos-typescript"
path: "frontend/khaleesi/app/khaleesi/proto/"
retention-days: 2
# Build the backend base images with new requirements.
build-backend-base-images:
runs-on: "ubuntu-latest"
needs: [ "update-pip-cache" ]
strategy:
matrix:
image: [ "construction", "image" ]
env:
base-image-version: "1.0.0"
steps:
- name: "Checkout repository"
uses: "actions/checkout@v3"
- name: "Setup python cache"
uses: "actions/setup-python@v4"
with:
python-version: "3.13"
cache: "pip"
- name: "Build image"
run: ./scripts/util/build-backend-base.sh ${{ env.base-image-version }} ${{ matrix.image }}
- name: "Upload image as artifact"
uses: "./.github/actions/upload-image"
with:
image: khaleesi/base/backend-${{ matrix.image }}:${{ env.base-image-version }}
# Verify the helm templates.
test-helm:
runs-on: "ubuntu-latest"
needs: [ "matrix" ]
strategy:
matrix:
app: ${{ fromJson(needs.matrix.outputs.deploy-apps) }}
environment: ${{ fromJson(needs.matrix.outputs.all-environments) }}
steps:
- name: "Checkout repository"
uses: "actions/checkout@v3"
- name: "Helm lint cluster"
run: "helm lint ./kubernetes/khaleesi-ninja-cluster"
- name: "Helm lint environment"
run: |
helm lint ./kubernetes/khaleesi-ninja-environment \
--values ./kubernetes/configuration/environment/${{ matrix.environment.name }}.yml
- name: "Helm lint site"
run: |
helm lint ./kubernetes/khaleesi-ninja-site \
--values ./kubernetes/configuration/site/${{ matrix.app.site }}.yml \
--values ./kubernetes/configuration/environment/${{ matrix.environment.name }}.yml
- name: "Helm lint app"
run: |
helm lint ./kubernetes/khaleesi-ninja-app \
--values ./kubernetes/configuration/site/${{ matrix.app.site }}.yml \
--values ./kubernetes/configuration/type/${{ matrix.app.type }}.yml \
--values ./kubernetes/configuration/app/${{ matrix.app.site }}/${{ matrix.app.name }}.yml \
--values ./kubernetes/configuration/environment/${{ matrix.environment.name }}.yml
# Build the images for reuse.
build:
runs-on: "ubuntu-latest"
needs: [ "matrix", "generate-protos", "build-backend-base-images" ]
strategy:
matrix:
app: ${{ fromJson(needs.matrix.outputs.all-apps) }}
env:
base-image-version: "1.0.0"
steps:
- name: "Checkout repository"
uses: "actions/checkout@v3"
- name: "Prepare backend build"
if: matrix.app.type == 'micro'
uses: "./.github/actions/prepare-backend-build"
with:
site: ${{ matrix.app.site }}
app: ${{ matrix.app.name }}
- name: "Download typescript protos"
if: matrix.app.type == 'frontend'
uses: "actions/download-artifact@v4"
with:
name: "protos-typescript"
path: frontend/${{ matrix.app.site }}/app/khaleesi/proto/
- name: "Build the development container image"
run: ./scripts/build.sh ${{ matrix.app.site }} ${{ matrix.app.name }} ${{ matrix.app.type }} ${{ matrix.app.version }} ${{ matrix.app.deploy }} development
- name: "Build the production container image"
run: ./scripts/build.sh ${{ matrix.app.site }} ${{ matrix.app.name }} ${{ matrix.app.type }} ${{ matrix.app.version }} ${{ matrix.app.deploy }} production
- name: "Upload development image"
uses: "./.github/actions/upload-image"
with:
image: khaleesi-ninja/${{ matrix.app.site }}/${{ matrix.app.name }}:latest-development
- name: "Upload production image"
uses: "./.github/actions/upload-image"
with:
image: khaleesi-ninja/${{ matrix.app.site }}/${{ matrix.app.name }}:latest-production
# Execute the unit tests in parallel.
unit-test:
runs-on: "ubuntu-latest"
needs: [ "matrix", "build" ]
strategy:
matrix:
app: ${{ fromJson(needs.matrix.outputs.all-apps) }}
steps:
- name: "Checkout repository"
uses: "actions/checkout@v3"
- name: "Download image"
uses: "./.github/actions/download-image"
with:
image: khaleesi-ninja/${{ matrix.app.site }}/${{ matrix.app.name }}:latest-development
- name: "Execute the container test"
run: ./scripts/test.sh ${{ matrix.app.site }} ${{ matrix.app.name }} ${{ matrix.app.type }} ${{ matrix.app.version }} ${{ matrix.app.deploy }}
- name: "Upload coverage to codecov"
if: ${{ always() }}
uses: "codecov/codecov-action@v3"
with:
token: ${{secrets.CODECOV_TOKEN}}
flags: "integration"
fail_ci_if_error: true
directory: "temp/"
# Execute the E2E tests in parallel.
e2e-test:
runs-on: "ubuntu-latest"
needs: [ "matrix", "build", "test-helm" ]
strategy:
matrix:
environment: ${{ fromJson(needs.matrix.outputs.deploy-environments) }}
steps:
- name: "Checkout repository"
uses: "actions/checkout@v3"
- name: "Start minikube"
uses: "medyagh/setup-minikube@latest"
- name: "Setup helm"
uses: "azure/setup-helm@v3"
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: "Set up the cluster"
run: "./scripts/operations/setup_cluster.sh"
- name: "Set up the environment"
run: ./scripts/operations/setup_environment.sh ${{ matrix.environment.name }}
- name: "Download all images"
uses: "actions/download-artifact@v4"
with:
pattern: khaleesi-ninja_*_*.latest-${{ matrix.environment.container_mode }}
path: /tmp
merge-multiple: true
- name: "Load all images into minikube"
run: ls -1 /tmp/khaleesi-ninja_*_*.latest-${{ matrix.environment.container_mode }} | xargs --no-run-if-empty -L 1 minikube image load
- name: "Wait for the environment to be ready"
run: kubectl -n "khaleesi-ninja-${{ matrix.environment.name }}" wait pod -l job!=true --for condition=ready --timeout 5m
- name: "Spin up the environment"
run: ./scripts/ci/deploy.sh ${{ matrix.environment.name }}
- name: "Wait for successful spinup"
run: kubectl -n khaleesi-ninja-${{ matrix.environment.name }} wait pod -l job!=true --for condition=ready --timeout 2m
- name: "Check the status"
if: always()
run: kubectl -n khaleesi-ninja-${{ matrix.environment.name }} get pod
- name: "DEBUG"
if: always()
run: kubectl -n khaleesi-ninja-${{ matrix.environment.name }} logs --tail 100 -l site=admin -l app=frontend
# Clean up cache.
clean-cache:
runs-on: "ubuntu-latest"
needs: [ "unit-test", "e2e-test" ]
if: always()
permissions:
actions: "write"
steps:
- name: "Checkout repository"
uses: "actions/checkout@v3"
- name: "Clean up cache."
uses: "./.github/actions/clean-cache"