1
+ name : Build Docker Image
2
+
3
+ on :
4
+ workflow_call :
5
+ outputs :
6
+ server_image_tag :
7
+ description : " The tag of the server image that was built"
8
+ value : ${{ jobs.build.outputs.server_image_tag }}
9
+ client_image_tag :
10
+ description : " The tag of the client image that was built"
11
+ value : ${{ jobs.build.outputs.client_image_tag }}
12
+
13
+ jobs :
14
+ build :
15
+ runs-on : ubuntu-latest
16
+ strategy :
17
+ fail-fast : false
18
+ matrix :
19
+ include :
20
+ - dockerfile : .docker/client/Dockerfile
21
+ image : ghcr.io/ls1intum/thaii/client
22
+ context : ./client
23
+ path : client
24
+ - dockerfile : .docker/server/Dockerfile
25
+ image : ghcr.io/ls1intum/thaii/server
26
+ context : ./server
27
+ path : server
28
+ outputs :
29
+ server_image_tag : " ${{ steps.output-tag-server.outputs.server_image_tag }}"
30
+ client_image_tag : " ${{ steps.output-tag-client.outputs.client_image_tag }}"
31
+ steps :
32
+ - name : Checkout
33
+ uses : actions/checkout@v4
34
+ with :
35
+ fetch-depth : 1
36
+
37
+ - name : Get changed files in the client folder
38
+ id : changed-files-client-folder
39
+ uses : tj-actions/changed-files@v44
40
+ with :
41
+ files : client/**
42
+
43
+ - name : Get changed files in the server folder
44
+ id : changed-files-server-folder
45
+ uses : tj-actions/changed-files@v44
46
+ with :
47
+ files : server/**
48
+
49
+ - name : Log in to the Container registry
50
+ if : ${{ (steps.changed-files-client-folder.outputs.any_changed == 'true') || (steps.changed-files-server-folder.outputs.any_changed == 'true') }}
51
+ uses : docker/login-action@v3
52
+ with :
53
+ registry : ghcr.io
54
+ username : ${{ github.actor }}
55
+ password : ${{ secrets.GITHUB_TOKEN }}
56
+
57
+ - name : Set up QEMU
58
+ if : ${{ (steps.changed-files-client-folder.outputs.any_changed == 'true') || (steps.changed-files-server-folder.outputs.any_changed == 'true') }}
59
+ uses : docker/setup-qemu-action@v3
60
+ with :
61
+ platforms : all
62
+
63
+ - name : Install Docker Buildx
64
+ if : ${{ (steps.changed-files-client-folder.outputs.any_changed == 'true') || (steps.changed-files-server-folder.outputs.any_changed == 'true') }}
65
+ id : buildx
66
+ uses : docker/setup-buildx-action@v3
67
+
68
+ - name : Extract metadata (tags, labels) for Docker
69
+ id : meta
70
+ uses : docker/metadata-action@v5
71
+ with :
72
+ images : ${{ matrix.image }}
73
+ tags : |
74
+ type=raw,value=latest,enable={{is_default_branch}}
75
+ type=ref,event=branch
76
+ type=ref,event=pr
77
+
78
+ - name : Build and push Docker Image
79
+ uses : docker/build-push-action@v5
80
+ if : ${{ (steps.changed-files-client-folder.outputs.any_changed == 'true' && matrix.path == 'client') || (steps.changed-files-server-folder.outputs.any_changed == 'true' && matrix.path == 'server') }}
81
+ with :
82
+ context : ${{ matrix.context }}
83
+ file : ${{ matrix.dockerfile }}
84
+ platforms : linux/amd64,linux/arm64
85
+ push : true
86
+ tags : ${{ steps.meta.outputs.tags }}
87
+
88
+ - id : output-tag-client
89
+ run : |
90
+ if [[ "${{ matrix.path }}" == "client" ]] && [[ "${{ steps.changed-files-client-folder.outputs.any_changed }}" == "true" ]]; then
91
+ echo "client_image_tag=${{ steps.meta.outputs.version }}" >> "$GITHUB_OUTPUT"
92
+ elif [[ "${{ matrix.path }}" == "client" ]]; then
93
+ echo "client_image_tag=latest" >> "$GITHUB_OUTPUT"
94
+ fi
95
+
96
+ - id : output-tag-server
97
+ run : |
98
+ if [[ "${{ matrix.path }}" == "server" ]] && [[ "${{ steps.changed-files-server-folder.outputs.any_changed }}" == "true" ]]; then
99
+ echo "server_image_tag=${{ steps.meta.outputs.version }}" >> "$GITHUB_OUTPUT"
100
+ elif [[ "${{ matrix.path }}" == "server" ]]; then
101
+ echo "server_image_tag=latest" >> "$GITHUB_OUTPUT"
102
+ fi
0 commit comments