-
Notifications
You must be signed in to change notification settings - Fork 2
817 lines (753 loc) · 37.2 KB
/
onCodeChanges.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
name: onCodeChanges
on:
push:
branches:
- master
paths:
- 'dockerfile_images/**'
repository_dispatch:
types: [repository_trigger,robotology_trigger, cron_trigger]
env:
REGISTRY: ghcr.io
REPOSITORY_NAME: ${{ github.repository }}
REPOSITORY_OWNER: ${{ github.repository_owner }}
DOCKERHUB_OWNER: ${{ secrets.DOCKERHUB_USERNAME }}
DEFAULT_USER: defaultuser
IMAGE_PREFIX: cd_
SUPERBUILD_TAG: v2023.08.0
jobs:
debug:
runs-on: [ubuntu-latest]
steps:
- id: get_data
run: |
echo "$(date +'%d/%m/%Y_%H:%M:%S')" > DATE_HOUR_
echo "metadata=$(cat DATE_HOUR_)" > DATE_HOUR_TAG
echo $(cat DATE_HOUR_TAG)
- id: get_version
run: |
echo "I received the version: ${{ github.event.client_payload.version }}"
check_files:
runs-on: [ubuntu-latest]
needs: debug
steps:
- id: file_changes
if: github.event_name == 'push'
uses: trilom/[email protected]
- name: files
if: github.event_name == 'push'
id: check-modifications
run: |
cat $HOME/files.json
cat $HOME/files_modified.json
cat $HOME/files_added.json
echo '${{ steps.file_changes.outputs.files}}'
echo '${{ steps.file_changes.outputs.files_modified}}'
echo '${{ steps.file_changes.outputs.files_added}}'
- uses: actions/checkout@v4
- name: find app name
id: set-matrix
run: |
if [[ "${{github.event_name}}" == "push" ]]
then
parsed_list=($(echo '${{ steps.file_changes.outputs.files}}' | tr ',' '\n'))
elif [ "${{ github.event.client_payload.type }}" == "repository_trigger" ] || [ "${{ github.event.client_payload.type }}" == "cron_trigger" ]
then
image_list="\"$(echo ${{ github.event.client_payload.img_list }} > temp.tmp && sed -i 's/ /" "/g' temp.tmp && cat temp.tmp)\""
image_list=( $image_list )
iter_parsed_list=0
for _image in "${image_list[@]}"
do
folders=( $(ls dockerfile_images/ | tr '\n' ' ' ) )
for i in "${folders[@]}"
do
subfolders=( $(ls dockerfile_images/$i/ | tr '\n' ' ' ) )
for j in "${subfolders[@]}"
do
_image2="$(echo "$_image" | awk -F'"' '{print $2}')"
if [ "$j" == "$_image2" ]
then
if [ $iter_parsed_list == 0 ]
then
parsed_list="dockerfile_images/$i/$j/"
iter_parsed_list=$((iter_parsed_list+1))
else
parsed_list="$parsed_list dockerfile_images/$i/$j/"
fi
fi
done
done
done
parsed_list=( $parsed_list )
elif [ "${{ github.event.client_payload.type }}" == "robotology_trigger" ]
then
echo "Payload from robotology: ${{ github.event.client_payload.paths }}"
path_list=($(echo "${{ github.event.client_payload.paths }}"))
iter_parsed_list=0
for each_path in "${path_list[@]}"
do
while read -r line
do
repo_folder=$(echo "$line" | awk -F' ' '{print $1}')
if [[ $each_path == $repo_folder ]]
then
demo_folder=$(echo "$line" | awk -F' ' '{print $2}')
echo "Found directory $demo_folder in conf.ini"
if [ $iter_parsed_list == 0 ]
then
parsed_list="dockerfile_images/$demo_folder/"
iter_parsed_list=$((iter_parsed_list+1))
else
parsed_list="$parsed_list dockerfile_images/$demo_folder/"
fi
fi
done < conf.ini
done
parsed_list=( $parsed_list )
fi
superbuild_matrix=""
custom_matrix=""
children_matrix=""
superbuild_flag=false
custom_flag=false
children_flag=false
children_flag_output=false
iter_superbuild=0
iter_custom=0
iter_children=0
for i in "${parsed_list[@]}"
do
folder=$(echo $i | awk -F'/' '{print $1}' | tr -d '"' | tr -d '[' | tr -d ']')
if [ "$folder" == "dockerfile_images" ]
then
element=$(echo $i | awk -F'/' '{print $3}' | tr -d '"' | tr -d '[' | tr -d ']')
image_path=dockerfile_images/$(echo $i | awk -F'/' '{print $2}' | tr -d '"' | tr -d '[' | tr -d ']')
element_flag=false
children_flag=false
children_image_flag=false
while read -r line || [ -n "$line" ]
do
if [ "$line" == "[superbuild]" ]
then
superbuild_flag=true
element_flag=true
fi
if [ "$line" == "[sources]" ] || [ "$line" == "[binaries]" ] || [ "$line" == "[tag]" ] || [ "$line" == "[superbuild]" ] || [ "$line" == "[demos]" ] || [ "$line" == "" ]
then
children_flag=false
fi
if [ $children_flag == true ]
then
if [ $iter_children == 0 ]
then
children_flag_output=true
children_matrix="$line"
iter_children=$((iter_children+1))
else
children_matrix="$children_matrix $line"
fi
fi
if [ "$line" == "[children]" ]
then
echo "children found"
children_flag=true
children_image_flag=true
fi
done < $image_path/$element/conf_build.ini
echo $children_image_flag
if [[ $element_flag == true ]]
then
if [ $iter_superbuild == 0 ]
then
superbuild_matrix="$element"
iter_superbuild=$((iter_superbuild+1))
else
superbuild_matrix="$superbuild_matrix $element"
fi
else
custom_flag=true
if [ $iter_custom == 0 ]
then
custom_matrix="$element"
iter_custom=$((iter_custom+1))
else
custom_matrix="$custom_matrix $element"
fi
fi
fi
done
children_matrix="$children_matrix"
children_matrix_list=( $children_matrix )
superbuild_matrix=( $superbuild_matrix )
new_superbuild_matrix=""
echo "this is the list without @ $superbuild_matrix"
echo "this is the list with @ ${superbuild_matrix[@]}"
for elem_1 in "${superbuild_matrix[@]}"
do
echo "this is element 1 $elem_1"
is_children=false
for elem_2 in "${children_matrix_list[@]}"
do
echo "this is element 2 $elem_2"
if [ "$elem_2" == "$elem_1" ]
then
is_children=true
echo "$elem_1 is children"
break
fi
done
if ( ! $is_children )
then
if [ "$new_superbuild_matrix" == "" ]
then
new_superbuild_matrix="\"$elem_1\""
else
new_superbuild_matrix="$new_superbuild_matrix \"$elem_1\""
fi
fi
done
echo "this is after the loop ${new_superbuild_matrix[@]}"
superbuild_matrix_temp=$(echo "${new_superbuild_matrix[@]}" | tr ' ' '\n' | sort -u | tr '\n' ',')
superbuild_final_matrix="[ $(echo "${superbuild_matrix_temp[@]}")"
superbuild_final_matrix="$(echo ${superbuild_final_matrix::-1}) ]"
custom_matrix=( $custom_matrix )
new_custom_matrix=""
for elem_1 in "${custom_matrix[@]}"
do
is_children=false
for elem_2 in "${children_matrix_list[@]}"
do
if [ "$elem_2" == "$elem_1" ]
then
is_children=true
break
fi
done
if ( ! $is_children )
then
if [ "$new_custom_matrix" == "" ]
then
new_custom_matrix="\"$elem_1\""
else
new_custom_matrix="$new_custom_matrix \"$elem_1\""
fi
fi
done
custom_matrix_temp=$(echo "${new_custom_matrix[@]}" | tr ' ' '\n' | sort -u | tr '\n' ',')
custom_final_matrix="[ $(echo "${custom_matrix_temp[@]}")"
custom_final_matrix="$(echo ${custom_final_matrix::-1}) ]"
if [[ "${{ github.event.client_payload.type }}" == "repository_trigger" ]]
then
version_matrix="[ \"release\" ]"
else
version_matrix="[ \"master\" ]"
fi
echo "superbuild matrix: $superbuild_final_matrix"
echo "superbuild build: $superbuild_flag"
echo "custom matrix: $custom_final_matrix"
echo "custom build: $custom_flag"
echo "children: ${children_matrix[@]}"
echo "children_flag build: $children_flag"
echo "children_flag_output: $children_flag_output"
echo "superbuild_matrix=$superbuild_final_matrix" >> $GITHUB_OUTPUT
echo "custom_matrix=$custom_final_matrix" >> $GITHUB_OUTPUT
echo "superbuild_flag=$superbuild_flag" >> $GITHUB_OUTPUT
echo "custom_flag=$custom_flag" >> $GITHUB_OUTPUT
echo "paths=${parsed_list[@]}" >> $GITHUB_OUTPUT
echo "children_matrix=${children_matrix}" >> $GITHUB_OUTPUT
echo "children_flag_output=$children_flag_output" >> $GITHUB_OUTPUT
echo "version=$version_matrix" >> $GITHUB_OUTPUT
outputs:
superbuild_matrix: ${{ steps.set-matrix.outputs.superbuild_matrix }}
custom_matrix: ${{ steps.set-matrix.outputs.custom_matrix }}
superbuild_flag: ${{ steps.set-matrix.outputs.superbuild_flag }}
custom_flag: ${{ steps.set-matrix.outputs.custom_flag }}
paths: ${{ steps.set-matrix.outputs.paths }}
children_matrix: ${{ steps.set-matrix.outputs.children_matrix }}
children_flag: ${{ steps.set-matrix.outputs.children_flag_output }}
version: ${{ steps.set-matrix.outputs.version }}
build_push:
runs-on: [ubuntu-latest]
needs: check_files
if: needs.check_files.outputs.superbuild_flag == 'true'
strategy:
matrix:
apps: ${{fromJson(needs.check_files.outputs.superbuild_matrix)}}
version: ${{fromJson(needs.check_files.outputs.version)}}
tag: [Stable, Unstable, Custom]
exclude:
- version: release
tag: Stable
- version: release
tag: Unstable
- version: master
tag: Custom
fail-fast: false
steps:
- name: Print app name
run: echo ${{matrix.apps}} && echo ${{matrix.version}} && echo ${{matrix.tag}}
#########################################################################################
- uses: oprypin/find-latest-tag@v1
if: matrix.version == 'release'
with:
repository: ${{ env.REPOSITORY_NAME }}
releases-only: true
id: release-version
##################### check out the correct version (master or release) ###############
- uses: actions/checkout@v4
if: matrix.version == 'master'
with:
ref: 'master'
- uses: actions/checkout@v4
if: matrix.version == 'release'
with:
ref: '${{ steps.release-version.outputs.tag }}'
#########################################################################################
- name: Login to DockerHub Registry
run: echo ${{ secrets.DOCKERHUB_PASSWORD }} | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
#########################################################################################
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
##################### Command to set the tag for the date argument ######################
- name: set date argument for Docker build
run: |
echo "$(date +'%d/%m/%Y')" > DATE_
echo "metadata=$(cat DATE_)" > DATE_TAG
echo $(cat DATE_TAG)
##################### Here we check the release version and replace Custom with stable only for the image name ######################
- name: Get release / master version
id: get_version
run: |
echo "VERSION=$( if [ \"${{ matrix.version }}\" == \"release\" ]; then echo \"${{ github.event.client_payload.version }}\"; else echo \"master\"; fi)" >> $GITHUB_OUTPUT
if [ "${{matrix.tag}}" == "Custom" ]
then
echo "TAG=" >> $GITHUB_OUTPUT
else
echo "TAG=$(echo \"-${{matrix.tag}}\" | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT
fi
- name: Get path
id: get_path
run: |
for j in ${{needs.check_files.outputs.paths}}
do
if [ $(echo $j | awk '/'"${{matrix.apps}}"'/') ]
then
path="dockerfile_images/$(echo $j | awk -F'/' '{print $2}' | tr -d '"')"
echo "PATH=$path" >> $GITHUB_OUTPUT
exit 0
fi
done
- name: Get Build Arguments
id: get_args
run: |
start_img=""
source_img=""
sources_args=""
binaries_args=""
tag_arg=""
sources_flag=false
binaries_flag=false
tag_flag=false
tag_github_flag=false
compile_sources=false
compile_binaries=false
demos_matrix=""
demos_flag=false
demos_flag_output=false
iter_demos=0
echo "{{matrix.tag}} - ${{matrix.tag}}"
echo "{{steps.get_version.outputs.TAG}} - ${{steps.get_version.outputs.TAG}}"
echo "{{matrix.version}} - ${{matrix.version}}"
echo "{{matrix.apps}} - ${{matrix.apps}}"
echo "{{steps.get_version.outputs.VERSION}} - ${{steps.get_version.outputs.VERSION}}"
echo "{{env.DEFAULT_USER}} - ${{env.DEFAULT_USER}}"
while read -r line || [ -n "$line" ]
do
echo "line is $line"
line=$(echo "$line" > temp.tmp && sed -i 's/{{matrix.tag}}/${{matrix.tag}}/g' temp.tmp && cat temp.tmp)
line=$(echo "$line" > temp.tmp && sed -i 's/{{steps.get_version.outputs.TAG}}/${{steps.get_version.outputs.TAG}}/g' temp.tmp && cat temp.tmp)
line=$(echo "$line" > temp.tmp && sed -i 's/{{matrix.version}}/${{matrix.version}}/g' temp.tmp && cat temp.tmp)
line=$(echo "$line" > temp.tmp && sed -i 's/{{matrix.apps}}/${{matrix.apps}}/g' temp.tmp && cat temp.tmp)
line=$(echo "$line" > temp.tmp && sed -i 's/{{steps.get_version.outputs.VERSION}}/${{steps.get_version.outputs.VERSION}}/g' temp.tmp && cat temp.tmp)
line=$(echo "$line" > temp.tmp && sed -i 's/{{env.REGISTRY}}/${{env.REGISTRY}}/g' temp.tmp && cat temp.tmp)
line=$(echo "$line" > temp.tmp && sed -i 's@{{env.REPOSITORY_NAME}}@${{env.REPOSITORY_NAME}}@g' temp.tmp && cat temp.tmp)
line=$(echo "$line" > temp.tmp && sed -i 's/{{env.IMAGE_PREFIX}}/${{env.IMAGE_PREFIX}}/g' temp.tmp && cat temp.tmp)
line=$(echo "$line" > temp.tmp && sed -i 's/{{env.REPOSITORY_OWNER}}/${{env.REPOSITORY_OWNER}}/g' temp.tmp && cat temp.tmp)
line=$(echo "$line" > temp.tmp && sed -i 's/{{env.DEFAULT_USER}}/${{env.DEFAULT_USER}}/g' temp.tmp && cat temp.tmp)
line=$(echo "$line" > temp.tmp && sed -i 's/{{env.SUPERBUILD_TAG}}/${{env.SUPERBUILD_TAG}}/g' temp.tmp && cat temp.tmp)
echo "dopo line is $line"
if [ "$line" == "[sources]" ]
then
sources_flag=true
binaries_flag=false
tag_flag=false
compile_sources=true
demos_flag=false
fi
if [ "$line" == "[binaries]" ]
then
sources_flag=false
binaries_flag=true
tag_flag=false
compile_binaries=true
demos_flag=false
fi
if [ "$line" == "[tag]" ]
then
sources_flag=false
binaries_flag=false
tag_flag=true
demos_flag=false
fi
if [ "$line" == "[children]" ]
then
sources_flag=false
binaries_flag=false
tag_flag=false
demos_flag=false
fi
if [ $demos_flag == true ]
then
if [ $iter_demos == 0 ]
then
demos_flag_output=true
demos_matrix="$line"
iter_demos=$((iter_demos+1))
else
demos_matrix="$demos_matrix $line"
fi
fi
if [ "$line" == "[demos]" ]
then
sources_flag=false
binaries_flag=false
tag_flag=false
demos_flag=true
fi
if [ "$line" != "[sources]" ] && [ "$line" != "[binaries]" ] && [ "$line" != "[tag]" ] && [ "$line" != "[superbuild]" ] && [ "$line" != "[children]" ] && [ "$line" != "[demos]" ] && [ "$line" != "" ]
then
if [[ $sources_flag != false ]]
then
sources_args="$sources_args --build-arg \"$line\""
fi
if [[ $binaries_flag != false ]]
then
binaries_args="$binaries_args --build-arg \"$line\""
fi
if [[ $tag_flag != false ]]
then
tag_arg="--tag ${{env.DEFAULT_USER}}/\"$line"
img_name="\"$line"
fi
fi
done < ${{ steps.get_path.outputs.PATH }}/${{matrix.apps}}/conf_build.ini
demos_matrix=$(echo "${demos_matrix[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' ')
demos_matrix="$(echo ${demos_matrix::-1})"
echo "SRC_ARGS=$sources_args" >> $GITHUB_OUTPUT
echo "BIN_ARGS=$binaries_args" >> $GITHUB_OUTPUT
echo "TAG_ARGS=$tag_arg" >> $GITHUB_OUTPUT
echo "IMG_NAME=$img_name" >> $GITHUB_OUTPUT
echo "CMPL_SRC=$compile_sources" >> $GITHUB_OUTPUT
echo "CMPL_BIN=$compile_binaries" >> $GITHUB_OUTPUT
echo "demos_matrix=${demos_matrix[@]}" >> $GITHUB_OUTPUT
echo "demos_flag_output=$demos_flag_output" >> $GITHUB_OUTPUT
echo "sources: $sources_args"
echo "binaries: $binaries_args"
echo "cmpl sources: $compile_sources"
echo "cmpl binaries: $compile_binaries"
echo "cmpl tag: $tag_arg"
echo "demo matrix: ${demos_matrix[@]}"
- name: Build Docker sources images
id: build-sources
if: steps.get_args.outputs.CMPL_SRC == 'true'
run: docker build ${{ steps.get_args.outputs.SRC_ARGS }} --no-cache ${{ steps.get_path.outputs.PATH }}/${{matrix.apps}} --file ${{ steps.get_path.outputs.PATH }}/${{matrix.apps}}/Dockerfile ${{ steps.get_args.outputs.TAG_ARGS }}_sources"
- name: Tag source images for dockerhub
id: tag-sources-dockerhub
if: steps.get_args.outputs.CMPL_SRC == 'true'
run: docker tag ${{env.DEFAULT_USER}}/${{ steps.get_args.outputs.IMG_NAME }}_sources" ${{ secrets.DOCKERHUB_USERNAME }}/${{ steps.get_args.outputs.IMG_NAME }}_sources"
- name: Push Docker source images
id: push-sources-dockerhub
if: steps.get_args.outputs.CMPL_SRC == 'true'
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/${{ steps.get_args.outputs.IMG_NAME }}_sources"
- name: Tag source images for Ghcr.io
id: tag-sources-ghcr
if: steps.get_args.outputs.CMPL_SRC == 'true'
run: docker tag ${{env.DEFAULT_USER}}/${{ steps.get_args.outputs.IMG_NAME }}_sources" ${{ env.REGISTRY }}/${{ env.REPOSITORY_NAME }}/${{ env.IMAGE_PREFIX }}${{ steps.get_args.outputs.IMG_NAME }}_sources"
- name: Push source images to Ghcr.io
id: push-sources-ghcr
if: steps.get_args.outputs.CMPL_SRC == 'true'
run: docker push ${{ env.REGISTRY }}/${{ env.REPOSITORY_NAME }}/${{ env.IMAGE_PREFIX }}${{ steps.get_args.outputs.IMG_NAME }}_sources"
- name: Build Docker binaries images
id: build-binaries
if: steps.get_args.outputs.CMPL_BIN == 'true'
run: docker build ${{ steps.get_args.outputs.BIN_ARGS }} --no-cache ${{ steps.get_path.outputs.PATH }}/${{matrix.apps}} --file ${{ steps.get_path.outputs.PATH }}/${{matrix.apps}}/Dockerfile4Production ${{ steps.get_args.outputs.TAG_ARGS }}_binaries"
- name: Tag binaries images for dockerhub
id: tag-binaries-dockerhub
if: steps.get_args.outputs.CMPL_BIN == 'true'
run: docker tag ${{env.DEFAULT_USER}}/${{ steps.get_args.outputs.IMG_NAME }}_binaries" ${{ secrets.DOCKERHUB_USERNAME }}/${{ steps.get_args.outputs.IMG_NAME }}_binaries"
- name: Push Docker binaries images
id: push-binaries-dockerhub
if: steps.get_args.outputs.CMPL_BIN == 'true'
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/${{ steps.get_args.outputs.IMG_NAME }}_binaries"
- name: Tag binaries images for ghcr
id: tag-binaries-ghcr
if: steps.get_args.outputs.CMPL_BIN == 'true'
run: docker tag ${{env.DEFAULT_USER}}/${{ steps.get_args.outputs.IMG_NAME }}_binaries" ${{ env.REGISTRY }}/${{ env.REPOSITORY_NAME }}/${{ env.IMAGE_PREFIX }}${{ steps.get_args.outputs.IMG_NAME }}_binaries"
- name: Push binaries images to ghcr
id: push-binaries-ghcr
if: steps.get_args.outputs.CMPL_BIN == 'true'
run: docker push ${{ env.REGISTRY }}/${{ env.REPOSITORY_NAME }}/${{ env.IMAGE_PREFIX }}${{ steps.get_args.outputs.IMG_NAME }}_binaries"
# - name: Trigger testing pipeline for source image
# if: steps.build-sources.outcome == 'success' && steps.push-sources.outcome == 'success' && steps.get_args.outputs.demos_flag_output == 'true' && ! cancelled()
# uses: peter-evans/repository-dispatch@v3
# with:
# token: ${{ secrets.GITHUB_TOKEN }}
# repository: {{ }}
# event-type: app_testing_from_code
# client-payload: '{"type": "app_testing_from_code", "app_list": "${{ steps.get_args.outputs.demos_matrix }}", "img_list": "icubteamcode/${{matrix.apps}}", "version_list": ${{steps.get_version.outputs.VERSION}}-${{steps.get_version.outputs.TAG}}, "tag_list": "sources", "children_flag": ${{needs.check_files.outputs.children_flag}}}'
# - name: Trigger testing pipeline for binary image
# if: steps.build-binaries.outcome == 'success' && steps.push-binaries.outcome == 'success' && steps.get_args.outputs.demos_flag_output == 'true' && ! cancelled()
# uses: peter-evans/repository-dispatch@v3
# with:
# token: ${{ secrets.GITHUB_TOKEN }}
# repository: {{ }}
# event-type: app_testing_from_code
# client-payload: '{"type": "app_testing_from_code", "app_list": "${{ steps.get_args.outputs.demos_matrix }}","img_list": "icubteamcode/${{matrix.apps}}", "version_list": ${{steps.get_version.outputs.VERSION}}-${{steps.get_version.outputs.TAG}}, "tag_list": "binaries", "children_flag": ${{needs.check_files.outputs.children_flag}}}'
# outputs:
# img_name: ${{ steps.get_args.outputs.IMG_NAME }}
# version_name: ${{ steps.get_version.outputs.VERSION }}
# tag_name: ${{ steps.get_version.outputs.TAG }}
build_push_custom:
runs-on: [ubuntu-latest]
needs: check_files
if: needs.check_files.outputs.custom_flag == 'true'
strategy:
matrix:
apps: ${{fromJson(needs.check_files.outputs.custom_matrix)}}
version: ${{fromJson(needs.check_files.outputs.version)}}
fail-fast: false
steps:
#########################################################################################
- uses: oprypin/find-latest-tag@v1
if: matrix.version == 'release'
with:
repository: ${{ env.REPOSITORY_NAME }}
releases-only: true
id: release-version
##################### check out the correct version (master or release) ###############
- uses: actions/checkout@v4
if: matrix.version == 'master'
with:
ref: 'master'
- uses: actions/checkout@v4
if: matrix.version == 'release'
with:
ref: '${{ steps.release-version.outputs.tag }}'
#########################################################################################
- name: Login to DockerHub Registry
run: echo ${{ secrets.DOCKERHUB_PASSWORD }} | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
#########################################################################################
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
##################### Command to set the tag for the date argument ######################
- name: set date argument for Docker build
run: |
echo "$(date +'%d/%m/%Y')" > DATE_
echo "metadata=$(cat DATE_)" > DATE_TAG
echo $(cat DATE_TAG)
##################### Here we check the release version and replace Custom with stable only for the image name ######################
- name: Get release / master version
id: get_version
run: |
echo "VERSION=$( if [ \"${{ matrix.version }}\" == \"release\" ]; then echo \"${{ github.event.client_payload.version }}\"; else echo \"master\"; fi)" >> $GITHUB_OUTPUT
- name: Get path
id: get_path
run: |
for j in ${{needs.check_files.outputs.paths}}
do
echo "$(echo $j | awk '/'"${{matrix.apps}}"'/')"
if [ $(echo $j | awk '/'"${{matrix.apps}}"'/') ]
then
path="dockerfile_images/$(echo $j | awk -F'/' '{print $2}' | tr -d '"')"
echo $path
echo "PATH=$path" >> $GITHUB_OUTPUT
exit 0
fi
done
- name: Get Build Arguments
id: get_args
run: |
sources_args=""
binaries_args=""
tag_arg=""
sources_flag=false
binaries_flag=false
tag_flag=false
compile_sources=false
compile_binaries=false
demos_matrix=""
demos_flag=false
demos_flag_output=false
iter_demos=0
while read -r line || [ -n "$line" ]
do
line=$(echo "$line" > temp.tmp && sed -i 's/{{matrix.apps}}/${{matrix.apps}}/g' temp.tmp && cat temp.tmp)
line=$(echo "$line" > temp.tmp && sed -i 's/{{matrix.version}}/${{matrix.version}}/g' temp.tmp && cat temp.tmp)
line=$(echo "$line" > temp.tmp && sed -i 's/{{steps.get_version.outputs.VERSION}}/${{steps.get_version.outputs.VERSION}}/g' temp.tmp && cat temp.tmp)
line=$(echo "$line" > temp.tmp && sed -i 's/{{env.REGISTRY}}/${{env.REGISTRY}}/g' temp.tmp && cat temp.tmp)
line=$(echo "$line" > temp.tmp && sed -i 's@{{env.REPOSITORY_NAME}}@${{env.REPOSITORY_NAME}}@g' temp.tmp && cat temp.tmp)
line=$(echo "$line" > temp.tmp && sed -i 's/{{env.IMAGE_PREFIX}}/${{env.IMAGE_PREFIX}}/g' temp.tmp && cat temp.tmp)
line=$(echo "$line" > temp.tmp && sed -i 's/{{env.REPOSITORY_OWNER}}/${{env.REPOSITORY_OWNER}}/g' temp.tmp && cat temp.tmp)
line=$(echo "$line" > temp.tmp && sed -i 's/{{env.DEFAULT_USER}}/${{env.DEFAULT_USER}}/g' temp.tmp && cat temp.tmp)
line=$(echo "$line" > temp.tmp && sed -i 's/{{env.SUPERBUILD_TAG}}/${{env.SUPERBUILD_TAG}}/g' temp.tmp && cat temp.tmp)
if [ "$line" == "[sources]" ]
then
sources_flag=true
binaries_flag=false
tag_flag=false
compile_sources=true
demos_flag=false
fi
if [ "$line" == "[binaries]" ]
then
sources_flag=false
binaries_flag=true
tag_flag=false
compile_binaries=true
demos_flag=false
fi
if [ "$line" == "[tag]" ]
then
sources_flag=false
binaries_flag=false
tag_flag=true
demos_flag=false
fi
if [ "$line" == "[children]" ]
then
sources_flag=false
binaries_flag=false
tag_flag=false
demos_flag=false
fi
if [ $demos_flag == true ]
then
if [ $iter_demos == 0 ]
then
demos_flag_output=true
demos_matrix="$line"
iter_demos=$((iter_demos+1))
else
demos_matrix="$demos_matrix $line"
fi
fi
if [ "$line" == "[demos]" ]
then
sources_flag=false
binaries_flag=false
tag_flag=false
demos_flag=true
fi
if [ "$line" != "[sources]" ] && [ "$line" != "[binaries]" ] && [ "$line" != "[tag]" ] && [ "$line" != "[superbuild]" ] && [ "$line" != "[children]" ] && [ "$line" != "[demos]" ] && [ "$line" != "" ]
then
if [[ $sources_flag != false ]]
then
sources_args="$sources_args --build-arg \"$line\""
fi
if [[ $binaries_flag != false ]]
then
binaries_args="$binaries_args --build-arg \"$line\""
fi
if [[ $tag_flag != false ]]
then
tag_arg="--tag ${{env.DEFAULT_USER}}/\"$line"
img_name="\"$line"
fi
fi
done < ${{ steps.get_path.outputs.PATH }}/${{matrix.apps}}/conf_build.ini
demos_matrix=$(echo "${demos_matrix[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' ')
demos_matrix="$(echo ${demos_matrix::-1})"
echo "SRC_ARGS=$sources_args" >> $GITHUB_OUTPUT
echo "BIN_ARGS=$binaries_args" >> $GITHUB_OUTPUT
echo "TAG_ARGS=$tag_arg" >> $GITHUB_OUTPUT
echo "IMG_NAME=$img_name" >> $GITHUB_OUTPUT
echo "CMPL_SRC=$compile_sources" >> $GITHUB_OUTPUT
echo "CMPL_BIN=$compile_binaries" >> $GITHUB_OUTPUT
echo "demos_matrix=${demos_matrix[@]}" >> $GITHUB_OUTPUT
echo "demos_flag_output=$demos_flag_output" >> $GITHUB_OUTPUT
echo "sources: $sources_args"
echo "binaries: $binaries_args"
echo "cmpl sources: $compile_sources"
echo "cmpl binaries: $compile_binaries"
echo "cmpl tag: $tag_arg"
- name: Build Docker sources images
id: build-sources
if: steps.get_args.outputs.CMPL_SRC == 'true'
run: docker build ${{ steps.get_args.outputs.SRC_ARGS }} --no-cache ${{ steps.get_path.outputs.PATH }}/${{matrix.apps}} --file ${{ steps.get_path.outputs.PATH }}/${{matrix.apps}}/Dockerfile ${{ steps.get_args.outputs.TAG_ARGS }}_sources"
- name: Tag source images for dockerhub
id: tag-sources-dockerhub
if: steps.get_args.outputs.CMPL_SRC == 'true'
run: docker tag ${{env.DEFAULT_USER}}/${{ steps.get_args.outputs.IMG_NAME }}_sources" ${{ secrets.DOCKERHUB_USERNAME }}/${{ steps.get_args.outputs.IMG_NAME }}_sources"
- name: Push Docker source images
id: push-sources
if: steps.get_args.outputs.CMPL_SRC == 'true'
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/${{ steps.get_args.outputs.IMG_NAME }}_sources"
- name: Tag source images for Ghcr.io
id: tag-sources-ghcr
if: steps.get_args.outputs.CMPL_SRC == 'true'
run: docker tag ${{env.DEFAULT_USER}}/${{ steps.get_args.outputs.IMG_NAME }}_sources" ${{ env.REGISTRY }}/${{ env.REPOSITORY_NAME }}/${{ env.IMAGE_PREFIX }}${{ steps.get_args.outputs.IMG_NAME }}_sources"
- name: Push source images to Ghcr.io
id: push-sources-ghcr
if: steps.get_args.outputs.CMPL_SRC == 'true'
run: docker push ${{ env.REGISTRY }}/${{ env.REPOSITORY_NAME }}/${{ env.IMAGE_PREFIX }}${{ steps.get_args.outputs.IMG_NAME }}_sources"
- name: Build Docker binaries images
id: build-binaries
if: steps.get_args.outputs.CMPL_BIN == 'true'
run: docker build ${{ steps.get_args.outputs.BIN_ARGS }} --no-cache ${{ steps.get_path.outputs.PATH }}/${{matrix.apps}} --file ${{ steps.get_path.outputs.PATH }}/${{matrix.apps}}/Dockerfile4Production ${{ steps.get_args.outputs.TAG_ARGS }}_binaries"
- name: Tag binaries images for dockerhub
id: tag-binaries-dockerhub
if: steps.get_args.outputs.CMPL_BIN == 'true'
run: docker tag ${{env.DEFAULT_USER}}/${{ steps.get_args.outputs.IMG_NAME }}_binaries" ${{ secrets.DOCKERHUB_USERNAME }}/${{ steps.get_args.outputs.IMG_NAME }}_binaries"
- name: Push Docker binaries images
id: push-binaries
if: steps.get_args.outputs.CMPL_BIN == 'true'
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/${{ steps.get_args.outputs.IMG_NAME }}_binaries"
- name: Tag binaries images for ghcr
id: tag-binaries-ghcr
if: steps.get_args.outputs.CMPL_BIN == 'true'
run: docker tag ${{env.DEFAULT_USER}}/${{ steps.get_args.outputs.IMG_NAME }}_binaries" ${{ env.REGISTRY }}/${{ env.REPOSITORY_NAME }}/${{ env.IMAGE_PREFIX }}${{ steps.get_args.outputs.IMG_NAME }}_binaries"
- name: Push binaries images to ghcr
id: push-binaries-ghcr
if: steps.get_args.outputs.CMPL_BIN == 'true'
run: docker push ${{ env.REGISTRY }}/${{ env.REPOSITORY_NAME }}/${{ env.IMAGE_PREFIX }}${{ steps.get_args.outputs.IMG_NAME }}_binaries"
trigger_children_build:
runs-on: [ubuntu-latest]
needs: [build_push_custom, build_push, check_files]
if: always() && needs.check_files.outputs.children_flag == 'true' && ! cancelled()
steps:
# this step ensures that the children are built with the "release" version, which is used when the "repository_trigger" is sent
- name: Repository Dispatch for release
if: github.event.client_payload.type == 'repository_trigger'
uses: peter-evans/repository-dispatch@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
repository: ${{ env.REPOSITORY_NAME }}
event-type: repository_trigger
client-payload: '{"version": "${{ github.event.client_payload.version }}", "type": "repository_trigger", "img_list": "${{ needs.check_files.outputs.children_matrix }}"}'
# in the case where we are building "master" versions, we need to send a trigger that build only master, e.g.: "cron_trigger"
- name: Repository Dispatch for master
if: github.event.client_payload.type != 'repository_trigger'
uses: peter-evans/repository-dispatch@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
repository: ${{ env.REPOSITORY_NAME }}
event-type: cron_trigger
client-payload: '{"type": "cron_trigger", "img_list": "${{ needs.check_files.outputs.children_matrix }}"}'