-
Notifications
You must be signed in to change notification settings - Fork 1
102 lines (91 loc) · 3.87 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
name: Build Docker Image
on:
workflow_call:
outputs:
server_image_tag:
description: "The tag of the server image that was built"
value: ${{ jobs.build.outputs.server_image_tag }}
client_image_tag:
description: "The tag of the client image that was built"
value: ${{ jobs.build.outputs.client_image_tag }}
jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- dockerfile: ./client.Dockerfile
image: ghcr.io/ls1intum/thesis-track/thesis-track-client
context: ./
path: client
- dockerfile: ./server.Dockerfile
image: ghcr.io/ls1intum/thesis-track/thesis-track-server
context: ./
path: server
outputs:
server_image_tag: "${{ steps.output-tag-server.outputs.server_image_tag }}"
client_image_tag: "${{ steps.output-tag-client.outputs.client_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 server folder
id: changed-files-server-folder
uses: tj-actions/changed-files@v45
with:
files: server/**
- name: Log in to the Container registry
if: ${{ (steps.changed-files-client-folder.outputs.any_changed == 'true') || (steps.changed-files-server-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-server-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-server-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: |
type=raw,value=latest,enable={{is_default_branch}}
type=ref,event=branch
type=ref,event=pr
- name: Build and push Docker Image
uses: docker/build-push-action@v5
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') }}
with:
context: ${{ matrix.context }}
file: ${{ matrix.dockerfile }}
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
- 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-server
run: |
if [[ "${{ matrix.path }}" == "server" ]] && [[ "${{ steps.changed-files-server-folder.outputs.any_changed }}" == "true" ]]; then
echo "server_image_tag=${{ steps.meta.outputs.version }}" >> "$GITHUB_OUTPUT"
elif [[ "${{ matrix.path }}" == "server" ]]; then
echo "server_image_tag=latest" >> "$GITHUB_OUTPUT"
fi