-
Notifications
You must be signed in to change notification settings - Fork 22
1509 lines (1284 loc) · 61.5 KB
/
deploy-apis-to-production.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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
name: deploy-apis-to-production
on:
pull_request:
branches:
- master
types:
- closed
env:
REGISTRY_URL: eu.gcr.io
PROJECT_ID: airqo-250220
DEPLOY_BRANCH: staging
jobs:
image-tag:
if: github.event.pull_request.merged == true
name: create image tag
runs-on: ubuntu-latest
outputs:
build_id: ${{ steps.prep.outputs.build_id }} # build id
datetime: ${{ steps.prep.outputs.datetime }} # build date
steps:
- name: generate build ID
id: prep
run: |
sha=${GITHUB_SHA::8}
timestamp=$(date +%s)
datetime=$(date)
echo "build_id=prod-${sha}-${timestamp}" >>$GITHUB_OUTPUT
echo "datetime=${datetime}" >>$GITHUB_OUTPUT
check:
if: github.event.pull_request.merged == true
name: check changed microservice(s)
outputs:
run_auth_service: ${{ steps.check_files.outputs.run_auth_service }} # auth service
run_device_registry: ${{ steps.check_files.outputs.run_device_registry }} # device registry
run_device_monitoring: ${{ steps.check_files.outputs.run_device_monitoring }} # device monitoring
run_data_mgt: ${{ steps.check_files.outputs.run_data_mgt }} # data mgt
run_analytics: ${{ steps.check_files.outputs.run_analytics }} # analytics
run_device_uptime: ${{ steps.check_files.outputs.run_device_uptime }} # device uptime
run_device_status: ${{ steps.check_files.outputs.run_device_status }} # device status
run_locate: ${{ steps.check_files.outputs.run_locate }} # locate
run_predict: ${{ steps.check_files.outputs.run_predict }} # predict
run_gp_model: ${{ steps.check_files.outputs.run_gp_model }} # gp_model
run_exceedances: ${{ steps.check_files.outputs.run_exceedances }} # exceedances
run_meta_data: ${{ steps.check_files.outputs.run_meta_data }} # meta data
run_view: ${{ steps.check_files.outputs.run_view }} # view
run_calibrate: ${{ steps.check_files.outputs.run_calibrate }} # calibrate
run_kafka_cluster_operator: ${{ steps.check_files.outputs.run_kafka_cluster_operator }} # kafka cluster operator
run_kafka_cluster: ${{ steps.check_files.outputs.run_kafka_cluster }} # kafka cluster
run_kafka_topics: ${{ steps.check_files.outputs.run_kafka_topics }} # kafka topics
run_airflow: ${{ steps.check_files.outputs.run_airflow }} # airflow
run_incentives: ${{ steps.check_files.outputs.run_incentives }} # incentives
run_kafka_connectors: ${{ steps.check_files.outputs.run_kafka_connectors }} # kafka connectors
run_nginx: ${{ steps.check_files.outputs.run_nginx }} # nginx
runs-on: ubuntu-latest
steps:
- name: checkout code
uses: actions/[email protected]
with:
fetch-depth: 2
#### all microservices ######
- name: check modified microserivce
id: check_files
run: |
echo "=============== list modified files ==============="
git diff --name-only HEAD^ HEAD
echo "========== check paths of modified files =========="
git diff --name-only HEAD^ HEAD > files.txt
echo "run_auth_service=false" >>$GITHUB_OUTPUT
echo "run_device_registry=false" >>$GITHUB_OUTPUT
echo "run_device_monitoring=false" >>$GITHUB_OUTPUT
echo "run_data_mgt=false" >>$GITHUB_OUTPUT
echo "run_analytics=false" >>$GITHUB_OUTPUT
echo "run_device_uptime=false" >>$GITHUB_OUTPUT
echo "run_device_status=false" >>$GITHUB_OUTPUT
echo "run_locate=false" >>$GITHUB_OUTPUT
echo "run_predict=false" >>$GITHUB_OUTPUT
echo "run_gp_model=false" >>$GITHUB_OUTPUT
echo "run_exceedances=false" >>$GITHUB_OUTPUT
echo "run_meta_data=false" >>$GITHUB_OUTPUT
echo "run_view=false" >>$GITHUB_OUTPUT
echo "run_calibrate=false" >>$GITHUB_OUTPUT
echo "run_kafka_cluster_operator=false" >>$GITHUB_OUTPUT
echo "run_kafka_cluster=false" >>$GITHUB_OUTPUT
echo "run_kafka_topics=false" >>$GITHUB_OUTPUT
echo "run_airflow=false" >>$GITHUB_OUTPUT
echo "run_incentives=false" >>$GITHUB_OUTPUT
echo "run_kafka_connectors=false" >>$GITHUB_OUTPUT
echo "run_nginx=false" >>$GITHUB_OUTPUT
while IFS= read -r file
do
echo $file
if [[ $file == src/auth-service/* ]]; then
echo "run_auth_service=true" >>$GITHUB_OUTPUT
fi
if [[ $file == k8s/auth-service/* ]]; then
echo "run_auth_service=true" >>$GITHUB_OUTPUT
fi
if [[ $file == src/device-registry/* ]]; then
echo "run_device_registry=true" >>$GITHUB_OUTPUT
fi
if [[ $file == k8s/device-registry/* ]]; then
echo "run_device_registry=true" >>$GITHUB_OUTPUT
fi
if [[ $file == src/device-monitoring/* ]]; then
echo "run_device_monitoring=true" >>$GITHUB_OUTPUT
fi
if [[ $file == k8s/device-monitor/* ]]; then
echo "run_device_monitoring=true" >>$GITHUB_OUTPUT
fi
if [[ $file == src/data-mgt/node/* ]]; then
echo "run_data_mgt=true" >>$GITHUB_OUTPUT
fi
if [[ $file == k8s/data-mgt/* ]]; then
echo "run_data_mgt=true" >>$GITHUB_OUTPUT
fi
if [[ $file == src/analytics/* ]]; then
echo "run_analytics=true" >>$GITHUB_OUTPUT
fi
if [[ $file == k8s/analytics/* ]]; then
echo "run_analytics=true" >>$GITHUB_OUTPUT
fi
if [[ $file == src/device-uptime/* ]]; then
echo "run_device_uptime=true" >>$GITHUB_OUTPUT
fi
if [[ $file == k8s/device-uptime/* ]]; then
echo "run_device_uptime=true" >>$GITHUB_OUTPUT
fi
if [[ $file == src/device-status/* ]]; then
echo "run_device_status=true" >>$GITHUB_OUTPUT
fi
if [[ $file == k8s/device-status/* ]]; then
echo "run_device_status=true" >>$GITHUB_OUTPUT
fi
if [[ $file == src/locate/* ]]; then
echo "run_locate=true" >>$GITHUB_OUTPUT
fi
if [[ $file == k8s/locate/* ]]; then
echo "run_locate=true" >>$GITHUB_OUTPUT
fi
if [[ $file == src/predict/* ]]; then
echo "run_predict=true" >>$GITHUB_OUTPUT
fi
if [[ $file == k8s/predict/* ]]; then
echo "run_predict=true" >>$GITHUB_OUTPUT
fi
if [[ $file == src/gp-model/* ]]; then
echo "run_gp_model=true" >>$GITHUB_OUTPUT
fi
if [[ $file == k8s/gp-model/* ]]; then
echo "run_gp_model=true" >>$GITHUB_OUTPUT
fi
if [[ $file == src/exceedances/* ]]; then
echo "run_exceedances=true" >>$GITHUB_OUTPUT
fi
if [[ $file == k8s/exceedance/* ]]; then
echo "run_exceedances=true" >>$GITHUB_OUTPUT
fi
if [[ $file == src/meta-data/* ]]; then
echo "run_meta_data=true" >>$GITHUB_OUTPUT
fi
if [[ $file == k8s/meta-data/* ]]; then
echo "run_meta_data=true" >>$GITHUB_OUTPUT
fi
if [[ $file == src/view/* ]]; then
echo "run_view=true" >>$GITHUB_OUTPUT
fi
if [[ $file == k8s/view/* ]]; then
echo "run_view=true" >>$GITHUB_OUTPUT
fi
if [[ $file == src/calibrate/* ]]; then
echo "run_calibrate=true" >>$GITHUB_OUTPUT
fi
if [[ $file == k8s/calibrate/* ]]; then
echo "run_calibrate=true" >>$GITHUB_OUTPUT
fi
if [[ $file == k8s/kafka/clusters/* ]]; then
echo "run_kafka_cluster=true" >>$GITHUB_OUTPUT
fi
if [[ $file == k8s/kafka/operator/* ]]; then
echo "run_kafka_cluster_operator=true" >>$GITHUB_OUTPUT
fi
if [[ $file == k8s/kafka/topics/* ]]; then
echo "run_kafka_topics=true" >>$GITHUB_OUTPUT
fi
if [[ $file == src/kafka-connectors/* ]]; then
echo "run_kafka_connectors=true" >>$GITHUB_OUTPUT
fi
if [[ $file == src/airflow/* ]]; then
echo "run_airflow=true" >>$GITHUB_OUTPUT
fi
if [[ $file == k8s/airflow/* ]]; then
echo "run_airflow=true" >>$GITHUB_OUTPUT
fi
if [[ $file == src/incentives/* ]]; then
echo "run_incentives=true" >>$GITHUB_OUTPUT
fi
if [[ $file == k8s/incentives/* ]]; then
echo "run_incentives=true" >>$GITHUB_OUTPUT
fi
if [[ $file == k8s/nginx/production/* ]]; then
echo "run_nginx=true" >>$GITHUB_OUTPUT
fi
if [[ $file == workflow-trigger ]]; then
echo "run_calibrate=true" >>$GITHUB_OUTPUT
echo "run_meta_data=true" >>$GITHUB_OUTPUT
echo "run_exceedances=true" >>$GITHUB_OUTPUT
echo "run_gp_model=true" >>$GITHUB_OUTPUT
echo "run_predict=true" >>$GITHUB_OUTPUT
echo "run_locate=true" >>$GITHUB_OUTPUT
echo "run_device_status=true" >>$GITHUB_OUTPUT
echo "run_device_uptime=true" >>$GITHUB_OUTPUT
echo "run_analytics=true" >>$GITHUB_OUTPUT
echo "run_data_mgt=true" >>$GITHUB_OUTPUT
echo "run_device_monitoring=true" >>$GITHUB_OUTPUT
echo "run_device_registry=true" >>$GITHUB_OUTPUT
echo "run_auth_service=true" >>$GITHUB_OUTPUT
echo "run_airflow=true" >>$GITHUB_OUTPUT
echo "run_incentives=true" >>$GITHUB_OUTPUT
echo "run_view=true" >>$GITHUB_OUTPUT
echo "run_kafka_connectors=true" >>$GITHUB_OUTPUT
echo "run_nginx=true" >>$GITHUB_OUTPUT
fi
done < files.txt
#### Kafka Connectors ######
kafka-connectors:
name: build-push-deploy-kafka-connectors
needs: [check, image-tag]
if: needs.check.outputs.run_kafka_connectors == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/[email protected]
- name: Set up QEMU
uses: docker/[email protected]
- name: Set up Docker Buildx
uses: docker/[email protected]
- name: Login to GCR
uses: docker/[email protected]
with:
registry: ${{ env.REGISTRY_URL }}
username: _json_key
password: ${{ secrets.GCR_CONFIG }}
- name: Build and push measurements source connectors
uses: docker/[email protected]
with:
push: true
context: src/kafka-connectors/measurements-source-connector
tags: ${{ env.REGISTRY_URL }}/${{ env.PROJECT_ID }}/measurements-connect:${{ needs.image-tag.outputs.build_id }},${{ env.REGISTRY_URL }}/${{ env.PROJECT_ID }}/measurements-connect:latest
- name: Build and push biq query connector
uses: docker/[email protected]
with:
push: true
context: src/kafka-connectors/bigquery-connector
tags: ${{ env.REGISTRY_URL }}/${{ env.PROJECT_ID }}/bigquery-connector:${{ needs.image-tag.outputs.build_id }},${{ env.REGISTRY_URL }}/${{ env.PROJECT_ID }}/bigquery-connector:latest
- name: Login to k8s cluster
uses: azure/[email protected]
with:
method: kubeconfig
kubeconfig: ${{ secrets.K8S_CONFIG_PROD }}
- name: Update corresponding helm values file(with retry)
uses: Wandalen/[email protected] # Retries action on fail
with:
action: fjogeleit/yaml-update-action@main # Action to retry
with: |
valueFile: "k8s/kafka/BigQuery-connectors/values-prod.yaml"
propertyPath: "image.tag"
value: ${{ needs.image-tag.outputs.build_id }}
branch: ${{ env.DEPLOY_BRANCH }}
token: ${{ secrets.YAML_UPDATER_TOKEN }}
message: "Update BigQuery-connectors production image tag to ${{ needs.image-tag.outputs.build_id }}"
- name: Deploy to k8s cluster
run: |
export MEASUREMENTS_CONNECT_IMAGE=${{ env.REGISTRY_URL }}/${{ env.PROJECT_ID }}/measurements-connect:${{ needs.image-tag.outputs.build_id }}
export PROD_KAFKA_CLUSTER=${{ secrets.PROD_KAFKA_CLUSTER }}
cat k8s/kafka/connectors/measurements-connect.yaml | sed "s/{{MEASUREMENTS_CONNECT_IMAGE}}/$MEASUREMENTS_CONNECT_IMAGE/g" | sed "s/{{KAFKA_CLUSTER}}/$PROD_KAFKA_CLUSTER/g" | kubectl apply -n message-broker -f-
kubectl apply -f k8s/kafka/connectors/purple-air-connector.yaml -n message-broker
- name: Set up GCP credentials and Kubernetes configmaps
run : |
gcloud secrets versions access latest --secret="prod-env-kafka-bigquery-connectors" > .env
kubectl create configmap --dry-run=client -o yaml --from-env-file=.env bigquery-connectors | kubectl replace -f - -n production
gcloud secrets versions access latest --secret="prod-key-kafka-bigquery-connectors" > google_application_credentials.json
kubectl create configmap --dry-run=client -o yaml --from-file=google_application_credentials.json bigquery-connectors-files | kubectl replace -f - -n production
### auth service ###
auth-service:
name: build-push-deploy-auth
needs: [check, image-tag]
if: needs.check.outputs.run_auth_service == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/[email protected]
- name: Login to GCR
uses: docker/[email protected]
with:
registry: ${{ env.REGISTRY_URL }}
username: _json_key
password: ${{ secrets.GCR_CONFIG }}
- name: Login to K8S
uses: azure/[email protected]
with:
method: kubeconfig
kubeconfig: ${{ secrets.K8S_CONFIG_PROD }}
- name: Build and Push Docker Image
run: |
cd src/auth-service/
docker build --target=production --tag ${{ env.REGISTRY_URL }}/${{ env.PROJECT_ID }}/airqo-auth-api:${{ needs.image-tag.outputs.build_id }} .
docker tag ${{ env.REGISTRY_URL }}/${{ env.PROJECT_ID }}/airqo-auth-api:${{ needs.image-tag.outputs.build_id }} ${{ env.REGISTRY_URL }}/${{ env.PROJECT_ID }}/airqo-auth-api:latest
docker push ${{ env.REGISTRY_URL }}/${{ env.PROJECT_ID }}/airqo-auth-api:${{ needs.image-tag.outputs.build_id }}
docker push ${{ env.REGISTRY_URL }}/${{ env.PROJECT_ID }}/airqo-auth-api:latest
- name: Update corresponding helm values file(with retry)
uses: Wandalen/[email protected] # Retries action on fail
with:
action: fjogeleit/yaml-update-action@main # Action to retry
with: |
valueFile: "k8s/auth-service/values-prod.yaml"
propertyPath: "image.tag"
value: ${{ needs.image-tag.outputs.build_id }}
branch: ${{ env.DEPLOY_BRANCH }}
token: ${{ secrets.YAML_UPDATER_TOKEN }}
message: "Update auth service production image tag to ${{ needs.image-tag.outputs.build_id }}"
- name: Login to GCP
uses: google-github-actions/[email protected]
with:
credentials_json: ${{ secrets.GCP_SA_CREDENTIALS }}
- name: Setup Cloud SDK
uses: google-github-actions/[email protected]
- name: Update the corresponding k8s configmap(s)
run: |
cd src/auth-service/
gcloud secrets versions access latest --secret="prod-env-auth-service" > .env
kubectl create configmap --dry-run=client -o yaml --from-env-file=.env prod-auth-api-config | kubectl replace -f - -n production
gcloud secrets versions access latest --secret="prod-key-auth-service-firebase-admin-sdk" > firebase_admin_sdk.json
kubectl create configmap --dry-run=client -o yaml --from-file=firebase_admin_sdk.json prod-auth-api-config-files | kubectl replace -f - -n production
### airflow ###
airflow:
name: build-push-deploy-airflow
needs: [check, image-tag]
if: needs.check.outputs.run_airflow == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/[email protected]
- name: Set up QEMU
uses: docker/[email protected]
- name: Set up Docker Buildx
uses: docker/[email protected]
- name: Login to GCR
uses: docker/[email protected]
with:
registry: ${{ env.REGISTRY_URL }}
username: _json_key
password: ${{ secrets.GCR_CONFIG }}
- name: Build and push app
uses: docker/[email protected]
with:
push: true
context: src/airflow
target: deployment
tags: ${{ env.REGISTRY_URL }}/${{ env.PROJECT_ID }}/airqo-apache-airflow:${{ needs.image-tag.outputs.build_id }},${{ env.REGISTRY_URL }}/${{ env.PROJECT_ID }}/airqo-apache-airflow:latest
- name: Build and push XCom
uses: docker/[email protected]
with:
push: true
context: src/airflow
target: xcom-setup
tags: ${{ env.REGISTRY_URL }}/${{ env.PROJECT_ID }}/airqo-apache-airflow-xcom:${{ needs.image-tag.outputs.build_id }},${{ env.REGISTRY_URL }}/${{ env.PROJECT_ID }}/airqo-apache-airflow-xcom:latest
- name: Update corresponding helm values file(with retry)
uses: Wandalen/[email protected] # Retries action on fail
with:
action: fjogeleit/yaml-update-action@main # Action to retry
with: |
valueFile: "k8s/airflow/values-prod.yaml"
propertyPath: "images.tag"
value: ${{ needs.image-tag.outputs.build_id }}
branch: ${{ env.DEPLOY_BRANCH }}
token: ${{ secrets.YAML_UPDATER_TOKEN }}
message: "Update airflow prod image tag to ${{ needs.image-tag.outputs.build_id }}"
- name: Login to GCP
uses: google-github-actions/[email protected]
with:
credentials_json: ${{ secrets.GCP_SA_CREDENTIALS }}
- name: Setup Cloud SDK
uses: google-github-actions/[email protected]
- name: Login to K8S
uses: azure/[email protected]
with:
method: kubeconfig
kubeconfig: ${{ secrets.K8S_CONFIG_PROD }}
- name: Update the corresponding k8s configmap(s)
run: |
cd src/airflow/
gcloud secrets versions access latest --secret="prod-env-airflow" > .env
kubectl create configmap --dry-run=client -o yaml --from-env-file=.env airflow-config | kubectl replace -f - -n pipeline
#### Device Registry ######
device-registry:
name: build-push-deploy-device-registry
needs: [check, image-tag]
if: needs.check.outputs.run_device_registry == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/[email protected]
- name: Login to GCR
uses: docker/[email protected]
with:
registry: ${{ env.REGISTRY_URL }}
username: _json_key
password: ${{ secrets.GCR_CONFIG }}
- name: Login to K8S
uses: azure/[email protected]
with:
method: kubeconfig
kubeconfig: ${{ secrets.K8S_CONFIG_PROD }}
- name: Build and Push Docker Image
run: |
cd src/device-registry/
docker build --target=production --tag ${{ env.REGISTRY_URL }}/${{ env.PROJECT_ID }}/airqo-device-registry-api:${{ needs.image-tag.outputs.build_id }} .
docker tag ${{ env.REGISTRY_URL }}/${{ env.PROJECT_ID }}/airqo-device-registry-api:${{ needs.image-tag.outputs.build_id }} ${{ env.REGISTRY_URL }}/${{ env.PROJECT_ID }}/airqo-device-registry-api:latest
docker push ${{ env.REGISTRY_URL }}/${{ env.PROJECT_ID }}/airqo-device-registry-api:${{ needs.image-tag.outputs.build_id }}
docker push ${{ env.REGISTRY_URL }}/${{ env.PROJECT_ID }}/airqo-device-registry-api:latest
- name: Update corresponding helm values file
uses: Wandalen/[email protected]
with:
action: fjogeleit/yaml-update-action@main
with: |
valueFile: "k8s/device-registry/values-prod.yaml"
propertyPath: "image.tag"
value: ${{ needs.image-tag.outputs.build_id }}
branch: ${{ env.DEPLOY_BRANCH }}
token: ${{ secrets.YAML_UPDATER_TOKEN }}
message: "Update device registry production image tag to ${{ needs.image-tag.outputs.build_id }}"
- name: Login to GCP
uses: google-github-actions/[email protected]
with:
credentials_json: ${{ secrets.GCP_SA_CREDENTIALS }}
- name: Setup Cloud SDK
uses: google-github-actions/[email protected]
- name: Update the corresponding k8s configmap(s)
run: |
cd src/device-registry/
gcloud secrets versions access latest --secret="prod-env-device-registry" > .env
kubectl create configmap --dry-run=client -o yaml --from-env-file=.env env-device-registry-production | kubectl replace -f - -n production
gcloud secrets versions access latest --secret="prod-key-device-registry-service-account" > google_application_credentials.json
kubectl create configmap --dry-run=client -o yaml --from-file=google_application_credentials.json device-registry-config-files | kubectl replace -f - -n production
### device monitoring ###
device-monitoring:
name: build-push-deploy-device-monitoring
needs: [check, image-tag]
if: needs.check.outputs.run_device_monitoring == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/[email protected]
- name: Login to GCR
uses: docker/[email protected]
with:
registry: ${{ env.REGISTRY_URL }}
username: _json_key
password: ${{ secrets.GCR_CONFIG }}
- name: Login to K8S
uses: azure/[email protected]
with:
method: kubeconfig
kubeconfig: ${{ secrets.K8S_CONFIG_PROD }}
- name: Build and push API
uses: docker/[email protected]
with:
push: true
context: src/device-monitoring/
target: production
tags: ${{ env.REGISTRY_URL }}/${{ env.PROJECT_ID }}/airqo-device-monitor-api:${{ needs.image-tag.outputs.build_id }},${{ env.REGISTRY_URL }}/${{ env.PROJECT_ID }}/airqo-device-monitor-api:latest
- name: Build and push celery-beat
uses: docker/[email protected]
with:
push: true
context: src/device-monitoring/
target: celery-beat
tags: ${{ env.REGISTRY_URL }}/${{ env.PROJECT_ID }}/airqo-device-monitor-celery-beat:${{ needs.image-tag.outputs.build_id }},${{ env.REGISTRY_URL }}/${{ env.PROJECT_ID }}/airqo-device-monitor-celery-beat:latest
- name: Build and push celery-worker
uses: docker/[email protected]
with:
push: true
context: src/device-monitoring/
target: celery-worker
tags: ${{ env.REGISTRY_URL }}/${{ env.PROJECT_ID }}/airqo-device-monitor-celery-worker:${{ needs.image-tag.outputs.build_id }},${{ env.REGISTRY_URL }}/${{ env.PROJECT_ID }}/airqo-device-monitor-celery-worker:latest
- name: Update corresponding helm values file(with retry)
uses: Wandalen/[email protected] # Retries action on fail
with:
action: fjogeleit/yaml-update-action@main # Action to retry
with: |
valueFile: "k8s/device-monitor/values-prod.yaml"
propertyPath: "images.tag"
value: ${{ needs.image-tag.outputs.build_id }}
branch: ${{ env.DEPLOY_BRANCH }}
token: ${{ secrets.YAML_UPDATER_TOKEN }}
message: "Update device monitor production images' tag to ${{ needs.image-tag.outputs.build_id }}"
- name: Login to GCP
uses: google-github-actions/[email protected]
with:
credentials_json: ${{ secrets.GCP_SA_CREDENTIALS }}
- name: Setup Cloud SDK
uses: google-github-actions/[email protected]
- name: Update the corresponding k8s configmap(s)
run: |
cd src/device-monitoring/
gcloud secrets versions access latest --secret="prod-env-device-monitoring" > .env
kubectl create configmap --dry-run=client -o yaml --from-env-file=.env env-device-monitoring-production | kubectl replace -f - -n production
gcloud secrets versions access latest --secret="prod-key-device-monitoring-service-account" > google_application_credentials.json
kubectl create configmap --dry-run=client -o yaml --from-file=google_application_credentials.json device-monitor-config-files | kubectl replace -f - -n production
### data-mgt ###
data-mgt:
name: build-push-deploy-data-mgt
needs: [check, image-tag]
if: needs.check.outputs.run_data_mgt == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/[email protected]
- name: Login to GCR
uses: docker/[email protected]
with:
registry: ${{ env.REGISTRY_URL }}
username: _json_key
password: ${{ secrets.GCR_CONFIG }}
- name: Login to K8S
uses: azure/[email protected]
with:
method: kubeconfig
kubeconfig: ${{ secrets.K8S_CONFIG_PROD }}
- name: Build and Push Docker Image
run: |
cd src/data-mgt/node/
docker build --target=production --tag ${{ env.REGISTRY_URL }}/${{ env.PROJECT_ID }}/airqo-data-mgt-api:${{ needs.image-tag.outputs.build_id }} .
docker push ${{ env.REGISTRY_URL }}/${{ env.PROJECT_ID }}/airqo-data-mgt-api:${{ needs.image-tag.outputs.build_id }}
docker tag ${{ env.REGISTRY_URL }}/${{ env.PROJECT_ID }}/airqo-data-mgt-api:${{ needs.image-tag.outputs.build_id }} ${{ env.REGISTRY_URL }}/${{ env.PROJECT_ID }}/airqo-data-mgt-api:latest
docker push ${{ env.REGISTRY_URL }}/${{ env.PROJECT_ID }}/airqo-data-mgt-api:latest
- name: Update corresponding helm values file(with retry)
uses: Wandalen/[email protected] # Retries action on fail
with:
action: fjogeleit/yaml-update-action@main # Action to retry
with: |
valueFile: "k8s/data-mgt/values-prod.yaml"
propertyPath: "image.tag"
value: ${{ needs.image-tag.outputs.build_id }}
branch: ${{ env.DEPLOY_BRANCH }}
token: ${{ secrets.YAML_UPDATER_TOKEN }}
message: "Update data mgt production image tag to ${{ needs.image-tag.outputs.build_id }}"
- name: Login to GCP
uses: google-github-actions/[email protected]
with:
credentials_json: ${{ secrets.GCP_SA_CREDENTIALS }}
- name: Setup Cloud SDK
uses: google-github-actions/[email protected]
- name: Update the corresponding k8s configmap(s)
run: |
cd src/data-mgt/node/
gcloud secrets versions access latest --secret="prod-env-data-mgt-nodejs" > .env
kubectl create configmap --dry-run=client -o yaml --from-env-file=.env data-mgt-api-config | kubectl replace -f - -n production
### analytics ###
analytics:
name: build-push-deploy-analytics
needs: [check, image-tag]
if: needs.check.outputs.run_analytics == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/[email protected]
### run unit tests ###
- name: Login to GCR
uses: docker/[email protected]
with:
registry: ${{ env.REGISTRY_URL }}
username: _json_key
password: ${{ secrets.GCR_CONFIG }}
- name: Login to K8S
uses: azure/[email protected]
with:
method: kubeconfig
kubeconfig: ${{ secrets.K8S_CONFIG_PROD }}
- name: Build and push API Docker Image
uses: docker/[email protected]
with:
push: true
context: src/analytics/
target: production
tags: ${{ env.REGISTRY_URL }}/${{ env.PROJECT_ID }}/airqo-analytics-api:${{ needs.image-tag.outputs.build_id }},${{ env.REGISTRY_URL }}/${{ env.PROJECT_ID }}/airqo-analytics-api:latest
- name: Build and push Celery beat Docker Image
uses: docker/[email protected]
with:
push: true
context: src/analytics/
target: celery-beat
tags: ${{ env.REGISTRY_URL }}/${{ env.PROJECT_ID }}/airqo-analytics-celery-beat:${{ needs.image-tag.outputs.build_id }},${{ env.REGISTRY_URL }}/${{ env.PROJECT_ID }}/airqo-analytics-celery-beat:latest
- name: Build and push Celery worker Docker Image
uses: docker/[email protected]
with:
push: true
context: src/analytics/
target: celery-worker
tags: ${{ env.REGISTRY_URL }}/${{ env.PROJECT_ID }}/airqo-analytics-celery-worker:${{ needs.image-tag.outputs.build_id }},${{ env.REGISTRY_URL }}/${{ env.PROJECT_ID }}/airqo-analytics-celery-worker:latest
- name: Build and push device summary job Docker Image
uses: docker/[email protected]
with:
push: true
context: src/analytics/
target: devices-summary-job
tags: ${{ env.REGISTRY_URL }}/${{ env.PROJECT_ID }}/airqo-analytics-devices-summary-job:${{ needs.image-tag.outputs.build_id }},${{ env.REGISTRY_URL }}/${{ env.PROJECT_ID }}/airqo-analytics-devices-summary-job:latest
- name: Build and push reports job Docker Image
uses: docker/[email protected]
with:
push: true
context: src/analytics/jobs/reports
target: production
tags: ${{ env.REGISTRY_URL }}/${{ env.PROJECT_ID }}/airqo-analytics-report-job:${{ needs.image-tag.outputs.build_id }},${{ env.REGISTRY_URL }}/${{ env.PROJECT_ID }}/airqo-analytics-report-job:latest
- name: Update corresponding helm values file(with retry)
uses: Wandalen/[email protected] # Retries action on fail
with:
action: fjogeleit/yaml-update-action@main # Action to retry
with: |
valueFile: "k8s/analytics/values-prod.yaml"
propertyPath: "images.tag"
value: ${{ needs.image-tag.outputs.build_id }}
branch: ${{ env.DEPLOY_BRANCH }}
token: ${{ secrets.YAML_UPDATER_TOKEN }}
message: "Update analytics production image tag to ${{ needs.image-tag.outputs.build_id }}"
- name: Login to GCP
uses: google-github-actions/[email protected]
with:
credentials_json: ${{ secrets.GCP_SA_CREDENTIALS }}
- name: Setup Cloud SDK
uses: google-github-actions/[email protected]
- name: Update the corresponding k8s configmap(s)
run: |
cd src/analytics/
gcloud secrets versions access latest --secret="prod-env-analytics" > api.env
gcloud secrets versions access latest --secret="prod-env-analytics-report-job" > reports.env
gcloud secrets versions access latest --secret="prod-key-analytics-service-account" > google_application_credentials.json
kubectl create configmap --dry-run=client -o yaml --from-env-file=api.env env-analytics-production | kubectl replace -f - -n production
kubectl create configmap --dry-run=client -o yaml --from-env-file=reports.env env-analytics-report-production | kubectl replace -f - -n production
kubectl create configmap --dry-run=client -o yaml --from-file=google_application_credentials.json prod-analytics-config-files | kubectl replace -f - -n production
### device uptime ###
device-uptime:
name: build-push-deploy-device-uptime
needs: [check, image-tag]
if: needs.check.outputs.run_device_uptime == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/[email protected]
### run unit tests ###
- name: Login to GCR
uses: docker/[email protected]
with:
registry: ${{ env.REGISTRY_URL }}
username: _json_key
password: ${{ secrets.GCR_CONFIG }}
- name: Login to K8S
uses: azure/[email protected]
with:
method: kubeconfig
kubeconfig: ${{ secrets.K8S_CONFIG_PROD }}
- name: Build and push device uptime v1 docker image
uses: docker/[email protected]
with:
push: true
context: src/device-uptime/
target: production
tags: ${{ env.REGISTRY_URL }}/${{ env.PROJECT_ID }}/airqo-device-uptime-job:${{ needs.image-tag.outputs.build_id }},${{ env.REGISTRY_URL }}/${{ env.PROJECT_ID }}/airqo-device-uptime-job:latest
- name: Build and push device uptime v2 docker image
uses: docker/[email protected]
with:
push: true
context: src/device-uptime/
target: uptime
tags: ${{ env.REGISTRY_URL }}/${{ env.PROJECT_ID }}/airqo-device-uptime-job-v2:${{ needs.image-tag.outputs.build_id }},${{ env.REGISTRY_URL }}/${{ env.PROJECT_ID }}/airqo-device-uptime-job-v2:latest
- name: Update corresponding helm values file(with retry)
uses: Wandalen/[email protected] # Retries action on fail
with:
action: fjogeleit/yaml-update-action@main # Action to retry
with: |
valueFile: "k8s/device-uptime/values-prod.yaml"
propertyPath: "image.tag"
value: ${{ needs.image-tag.outputs.build_id }}
branch: ${{ env.DEPLOY_BRANCH }}
token: ${{ secrets.YAML_UPDATER_TOKEN }}
message: "Update device uptime production image tag to ${{ needs.image-tag.outputs.build_id }}"
- name: Login to GCP
uses: google-github-actions/[email protected]
with:
credentials_json: ${{ secrets.GCP_SA_CREDENTIALS }}
- name: Setup Cloud SDK
uses: google-github-actions/[email protected]
- name: Update the corresponding k8s configmap(s)
run: |
cd src/device-uptime/
gcloud secrets versions access latest --secret="prod-env-device-uptime" > .env
kubectl create configmap --dry-run=client -o yaml --from-env-file=.env env-device-uptime-production | kubectl replace -f - -n production
gcloud secrets versions access latest --secret="prod-key-device-uptime-v2-service-account" > google_application_credentials.json
kubectl create configmap --dry-run=client -o yaml --from-file=google_application_credentials.json device-uptime-v2-files | kubectl replace -f - -n production
### device status ###
device-status:
name: build-push-deploy-device-status
needs: [check, image-tag]
if: needs.check.outputs.run_device_status == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/[email protected]
### run unit tests ###
- name: Login to GCR
uses: docker/[email protected]
with:
registry: ${{ env.REGISTRY_URL }}
username: _json_key
password: ${{ secrets.GCR_CONFIG }}
- name: Login to K8S
uses: azure/[email protected]
with:
method: kubeconfig
kubeconfig: ${{ secrets.K8S_CONFIG_PROD }}
- name: Build and Push Docker Image
run: |
cd src/device-status/
docker build --tag ${{ env.REGISTRY_URL }}/${{ env.PROJECT_ID }}/airqo-device-status-job:${{ needs.image-tag.outputs.build_id }} -f Dockerfile .
docker push ${{ env.REGISTRY_URL }}/${{ env.PROJECT_ID }}/airqo-device-status-job:${{ needs.image-tag.outputs.build_id }}
docker tag ${{ env.REGISTRY_URL }}/${{ env.PROJECT_ID }}/airqo-device-status-job:${{ needs.image-tag.outputs.build_id }} ${{ env.REGISTRY_URL }}/${{ env.PROJECT_ID }}/airqo-device-status-job:latest
docker push ${{ env.REGISTRY_URL }}/${{ env.PROJECT_ID }}/airqo-device-status-job:latest
- name: Update corresponding helm values file(with retry)
uses: Wandalen/[email protected] # Retries action on fail
with:
action: fjogeleit/yaml-update-action@main # Action to retry
with: |
valueFile: "k8s/device-status/values-prod.yaml"
propertyPath: "image.tag"
value: ${{ needs.image-tag.outputs.build_id }}
branch: ${{ env.DEPLOY_BRANCH }}
token: ${{ secrets.YAML_UPDATER_TOKEN }}
message: "Update device status production image tag to ${{ needs.image-tag.outputs.build_id }}"
- name: Login to GCP
uses: google-github-actions/[email protected]
with:
credentials_json: ${{ secrets.GCP_SA_CREDENTIALS }}
- name: Setup Cloud SDK
uses: google-github-actions/[email protected]
- name: Update the corresponding k8s configmap(s)
run: |
cd src/device-status/
gcloud secrets versions access latest --secret="prod-env-device-status" > .env
kubectl create configmap --dry-run=client -o yaml --from-env-file=.env env-device-status-production | kubectl replace -f - -n production
### kafka cluster operator ###
kafka-cluster-operator:
name: build-push-deploy-kafka-cluster-operator
needs: [check]
if: needs.check.outputs.run_kafka_cluster_operator == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/[email protected]
- name: Login to K8S
uses: azure/[email protected]
with:
method: kubeconfig
kubeconfig: ${{ secrets.K8S_CONFIG_PROD }}
- name: Deploy to K8S
run: |
kubectl apply -f k8s/namespaces/message-broker.yaml
bash k8s/kafka/operator/deployment-script.sh
### kafka cluster ###
kafka-cluster:
name: build-push-deploy-kafka-cluster
needs: [check]
if: ${{ (needs.check.outputs.run_kafka_cluster == 'true') || (needs.check.outputs.run_kafka_cluster_operator == 'true') }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/[email protected]
- name: Login to K8S
uses: azure/[email protected]
with:
method: kubeconfig
kubeconfig: ${{ secrets.K8S_CONFIG_PROD }}
- name: Deploy to K8S
run: |
export CLUSTER_CONTROLLER_IP=${{ secrets.PROD_CLUSTER_CONTROLLER_IP}}
sed -i 's/CLUSTER_CONTROLLER_IP/'"$CLUSTER_CONTROLLER_IP"'/g' k8s/kafka/clusters/kafka-cluster.yaml
kubectl apply -n message-broker -f k8s/kafka/clusters/kafka-cluster.yaml
kubectl rollout restart deployment kafka-cluster-entity-operator -n message-broker
kubectl rollout restart deployment strimzi-cluster-operator -n message-broker
### kafka topics ###
kafka-topics:
name: build-push-deploy-kafka-topics
needs: [check]
if: ${{ (needs.check.outputs.run_kafka_cluster == 'true') || (needs.check.outputs.run_kafka_topics == 'true') }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/[email protected]
- name: Login to K8S
uses: azure/[email protected]
with:
method: kubeconfig
kubeconfig: ${{ secrets.K8S_CONFIG_PROD }}
- name: Deploy to K8S
run: |
kubectl apply -f k8s/kafka/topics/kafka-topics.yaml -n message-broker
### locate ###
locate:
name: build-push-deploy-locate
needs: [check, image-tag]
if: needs.check.outputs.run_locate == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/[email protected]
### run unit tests ###
- name: Login to GCR
uses: docker/[email protected]
with:
registry: ${{ env.REGISTRY_URL }}
username: _json_key
password: ${{ secrets.GCR_CONFIG }}
- name: Login to K8S
uses: azure/[email protected]
with:
method: kubeconfig
kubeconfig: ${{ secrets.K8S_CONFIG_PROD }}
- name: Build and Push Docker Image
run: |
cd src/locate/
docker build --target=production --tag ${{ env.REGISTRY_URL }}/${{ env.PROJECT_ID }}/airqo-locate-api:${{ needs.image-tag.outputs.build_id }} .
docker tag ${{ env.REGISTRY_URL }}/${{ env.PROJECT_ID }}/airqo-locate-api:${{ needs.image-tag.outputs.build_id }} ${{ env.REGISTRY_URL }}/${{ env.PROJECT_ID }}/airqo-locate-api:latest
docker push ${{ env.REGISTRY_URL }}/${{ env.PROJECT_ID }}/airqo-locate-api:${{ needs.image-tag.outputs.build_id }}
docker push ${{ env.REGISTRY_URL }}/${{ env.PROJECT_ID }}/airqo-locate-api:latest
- name: Update corresponding helm values file(with retry)
uses: Wandalen/[email protected] # Retries action on fail
with:
action: fjogeleit/yaml-update-action@main # Action to retry
with: |
valueFile: "k8s/locate/values-prod.yaml"
propertyPath: "image.tag"
value: ${{ needs.image-tag.outputs.build_id }}
branch: ${{ env.DEPLOY_BRANCH }}
token: ${{ secrets.YAML_UPDATER_TOKEN }}
message: "Update locate production image tag to ${{ needs.image-tag.outputs.build_id }}"
- name: Login to GCP
uses: google-github-actions/[email protected]
with:
credentials_json: ${{ secrets.GCP_SA_CREDENTIALS }}
- name: Setup Cloud SDK