forked from spiceai/spiceai
-
Notifications
You must be signed in to change notification settings - Fork 0
493 lines (403 loc) · 16.8 KB
/
build_nightly.yml
File metadata and controls
493 lines (403 loc) · 16.8 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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
name: build_nightly
on:
schedule:
- cron: '0 9 * * *' # Runs the workflow at 9:00 AM UTC (1AM PT) every day
workflow_dispatch:
inputs:
publish:
description: Publish the Docker images to the registry (CLI binaries are uploaded as artifacts only)
required: false
type: boolean
default: false
profile_option:
description: 'Which Rust build profile to use? (Default is release)'
required: false
type: choice
options:
- 'release'
- 'release-lto'
default: 'release'
env:
# CI performance optimizations
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
CARGO_NET_RETRY: 10
CARGO_HTTP_TIMEOUT: 60
CARGO_INCREMENTAL: 0
CARGO_NET_GIT_FETCH_WITH_CLI: true
jobs:
check_commits:
runs-on: ubuntu-24.04
outputs:
has_new_commits: ${{ steps.check_commits.outputs.has_new_commits }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
fetch-depth: 0
- name: Check new commits since latest nightly build
id: check_commits
run: |
# Get the latest commit hash from the default branch
latest_commit=$(git rev-parse HEAD)
# Attempt to get the commit hash of the current nightly tag
nightly_commit=$(git rev-list -n 1 nightly 2>/dev/null || echo "")
# Check if there are new commits since the last nightly tag
if [ "$latest_commit" = "$nightly_commit" ]; then
echo "No new commits since the last nightly build. Exiting..."
echo "has_new_commits=false" >> $GITHUB_OUTPUT
exit 0
fi
echo "New commits found. Proceeding with the build."
echo "has_new_commits=true" >> $GITHUB_OUTPUT
shell: bash
setup:
needs: check_commits
if: needs.check_commits.outputs.has_new_commits == 'true'
runs-on: ubuntu-24.04
outputs:
rel_version: ${{ steps.set_version.outputs.rel_version }}
nightly_label: ${{ steps.set_version.outputs.nightly_label }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: Set Nightly REL_VERSION from current timestamp
run: python3 ./.github/scripts/get_release_version.py
- name: Add REL_VERSION to output
id: set_version
run: |
commit_hash=$(git rev-parse --short HEAD)
date="$(date +%Y%m%d)"
version="${date}-${commit_hash}"
nightly_label="nightly.${date}.${commit_hash}"
echo "rel_version=${version}" >> $GITHUB_OUTPUT
echo "nightly_label=${nightly_label}" >> $GITHUB_OUTPUT
echo "Preparing to publish nightly build with version: \"${version}\""
# ==================== BINARY BUILD JOBS ====================
build-linux-x64:
name: Build - Linux x64
needs: [check_commits, setup]
if: needs.check_commits.outputs.has_new_commits == 'true'
runs-on: ubuntu-24.04
env:
RUST_PROFILE: ${{ github.event.inputs.profile_option || 'release' }}
CARGO_TERM_COLOR: always
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: Add nightly postfix to version in Cargo.toml
env:
NIGHTLY_LABEL: ${{ needs.setup.outputs.nightly_label }}
run: |
current_version=$(grep '^version =' Cargo.toml | sed -E 's/version = "(.*)"/\1/')
if [[ "$current_version" =~ -[a-zA-Z0-9]+(\.[0-9]+)*$ ]]; then
new_version="${current_version}.$NIGHTLY_LABEL"
else
new_version="${current_version}-$NIGHTLY_LABEL"
fi
sed -i "s/^version = \".*\"/version = \"${new_version}\"/" Cargo.toml
grep '^version =' Cargo.toml
- name: Set up Rust
uses: ./.github/actions/setup-rust
- name: Set up make
uses: ./.github/actions/setup-make
with:
os: linux
- name: Set up cc
uses: ./.github/actions/setup-cc
- name: Install protoc
uses: ./.github/actions/install-protoc
- name: Build spiced and spice CLI
working-directory: bin/spiced
run: cargo build --profile ${{ env.RUST_PROFILE }} --features release,models -p spiced -p spice --target-dir ../../target
- name: tar spiced binary
run: |
mv target/release/spiced spiced
chmod +x spiced
tar czf spiced_linux_x86_64.tar.gz spiced
- name: tar spice CLI binary
run: |
mv target/release/spice spice
chmod +x spice
tar czf spice_linux_x86_64.tar.gz spice
- name: Print versions
run: |
./spiced --version
./spice version
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: spiced_linux_x86_64
path: spiced_linux_x86_64.tar.gz
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: spice_linux_x86_64
path: spice_linux_x86_64.tar.gz
build-linux-arm64:
name: Build - Linux aarch64
needs: [check_commits, setup]
if: needs.check_commits.outputs.has_new_commits == 'true'
runs-on: hosted-linux-arm-runner
env:
RUST_PROFILE: ${{ github.event.inputs.profile_option || 'release' }}
CARGO_TERM_COLOR: always
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: Add nightly postfix to version in Cargo.toml
env:
NIGHTLY_LABEL: ${{ needs.setup.outputs.nightly_label }}
run: |
current_version=$(grep '^version =' Cargo.toml | sed -E 's/version = "(.*)"/\1/')
if [[ "$current_version" =~ -[a-zA-Z0-9]+(\.[0-9]+)*$ ]]; then
new_version="${current_version}.$NIGHTLY_LABEL"
else
new_version="${current_version}-$NIGHTLY_LABEL"
fi
sed -i "s/^version = \".*\"/version = \"${new_version}\"/" Cargo.toml
grep '^version =' Cargo.toml
- name: Set up Rust
uses: ./.github/actions/setup-rust
- name: Set up cc
uses: ./.github/actions/setup-cc
- name: Install missing tools
run: |
sudo apt-get update
sudo apt-get install build-essential libssl-dev pkg-config cmake unzip -y
- name: Install protoc
uses: ./.github/actions/install-protoc
- name: Build spiced and spice CLI
working-directory: bin/spiced
run: cargo build --profile ${{ env.RUST_PROFILE }} --features release,models -p spiced -p spice --target-dir ../../target
- name: tar spiced binary
run: |
mv target/release/spiced spiced
chmod +x spiced
tar czf spiced_linux_aarch64.tar.gz spiced
- name: tar spice CLI binary
run: |
mv target/release/spice spice
chmod +x spice
tar czf spice_linux_aarch64.tar.gz spice
- name: Print versions
run: |
./spiced --version
./spice version
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: spiced_linux_aarch64
path: spiced_linux_aarch64.tar.gz
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: spice_linux_aarch64
path: spice_linux_aarch64.tar.gz
build-macos-arm64:
name: Build - macOS aarch64
needs: [check_commits, setup]
if: needs.check_commits.outputs.has_new_commits == 'true'
runs-on: spiceai-macos
env:
RUST_PROFILE: ${{ github.event.inputs.profile_option || 'release' }}
CARGO_TERM_COLOR: always
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: Add nightly postfix to version in Cargo.toml
env:
NIGHTLY_LABEL: ${{ needs.setup.outputs.nightly_label }}
run: |
current_version=$(grep '^version =' Cargo.toml | sed -E 's/version = "(.*)"/\1/')
if [[ "$current_version" =~ -[a-zA-Z0-9]+(\.[0-9]+)*$ ]]; then
new_version="${current_version}.$NIGHTLY_LABEL"
else
new_version="${current_version}-$NIGHTLY_LABEL"
fi
sed -i '' "s/^version = \".*\"/version = \"${new_version}\"/" Cargo.toml
grep '^version =' Cargo.toml
- name: Install missing tools
run: |
brew update
brew list cmake || brew install cmake
brew install unixodbc
echo "RUSTFLAGS=-L /opt/homebrew/lib" >> $GITHUB_ENV
- name: Set up Rust
uses: ./.github/actions/setup-rust
- name: Install protoc
uses: ./.github/actions/install-protoc
- name: Build spiced and spice CLI
working-directory: bin/spiced
run: cargo build --profile ${{ env.RUST_PROFILE }} --features release,models -p spiced -p spice --target-dir ../../target
- name: tar spiced binary
run: |
mv target/release/spiced spiced
chmod +x spiced
tar czf spiced_darwin_aarch64.tar.gz spiced
- name: tar spice CLI binary
run: |
mv target/release/spice spice
chmod +x spice
tar czf spice_darwin_aarch64.tar.gz spice
- name: Print versions
run: |
./spiced --version
./spice version
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: spiced_darwin_aarch64
path: spiced_darwin_aarch64.tar.gz
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: spice_darwin_aarch64
path: spice_darwin_aarch64.tar.gz
# ==================== DOCKER IMAGE BUILD JOBS ====================
# These jobs use pre-built spiced binaries from the CLI build jobs
build-docker-arm64:
name: Build Docker - ARM64
needs: [check_commits, setup, build-linux-arm64]
if: needs.check_commits.outputs.has_new_commits == 'true'
runs-on: hosted-linux-arm-runner
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: Download spiced binary
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
with:
name: spiced_linux_aarch64
path: /tmp
- name: Extract spiced binary
run: |
tar -xzf /tmp/spiced_linux_aarch64.tar.gz -C .
chmod +x spiced
mv spiced .spiced-local-tmp
./.spiced-local-tmp --version
- name: Install docker
run: |
sudo apt-get update
sudo apt-get install -y ca-certificates curl gnupg lsb-release
sudo mkdir -m 0755 -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/$(lsb_release -i | awk '{ print tolower($3) }') $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
- name: Start Docker service
run: |
sudo systemctl start docker
sudo systemctl status docker
- name: chown /var/run/docker.sock to current user
run: |
sudo chown $USER /var/run/docker.sock
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4.0.0
- name: Build ARM64 Docker image
uses: docker/build-push-action@bcafcacb16a39f128d818304e6c9c0c18556b85f # v7.1.0
with:
context: .
file: Dockerfile.local
platforms: linux/arm64
outputs: type=docker,name=localhost:5000/spiceai:default-arm64,dest=/tmp/image-arm64-default.tar
cache-from: type=gha,scope=build-docker-arm64
cache-to: type=gha,scope=build-docker-arm64,mode=max
- name: Upload ARM64 Docker image
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: images-arm64
path: /tmp/image-arm64-default.tar
build-docker-amd64:
name: Build Docker - AMD64
needs: [check_commits, setup, build-linux-x64]
if: needs.check_commits.outputs.has_new_commits == 'true'
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: Download spiced binary
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
with:
name: spiced_linux_x86_64
path: /tmp
- name: Extract spiced binary
run: |
tar -xzf /tmp/spiced_linux_x86_64.tar.gz -C .
chmod +x spiced
mv spiced .spiced-local-tmp
./.spiced-local-tmp --version
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4.0.0
- name: Build AMD64 Docker image
uses: docker/build-push-action@bcafcacb16a39f128d818304e6c9c0c18556b85f # v7.1.0
with:
context: .
file: Dockerfile.local
platforms: linux/amd64
outputs: type=docker,name=localhost:5000/spiceai:default-amd64,dest=/tmp/image-amd64-default.tar
cache-from: type=gha,scope=build-docker-amd64
cache-to: type=gha,scope=build-docker-amd64,mode=max
- name: Upload AMD64 Docker image
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: images-amd64
path: /tmp/image-amd64-default.tar
publish-docker:
name: Publish Docker Images
needs: [check_commits, setup, build-docker-amd64, build-docker-arm64]
if: needs.check_commits.outputs.has_new_commits == 'true' && (github.event_name == 'schedule' || inputs.publish)
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
fetch-depth: 0
# Download Docker image artifacts
- name: Download Docker image artifacts
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
with:
path: /tmp
pattern: images-*
merge-multiple: true
- name: Verify artifacts
run: |
echo "Docker images:"
ls -l /tmp
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4.0.0
- name: Start local registry
run: |
docker run -d -p 5000:5000 --restart=always --name registry registry:2
- name: Login to GitHub Package Registry
if: github.event_name == 'schedule' || inputs.publish
uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Import images and create manifests
env:
REL_VERSION: ${{ needs.setup.outputs.rel_version }}
PUBLISH: ${{ github.event_name == 'schedule' || inputs.publish }}
run: |
echo "REL_VERSION=${REL_VERSION}"
echo "PUBLISH=${PUBLISH}"
# Load both architecture images
echo "Loading AMD64 image"
docker load -i /tmp/image-amd64-default.tar
echo "Loading ARM64 image"
docker load -i /tmp/image-arm64-default.tar
# Push images to local registry
echo "Pushing images to local registry"
docker push localhost:5000/spiceai:default-amd64
docker push localhost:5000/spiceai:default-arm64
if [[ "${PUBLISH}" == "true" ]]; then
# Push to GitHub Container Registry
echo "Pushing to GHCR"
docker buildx imagetools create \
-t ghcr.io/spiceai/spiceai-nightly:${REL_VERSION} \
-t ghcr.io/spiceai/spiceai-nightly:latest \
localhost:5000/spiceai:default-amd64 \
localhost:5000/spiceai:default-arm64
echo "Verifying GHCR image:"
docker buildx imagetools inspect ghcr.io/spiceai/spiceai-nightly:${REL_VERSION}
else
echo "Skipping push for non-tag build"
echo "Creating local manifest for testing:"
docker buildx imagetools create \
-t localhost:5000/spiceai:latest \
localhost:5000/spiceai:default-amd64 \
localhost:5000/spiceai:default-arm64
docker buildx imagetools inspect localhost:5000/spiceai:latest
fi
- name: Update nightly tag
run: |
git tag -f nightly
git push origin nightly --force
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}