-
Notifications
You must be signed in to change notification settings - Fork 1
308 lines (266 loc) · 10.9 KB
/
ci-cd.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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
name: CI/CI Pipeline
on:
# Triggers the workflow on push or pull request events but only for the "main" branch
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "test_backend"
test_backend:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: true
recursive: true
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.10'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest
pip install -r tq_backend/requirements.txt
- name: Run tests
run: |
pytest
# This workflow contains a single job called "test_frontend"
test_frontend:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: true
recursive: true
- name: Install dependencies
run: |
sudo apt-get update &&
sudo apt-get install -y \
sudo \
build-essential \
cmake \
git \
wget \
python3 \
python3-pip \
mesa-common-dev \
mesa-utils \
libvulkan-dev \
libxkbcommon-x11-0 \
libxkbcommon-dev \
software-properties-common \
libxcb-xinerama0 \
libxcb-xinput0 \
libxcb-icccm4 \
libxcb-image0 \
libxcb-keysyms1 \
libxcb-randr0 \
libxcb-render-util0 \
libxcb-shape0 \
libxcb-sync1 \
libxcb-xfixes0 \
libxcb-xkb1 \
qt6-base-dev \
qt6-declarative-dev \
qt6-tools-dev \
qt6-tools-dev-tools \
qt6-wayland-dev \
qml6-module-qtqml \
qml6-module-qtqml-workerscript \
qml6-module-qtquick \
qml6-module-qtquick-window \
qml6-module-qtquick-controls \
qml6-module-qtquick-layouts \
qml6-module-qtquick-templates \
qml6-module-qt-labs-platform \
xvfb && \
sudo apt-get clean && \
sudo rm -rf /var/lib/apt/lists/*
- name: Start Xvfb
run: |
sudo Xvfb :99 -ac &
export DISPLAY=:99
- name: Build and run tests
run: |
export DISPLAY=:99
mkdir -p build
cd build
cmake ../tq_frontend/tests
make
ctest --output-on-failure
build_and_push_backend_image:
needs: test_backend
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: true
recursive: true
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Log in to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push tq-backend image
run: |
docker build -t ${{ secrets.DOCKER_USERNAME }}/tq-backend:latest-$GITHUB_SHA -f tq_backend/Dockerfile ./tq_backend
docker push ${{ secrets.DOCKER_USERNAME }}/tq-backend:latest-$GITHUB_SHA
docker tag ${{ secrets.DOCKER_USERNAME }}/tq-backend:latest-$GITHUB_SHA ${{ secrets.DOCKER_USERNAME }}/tq-backend:latest
docker push ${{ secrets.DOCKER_USERNAME }}/tq-backend:latest
# This workflow contains a single job called "build_and_push_frontend_web_image"
build_and_push_frontend_web_image:
needs: test_frontend
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: true
recursive: true
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Log in to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push tq-frontend-web-light image
run: |
docker build -t ${{ secrets.DOCKER_USERNAME }}/tq-frontend-web-light:latest-$GITHUB_SHA -f tq_frontend/qtwebDockerfile ./tq_frontend
docker push ${{ secrets.DOCKER_USERNAME }}/tq-frontend-web-light:latest-$GITHUB_SHA
docker tag ${{ secrets.DOCKER_USERNAME }}/tq-frontend-web-light:latest-$GITHUB_SHA ${{ secrets.DOCKER_USERNAME }}/tq-frontend-web-light:latest
docker push ${{ secrets.DOCKER_USERNAME }}/tq-frontend-web-light:latest
# This workflow contains a single job called "build_and_push_frontend_desktop_image"
build_and_push_frontend_desktop_image:
needs: test_frontend
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: true
recursive: true
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Log in to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push tq-frontend-desktop image
run: |
docker build -t ${{ secrets.DOCKER_USERNAME }}/tq-frontend-desktop:latest-$GITHUB_SHA -f tq_frontend/qtdeskDockerfile ./tq_frontend
docker push ${{ secrets.DOCKER_USERNAME }}/tq-frontend-desktop:latest-$GITHUB_SHA
docker tag ${{ secrets.DOCKER_USERNAME }}/tq-frontend-desktop:latest-$GITHUB_SHA ${{ secrets.DOCKER_USERNAME }}/tq-frontend-desktop:latest
docker push ${{ secrets.DOCKER_USERNAME }}/tq-frontend-desktop:latest
# This workflow contains a single job called "build_and_push_reverse_proxy_image"
build_and_push_reverse_proxy_image:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: true
recursive: true
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Log in to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push tq-reverse-proxy image
run: |
docker build -t ${{ secrets.DOCKER_USERNAME }}/tq-reverse-proxy:latest-$GITHUB_SHA -f reverse-proxy/Dockerfile ./reverse-proxy
docker push ${{ secrets.DOCKER_USERNAME }}/tq-reverse-proxy:latest-$GITHUB_SHA
docker tag ${{ secrets.DOCKER_USERNAME }}/tq-reverse-proxy:latest-$GITHUB_SHA ${{ secrets.DOCKER_USERNAME }}/tq-reverse-proxy:latest
docker push ${{ secrets.DOCKER_USERNAME }}/tq-reverse-proxy:latest
deploy:
needs: [build_and_push_backend_image, build_and_push_frontend_web_image, build_and_push_reverse_proxy_image]
runs-on: ubuntu-latest
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: true
recursive: true
# Configure Workload Identity Federation and generate an access token.
#
# See https://github.com/google-github-actions/auth for more options,
# including authenticating via a JSON credentials file.
- id: 'auth'
name: 'Authenticate to Google Cloud'
uses: google-github-actions/auth@v2
with:
credentials_json: '${{ secrets.GCP_SA_KEY }}'
# Get the GKE credentials so we can deploy to the cluster
- name: 'Set up GKE credentials'
uses: google-github-actions/get-gke-credentials@v2
with:
cluster_name: '${{ secrets.GKE_CLUSTER_NAME }}'
location: '${{ secrets.GKE_CLUSTER_ZONE }}'
# verify the connection to the cluster BEFORE DEPLOYMENT
- name: 'Verify cluster services BEFORE DEPLOYMENT'
run: |
kubectl get services
kubectl get deployments
kubectl get pods
# Download and set up Kompose
- name: 'Download and set up Kompose'
run: |-
curl -L https://github.com/kubernetes/kompose/releases/latest/download/kompose-linux-amd64 -o kompose
chmod +x kompose
# Convert the Docker Compose file to Kubernetes manifests and apply them
- name: 'Convert Docker Compose to Kubernetes and apply'
run: |-
./kompose convert -f docker-compose-web.yml
kubectl apply -f tq-backend-service.yaml
kubectl apply -f tq-frontend-web-tcp-service.yaml
kubectl apply -f tq-reverse-proxy-tcp-service.yaml
kubectl apply -f tq-backend-deployment.yaml
kubectl apply -f tq-frontend-web-deployment.yaml
kubectl apply -f tq-reverse-proxy-deployment.yaml
# Update the image in the Kubernetes deployment
- name: 'Update image in Kubernetes deployment'
run: |-
kubectl set image deployment/tq-backend tq-backend=${{ secrets.DOCKER_USERNAME }}/tq-backend:latest-$GITHUB_SHA
kubectl set image deployment/tq-frontend-web tq-frontend-web=${{ secrets.DOCKER_USERNAME }}/tq-frontend-web-light:latest-$GITHUB_SHA
kubectl set image deployment/tq-reverse-proxy tq-reverse-proxy=${{ secrets.DOCKER_USERNAME }}/tq-reverse-proxy:latest-$GITHUB_SHA
# Check the rollout status of the deployments
- name: 'Check rollout status for tq-backend'
run: |
kubectl rollout status deployment/tq-backend
# Check the rollout status of the deployments
- name: 'Check rollout status for tq-frontend-web'
run: |
kubectl rollout status deployment/tq-frontend-web
# Check the rollout status of the deployments
- name: 'Check rollout status for tq-reverse-proxy'
run: |
kubectl rollout status deployment/tq-reverse-proxy
# verify the connection to the cluster AFTER DEPLOYMENT
- name: 'Verify cluster services AFTER DEPLOYMENT'
run: |
kubectl get services
kubectl get deployments
kubectl get pods