-
Notifications
You must be signed in to change notification settings - Fork 11
164 lines (144 loc) · 6.07 KB
/
build_docker.yml
File metadata and controls
164 lines (144 loc) · 6.07 KB
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
name: Build Docker Image
on:
workflow_call:
outputs:
server_image_tag:
description: "The tag of the server image that was built"
value: ${{ jobs.build-server.outputs.server_image_tag }}
client_image_tag:
description: "The tag of the client image that was built"
value: ${{ jobs.build-client.outputs.client_image_tag }}
permissions:
contents: read
packages: write
jobs:
build-server:
runs-on: ubuntu-latest
outputs:
server_image_tag: "${{ steps.output-tag.outputs.server_image_tag }}"
steps:
- name: Checkout
uses: actions/checkout@v6
with:
ref: ${{ github.head_ref || github.ref }}
fetch-depth: 1
- name: Get changed files in the server folder
id: changed-files
uses: tj-actions/changed-files@v47
with:
files: server/**
- name: Extract version from build.gradle
id: version
run: echo "version=$(grep '^version = ' server/build.gradle | sed 's/version = "\(.*\)"/\1/')" >> "$GITHUB_OUTPUT"
- name: Check that version is not already released
if: github.ref == format('refs/heads/{0}', github.event.repository.default_branch) && steps.changed-files.outputs.any_changed == 'true'
run: |
VERSION="${{ steps.version.outputs.version }}"
git fetch --tags --quiet
if git rev-parse -q --verify "refs/tags/${VERSION}" >/dev/null || \
git rev-parse -q --verify "refs/tags/v${VERSION}" >/dev/null; then
echo "::error::Version ${VERSION} has already been released (git tag exists). Please bump the version using supporting_scripts/update_version.sh before merging."
exit 1
fi
- name: Log in to the Container registry
if: ${{ steps.changed-files.outputs.any_changed == 'true' }}
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Install Docker Buildx
if: ${{ steps.changed-files.outputs.any_changed == 'true' }}
uses: docker/setup-buildx-action@v4
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v6
with:
images: ghcr.io/ls1intum/thesis-management/thesis-management-server
tags: |
type=raw,value=${{ steps.version.outputs.version }},enable={{is_default_branch}}
type=raw,value=latest,enable={{is_default_branch}}
type=ref,event=branch
type=ref,event=pr
- name: Build and push Docker Image
if: ${{ steps.changed-files.outputs.any_changed == 'true' }}
uses: docker/build-push-action@v7
with:
context: ./
file: ./server.Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=gha,scope=server-image
cache-to: type=gha,scope=server-image,mode=max
- id: output-tag
run: |
if [[ "${{ steps.changed-files.outputs.any_changed }}" == "true" ]]; then
echo "server_image_tag=${{ steps.meta.outputs.version }}" >> "$GITHUB_OUTPUT"
else
echo "server_image_tag=latest" >> "$GITHUB_OUTPUT"
fi
build-client:
runs-on: ubuntu-latest
outputs:
client_image_tag: "${{ steps.output-tag.outputs.client_image_tag }}"
steps:
- name: Checkout
uses: actions/checkout@v6
with:
ref: ${{ github.head_ref || github.ref }}
fetch-depth: 1
- name: Get changed files in the client folder
id: changed-files
uses: tj-actions/changed-files@v47
with:
files: client/**
- name: Extract version from package.json
id: version
run: echo "version=$(node -p "require('./client/package.json').version")" >> "$GITHUB_OUTPUT"
- name: Check that version is not already released
if: github.ref == format('refs/heads/{0}', github.event.repository.default_branch) && steps.changed-files.outputs.any_changed == 'true'
run: |
VERSION="${{ steps.version.outputs.version }}"
git fetch --tags --quiet
if git rev-parse -q --verify "refs/tags/${VERSION}" >/dev/null || \
git rev-parse -q --verify "refs/tags/v${VERSION}" >/dev/null; then
echo "::error::Version ${VERSION} has already been released (git tag exists). Please bump the version using supporting_scripts/update_version.sh before merging."
exit 1
fi
- name: Log in to the Container registry
if: ${{ steps.changed-files.outputs.any_changed == 'true' }}
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Install Docker Buildx
if: ${{ steps.changed-files.outputs.any_changed == 'true' }}
uses: docker/setup-buildx-action@v4
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v6
with:
images: ghcr.io/ls1intum/thesis-management/thesis-management-client
tags: |
type=raw,value=${{ steps.version.outputs.version }},enable={{is_default_branch}}
type=raw,value=latest,enable={{is_default_branch}}
type=ref,event=branch
type=ref,event=pr
- name: Build and push Docker Image
if: ${{ steps.changed-files.outputs.any_changed == 'true' }}
uses: docker/build-push-action@v7
with:
context: ./
file: ./client.Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=gha,scope=client-image
cache-to: type=gha,scope=client-image,mode=max
- id: output-tag
run: |
if [[ "${{ steps.changed-files.outputs.any_changed }}" == "true" ]]; then
echo "client_image_tag=${{ steps.meta.outputs.version }}" >> "$GITHUB_OUTPUT"
else
echo "client_image_tag=latest" >> "$GITHUB_OUTPUT"
fi