-
Notifications
You must be signed in to change notification settings - Fork 381
224 lines (215 loc) · 8.9 KB
/
docker-build.yml
File metadata and controls
224 lines (215 loc) · 8.9 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
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
name: Docker Build
on:
pull_request:
branches:
- main
push:
branches:
- main
tags:
- "[0-9]+.[0-9]+.[0-9]+"
workflow_dispatch:
env:
GRADLE_OPTS: -Dorg.gradle.daemon=false
REGISTRY: ghcr.io
jobs:
metadata:
name: Get Metadata
runs-on: ubuntu-24.04
outputs:
version: ${{ steps.get-version.outputs.ORT_VERSION }}
ort-tags: ${{ steps.meta-ort.outputs.tags }}
ort-labels: ${{ steps.meta-ort.outputs.labels }}
ort-minimal-tags: ${{ steps.meta-ort-minimal.outputs.tags }}
ort-minimal-labels: ${{ steps.meta-ort-minimal.outputs.labels }}
steps:
- name: Checkout Repository
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
with:
fetch-depth: 0
- name: Setup Gradle
uses: gradle/actions/setup-gradle@50e97c2cd7a37755bbfafc9c5b7cafaece252f6e # v6.1.0
- name: Get ORT version
id: get-version
run: |
ORT_VERSION=$(./gradlew -q printVersion)
echo "ORT_VERSION=${ORT_VERSION}" >> $GITHUB_OUTPUT
- name: Extract Metadata for 'ort' Docker Image
id: meta-ort
uses: docker/metadata-action@80c7e94dd9b9319bd5eb7a0e0fe9291e23a2a2e9 # v6.1.0
with:
images: |
${{ env.REGISTRY }}/${{ github.repository_owner }}/ort
tags: |
type=pep440,pattern={{version}}
type=raw,value=${{ steps.get-version.outputs.ORT_VERSION }}
type=ref,event=branch
type=ref,event=tag
type=sha
- name: Extract Metadata for 'ort-minimal' Docker Image
id: meta-ort-minimal
uses: docker/metadata-action@80c7e94dd9b9319bd5eb7a0e0fe9291e23a2a2e9 # v6.1.0
with:
images: |
${{ env.REGISTRY }}/${{ github.repository_owner }}/ort-minimal
tags: |
type=pep440,pattern={{version}}
type=raw,value=${{ steps.get-version.outputs.ORT_VERSION }}
type=ref,event=branch
type=ref,event=tag
type=sha
build:
name: "Docker Build (${{ matrix.name }})"
needs: metadata
strategy:
matrix:
include:
- os: "ubuntu-24.04"
name: "X86"
- os: "ubuntu-24.04-arm"
name: "ARM64"
fail-fast: false
runs-on: "${{ matrix.os }}"
env:
ORT_VERSION: ${{ needs.metadata.outputs.version }}
steps:
- name: Checkout Repository
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
with:
fetch-depth: 0
- name: Free Disk Space
uses: ./.github/actions/free-disk-space
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 # v4.1.0
- name: Login to GitHub Container Registry
uses: docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee # v4.2.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build & Push 'ort' Docker Image
id: build-ort
if: ${{ github.event_name != 'pull_request' }}
uses: docker/build-push-action@f9f3042f7e2789586610d6e8b85c8f03e5195baf # v7.2.0
with:
context: .
labels: ${{ needs.metadata.outputs.ort-labels }}
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ github.repository_owner }}/ort:cache
cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ github.repository_owner }}/ort:cache,mode=max
build-args: ORT_VERSION=${{ env.ORT_VERSION }}
sbom: true
outputs: type=image,name=${{ env.REGISTRY }}/${{ github.repository_owner }}/ort,push-by-digest=true,name-canonical=true,push=true
- name: Build 'ort' Docker Image
if: ${{ github.event_name == 'pull_request' }}
uses: docker/build-push-action@f9f3042f7e2789586610d6e8b85c8f03e5195baf # v7.2.0
with:
context: .
tags: ${{ needs.metadata.outputs.ort-tags }}
labels: ${{ needs.metadata.outputs.ort-labels }}
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ github.repository_owner }}/ort:cache
build-args: ORT_VERSION=${{ env.ORT_VERSION }}
sbom: true
- name: Build & Push 'ort-minimal' Docker Image
id: build-ort-minimal
if: ${{ github.event_name != 'pull_request' }}
uses: docker/build-push-action@f9f3042f7e2789586610d6e8b85c8f03e5195baf # v7.2.0
with:
context: .
# Do not "cache-to" here to not overwrite additional layers from the "full" image, which also contains all
# layers present in the "minimal" image anyway.
labels: ${{ needs.metadata.outputs.ort-minimal-labels }}
target: minimal
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ github.repository_owner }}/ort:cache
build-args: ORT_VERSION=${{ env.ORT_VERSION }}
sbom: true
outputs: type=image,name=${{ env.REGISTRY }}/${{ github.repository_owner }}/ort-minimal,push-by-digest=true,name-canonical=true,push=true
- name: Build 'ort-minimal' Docker Image
if: ${{ github.event_name == 'pull_request' }}
uses: docker/build-push-action@f9f3042f7e2789586610d6e8b85c8f03e5195baf # v7.2.0
with:
context: .
labels: ${{ needs.metadata.outputs.ort-minimal-labels }}
target: minimal
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ github.repository_owner }}/ort:cache
build-args: ORT_VERSION=${{ env.ORT_VERSION }}
sbom: true
- name: Export digests
if: ${{ github.event_name != 'pull_request' }}
run: |
mkdir -p /tmp/digests/ort /tmp/digests/ort-minimal
echo "${{ steps.build-ort.outputs.digest }}" > "/tmp/digests/ort/${{ matrix.name }}"
echo "${{ steps.build-ort-minimal.outputs.digest }}" > "/tmp/digests/ort-minimal/${{ matrix.name }}"
- name: Upload ORT digest
if: ${{ github.event_name != 'pull_request' }}
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: ort-digest-${{ matrix.name }}
path: /tmp/digests/ort/*
- name: Upload ORT-minimal digest
if: ${{ github.event_name != 'pull_request' }}
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: ort-minimal-digest-${{ matrix.name }}
path: /tmp/digests/ort-minimal/*
- name: Print Disk Space
run: df -h
merge:
name: Merge Multi-Arch Manifests
if: ${{ github.event_name != 'pull_request' }}
needs:
- metadata
- build
runs-on: ubuntu-24.04
steps:
- name: Download ORT digests
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
pattern: ort-digest-*
path: /tmp/digests/ort
merge-multiple: true
- name: Download ORT-minimal digests
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
pattern: ort-minimal-digest-*
path: /tmp/digests/ort-minimal
merge-multiple: true
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 # v4.1.0
- name: Login to GitHub Container Registry
uses: docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee # v4.2.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create 'ort' multi-arch manifest
working-directory: /tmp/digests/ort
env:
REGISTRY_IMAGE: ${{ env.REGISTRY }}/${{ github.repository_owner }}/ort
run: |
# Build tag arguments safely
TAGS=()
while IFS= read -r tag; do
[ -n "$tag" ] && TAGS+=("-t" "$tag")
done <<< "${{ needs.metadata.outputs.ort-tags }}"
# Build digest arguments safely
DIGESTS=()
for digest_file in *; do
[ -f "$digest_file" ] && DIGESTS+=("${REGISTRY_IMAGE}@$(cat "$digest_file")")
done
docker buildx imagetools create "${TAGS[@]}" "${DIGESTS[@]}"
- name: Create 'ort-minimal' multi-arch manifest
working-directory: /tmp/digests/ort-minimal
env:
REGISTRY_IMAGE: ${{ env.REGISTRY }}/${{ github.repository_owner }}/ort-minimal
run: |
# Build tag arguments safely
TAGS=()
while IFS= read -r tag; do
[ -n "$tag" ] && TAGS+=("-t" "$tag")
done <<< "${{ needs.metadata.outputs.ort-minimal-tags }}"
# Build digest arguments safely
DIGESTS=()
for digest_file in *; do
[ -f "$digest_file" ] && DIGESTS+=("${REGISTRY_IMAGE}@$(cat "$digest_file")")
done
docker buildx imagetools create "${TAGS[@]}" "${DIGESTS[@]}"