-
Notifications
You must be signed in to change notification settings - Fork 1
129 lines (115 loc) · 5.73 KB
/
build_docker.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
name: Build Docker Image
on:
workflow_call:
outputs:
client_image_tag:
description: "The tag of the client image that was built"
value: ${{ jobs.build.outputs.client_image_tag }}
application_server_image_tag:
description: "The tag of the application server image that was built"
value: ${{ jobs.build.outputs.application_server_image_tag }}
webhook_listener_image_tag:
description: "The tag of the webhook listener image that was built"
value: ${{ jobs.build.outputs.webhook_listener_image_tag }}
jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- dockerfile: ./client/Dockerfile
image: ghcr.io/ls1intum/helios/client
context: ./client
path: client
- dockerfile: ./server/application-server/Dockerfile
image: ghcr.io/ls1intum/helios/application-server
context: ./server/application-server
path: server
- dockerfile: ./server/webhook-listener/Dockerfile
image: ghcr.io/ls1intum/helios/webhook-listener
context: ./server/webhook-listener
path: webhook-listener
outputs:
client_image_tag: "${{ steps.output-tag-client.outputs.client_image_tag }}"
application_server_image_tag: "${{ steps.output-tag-application-server.outputs.application_server_image_tag }}"
webhook_listener_image_tag: "${{ steps.output-tag-webhook-listener.outputs.webhook_listener_image_tag }}"
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Get changed files in the client folder
id: changed-files-client-folder
uses: tj-actions/changed-files@v45
with:
files: client/**
- name: Get changed files in the application server folder
id: changed-files-application-server-folder
uses: tj-actions/changed-files@v45
with:
files: server/application-server/**
- name: Get changed files in the webhook listener folder
id: changed-files-webhook-listener-folder
uses: tj-actions/changed-files@v45
with:
files: server/webhook-listener/**
- name: Log in to the Container registry
if: ${{ (steps.changed-files-client-folder.outputs.any_changed == 'true') || (steps.changed-files-application-server-folder.outputs.any_changed == 'true') || (steps.changed-files-webhook-listener-folder.outputs.any_changed == 'true') }}
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up QEMU
if: ${{ (steps.changed-files-client-folder.outputs.any_changed == 'true') || (steps.changed-files-application-server-folder.outputs.any_changed == 'true') || (steps.changed-files-webhook-listener-folder.outputs.any_changed == 'true') }}
uses: docker/setup-qemu-action@v3
with:
platforms: all
- name: Install Docker Buildx
if: ${{ (steps.changed-files-client-folder.outputs.any_changed == 'true') || (steps.changed-files-application-server-folder.outputs.any_changed == 'true') || (steps.changed-files-webhook-listener-folder.outputs.any_changed == 'true') }}
id: buildx
uses: docker/setup-buildx-action@v3
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ matrix.image }}
tags: |
# Apply 'latest' tag for default branch
type=raw,value=latest,enable={{is_default_branch}}
type=ref,event=branch
type=ref,event=pr
type=sha
- name: Build and push Docker Image
uses: docker/build-push-action@v6
if: ${{ (steps.changed-files-client-folder.outputs.any_changed == 'true' && matrix.path == 'client') || (steps.changed-files-application-server-folder.outputs.any_changed == 'true' && matrix.path == 'server') || (steps.changed-files-webhook-listener-folder.outputs.any_changed == 'true' && matrix.path == 'webhook-listener') }}
with:
context: ${{ matrix.context }}
file: ${{ matrix.dockerfile }}
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=gha
cache-to: type=gha,mode=max
- id: output-tag-client
run: |
if [[ "${{ matrix.path }}" == "client" ]] && [[ "${{ steps.changed-files-client-folder.outputs.any_changed }}" == "true" ]]; then
echo "client_image_tag=${{ steps.meta.outputs.version }}" >> "$GITHUB_OUTPUT"
elif [[ "${{ matrix.path }}" == "client" ]]; then
echo "client_image_tag=latest" >> "$GITHUB_OUTPUT"
fi
- id: output-tag-application-server
run: |
if [[ "${{ matrix.path }}" == "server" ]] && [[ "${{ steps.changed-files-application-server-folder.outputs.any_changed }}" == "true" ]]; then
echo "application_server_image_tag=${{ steps.meta.outputs.version }}" >> "$GITHUB_OUTPUT"
elif [[ "${{ matrix.path }}" == "server" ]]; then
echo "application_server_image_tag=latest" >> "$GITHUB_OUTPUT"
fi
- id: output-tag-webhook-listener
run: |
if [[ "${{ matrix.path }}" == "webhook-listener" ]] && [[ "${{ steps.changed-files-webhook-listener-folder.outputs.any_changed }}" == "true" ]]; then
echo "webhook_listener_image_tag=${{ steps.meta.outputs.version }}" >> "$GITHUB_OUTPUT"
elif [[ "${{ matrix.path }}" == "webhook-listener" ]]; then
echo "webhook_listener_image_tag=latest" >> "$GITHUB_OUTPUT"
fi