-
Notifications
You must be signed in to change notification settings - Fork 275
/
Copy pathconfig.yml
1223 lines (1173 loc) · 46.1 KB
/
config.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
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
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
version: 2.1
# Cache key bump: 3
# These "CircleCI Orbs" are reusable bits of configuration that can be shared
# across projects. See https://circleci.com/orbs/ for more information.
orbs:
gh: circleci/[email protected]
slack: circleci/[email protected]
secops: apollo/[email protected]
executors:
amd_linux_build: &amd_linux_build_executor
docker:
- image: cimg/base:current
resource_class: xlarge
environment:
CARGO_BUILD_JOBS: 4
RUST_TEST_THREADS: 6
amd_linux_helm: &amd_linux_helm_executor
docker:
- image: cimg/base:current
resource_class: small
amd_linux_test: &amd_linux_test_executor
docker:
- image: cimg/base:current
- image: cimg/redis:7.4.1
- image: jaegertracing/all-in-one:1.54.0
- image: openzipkin/zipkin:3.4.3
- image: ghcr.io/datadog/dd-apm-test-agent/ddapm-test-agent:v1.17.0
resource_class: 2xlarge
environment:
CARGO_BUILD_JOBS: 4
arm_linux_build: &arm_linux_build_executor
docker:
- image: cimg/base:current
resource_class: arm.large
environment:
CARGO_BUILD_JOBS: 8
arm_linux_test: &arm_linux_test_executor
docker:
- image: cimg/base:current
resource_class: arm.xlarge
environment:
CARGO_BUILD_JOBS: 8
macos_build: &macos_build_executor
macos:
# See https://circleci.com/docs/xcode-policy along with the support matrix
# at https://circleci.com/docs/using-macos#supported-xcode-versions.
# We use the major.minor notation to bring in compatible patches.
xcode: "15.4.0"
resource_class: macos.m1.large.gen1
macos_test: &macos_test_executor
macos:
# See https://circleci.com/docs/xcode-policy along with the support matrix
# at https://circleci.com/docs/using-macos#supported-xcode-versions.
# We use the major.minor notation to bring in compatible patches.
xcode: "15.4.0"
resource_class: macos.m1.large.gen1
windows_build: &windows_build_executor
machine:
image: "windows-server-2019-vs2019:2024.02.21"
resource_class: windows.xlarge
shell: bash.exe --login -eo pipefail
windows_test: &windows_test_executor
machine:
image: "windows-server-2019-vs2019:2024.02.21"
resource_class: windows.xlarge
shell: bash.exe --login -eo pipefail
# We don't use {{ arch }} because on windows it is unstable https://discuss.circleci.com/t/value-of-arch-unstable-on-windows/40079
parameters:
toolchain_version:
type: string
default: '{{ checksum ".circleci/config.yml" }}-v3-{{ checksum "~/.arch" }}-{{ checksum "rust-toolchain.toml" }}-{{ checksum "~/.daily_version" }}'
xtask_version:
type: string
default: '{{ checksum ".circleci/config.yml" }}-v3-{{ checksum "~/.arch" }}-{{ checksum "rust-toolchain.toml" }}-{{ checksum "~/.xtask_version" }}'
merge_version:
type: string
default: '{{ checksum ".circleci/config.yml" }}-v3-{{ checksum "~/.arch" }}-{{ checksum "rust-toolchain.toml" }}-{{ checksum "~/.xtask_version" }}-{{ checksum "~/.merge_version" }}'
protoc_version:
type: string
default: "21.8"
# note the cmake version is only used for manual installs, not for installs from a package manager like apt or homebrew
cmake_version:
type: string
default: "3.31.1"
nightly:
type: boolean
default: false
# quick_nightly will skip testing and only build the release artifacts.
quick_nightly:
type: boolean
default: false
test_updated_cargo_deps:
type: boolean
default: false
# These are common environment variables that we want to set on on all jobs.
# While these could conceivably be set on the CircleCI project settings'
# as "Secrets", these are not really secrets, and its convenient to keep them in
# code. Also, most of our secrets are not necessary for _most_ of our jobs, so this enables
# forks of the project to run their own tests on their own CircleCI deployments with no
# additional configuration.
common_job_environment: &common_job_environment
CARGO_NET_GIT_FETCH_WITH_CLI: "true"
RUST_BACKTRACE: full
CARGO_INCREMENTAL: 0
commands:
setup_environment:
parameters:
platform:
type: executor
steps:
- unify_environment:
platform: << parameters.platform >>
- create_cache_keys
- restore_cache:
keys:
- "<< pipeline.parameters.toolchain_version >>"
- install_packages:
platform: << parameters.platform >>
- install_protoc:
platform: << parameters.platform >>
- install_rust:
platform: << parameters.platform >>
- install_extra_tools
- fetch_dependencies
- save_cache:
key: "<< pipeline.parameters.toolchain_version >>"
paths:
- ~/.deb
- ~/.cargo
- ~/.rustup
- ~/.local
- install_xtask
# Even though all executors use bash there are a number of differences that can be taken care of up front.
# Windows shell commands are found on the path before the linux subsystem commands, so use aliases to override.
# OSX doesn't seem to support aliases properly, so we use a symlink
unify_environment:
parameters:
platform:
type: executor
steps:
- run:
name: Setup path
command: echo 'export PATH="$HOME/.local/bin:$HOME/.local/aliases:$PATH"' >> "$BASH_ENV"
- when:
condition:
or:
- equal: [ *amd_linux_build_executor, << parameters.platform >> ]
- equal: [ *amd_linux_test_executor, << parameters.platform >> ]
steps:
- run:
name: Write arch
command: |
echo 'amd_linux' >> ~/.arch
- when:
condition:
or:
- equal: [ *arm_linux_build_executor, << parameters.platform >> ]
- equal: [ *arm_linux_test_executor, << parameters.platform >> ]
steps:
- run:
name: Write arch
command: |
echo 'arm_linux' >> ~/.arch
- when:
condition:
or:
- equal: [ *macos_build_executor, << parameters.platform >> ]
- equal: [ *macos_test_executor, << parameters.platform >> ]
steps:
- run:
name: Make link to md5
command: |
mkdir -p ~/.local/aliases
ln -s /sbin/md5 ~/.local/aliases/md5sum
- run:
name: Write arch
command: |
echo 'osx' >> ~/.arch
- when:
condition:
or:
- equal: [ *windows_build_executor, << parameters.platform >> ]
- equal: [ *windows_test_executor, << parameters.platform >> ]
steps:
- run:
name: Create bash aliases
command: |
echo 'alias find=/bin/find' >> "$BASH_ENV"
echo 'alias sort=/bin/sort' >> "$BASH_ENV"
echo 'export EXECUTABLE_SUFFIX=".exe"' >> "$BASH_ENV"
- run:
name: Write arch
command: |
echo 'windows' >> ~/.arch
# Create files that are useful for cache keys
create_cache_keys:
steps:
- run:
name: Create cache keys
command: |
# The Rust index takes time to download. Update this daily.
date +%j > ~/.daily_version
# The checksum of the xtask/src directory, so that when we make changes to xtask we cause a full rebuild
find xtask/src -type f | while read name; do md5sum $name; done | sort -k 2 | md5sum > ~/.xtask_version
# The closest common ancestor to the default branch, so that test jobs can take advantage previous compiles
git remote set-head origin -a
TARGET_BRANCH=$(git rev-parse --abbrev-ref origin/HEAD)
echo "Target branch is ${TARGET_BRANCH}"
COMMON_ANCESTOR_REF=$(git merge-base HEAD "${TARGET_BRANCH}")
echo "Common ancestor is ${COMMON_ANCESTOR_REF}"
echo "${CIRCLE_PROJECT_REPONAME}-${COMMON_ANCESTOR_REF}" > ~/.merge_version
# Linux specific step to install packages that are needed
install_packages:
parameters:
platform:
type: executor
steps:
- when:
condition:
or:
- equal: [ *amd_linux_build_executor, << parameters.platform >> ]
- equal: [ *amd_linux_test_executor, << parameters.platform >> ]
- equal: [ *arm_linux_build_executor, << parameters.platform >> ]
- equal: [ *arm_linux_test_executor, << parameters.platform >> ]
steps:
- run:
name: Update and install dependencies
command: |
if [[ ! -d "$HOME/.deb" ]]; then
mkdir $HOME/.deb
sudo apt-get update
sudo apt-get --download-only -o Dir::Cache="$HOME/.deb" -o Dir::Cache::archives="$HOME/.deb" install build-essential libssl-dev libdw-dev
fi
sudo dpkg -i $HOME/.deb/*.deb
- when:
condition:
or:
- equal: [ *windows_build_executor, << parameters.platform >> ]
- equal: [ *windows_test_executor, << parameters.platform >> ]
steps:
- run:
name: Install CMake
command: |
mkdir -p "$HOME/.local"
if [[ ! -f "$HOME/.local/bin/cmake" ]]; then
curl -L https://github.com/Kitware/CMake/releases/download/v<< pipeline.parameters.cmake_version >>/cmake-<< pipeline.parameters.cmake_version >>-windows-x86_64.zip --output cmake.zip
# The zip file has a root directory, so we put it somewhere else first before placing the files in .local
unzip cmake.zip -d /tmp > /dev/null
cp /tmp/cmake-<< pipeline.parameters.cmake_version >>-windows-x86_64/* -R "$HOME/.local"
fi
cmake --version
install_protoc:
parameters:
platform:
type: executor
steps:
- when:
condition:
or:
- equal: [ *amd_linux_build_executor, << parameters.platform >> ]
- equal: [ *amd_linux_test_executor, << parameters.platform >> ]
steps:
- run:
name: Install protoc
command: |
if [[ ! -f "$HOME/.local/bin/protoc" ]]; then
curl -L https://github.com/protocolbuffers/protobuf/releases/download/v<< pipeline.parameters.protoc_version >>/protoc-<< pipeline.parameters.protoc_version >>-linux-x86_64.zip --output protoc.zip
unzip protoc.zip -d $HOME/.local
fi
- when:
condition:
or:
- equal: [ *arm_linux_build_executor, << parameters.platform >> ]
- equal: [ *arm_linux_test_executor, << parameters.platform >> ]
steps:
- run:
name: Install protoc
command: |
if [[ ! -f "$HOME/.local/bin/protoc" ]]; then
curl -L https://github.com/protocolbuffers/protobuf/releases/download/v<< pipeline.parameters.protoc_version >>/protoc-<< pipeline.parameters.protoc_version >>-linux-aarch_64.zip --output protoc.zip
unzip protoc.zip -d $HOME/.local
fi
- when:
condition:
or:
- equal: [ *macos_build_executor, << parameters.platform >> ]
- equal: [ *macos_test_executor, << parameters.platform >> ]
steps:
- run:
name: Install protoc
command: |
if [[ ! -f "$HOME/.local/bin/protoc" ]]; then
curl -L https://github.com/protocolbuffers/protobuf/releases/download/v<< pipeline.parameters.protoc_version >>/protoc-<< pipeline.parameters.protoc_version >>-osx-universal_binary.zip --output protoc.zip
unzip protoc.zip -d $HOME/.local
fi
- when:
condition:
or:
- equal: [ *windows_build_executor, << parameters.platform >> ]
- equal: [ *windows_test_executor, << parameters.platform >> ]
steps:
- run:
name: Install protoc
command: |
if [[ ! -f "$HOME/.local/bin/protoc$EXECUTABLE_SUFFIX" ]]; then
curl -L https://github.com/protocolbuffers/protobuf/releases/download/v<< pipeline.parameters.protoc_version >>/protoc-<< pipeline.parameters.protoc_version >>-win64.zip --output protoc.zip
unzip protoc.zip -d $HOME/.local
fi
install_rust:
parameters:
platform:
type: executor
steps:
- run:
name: Install Rust
command: |
if [[ ! -d "$HOME/.cargo" ]]; then
curl https://sh.rustup.rs -sSf -o rustup.sh
chmod 755 ./rustup.sh
./rustup.sh -y --profile minimal --component clippy --component rustfmt --default-toolchain none
$HOME/.cargo/bin/rustc -V
fi
echo 'export PATH="$HOME/.cargo/bin:$PATH"' >> "$BASH_ENV"
- when:
condition:
or:
- equal: [ *windows_build_executor, << parameters.platform >> ]
- equal: [ *windows_test_executor, << parameters.platform >> ]
steps:
- run:
name: Special case for Windows because of ssh-agent
command: |
printf "[net]\ngit-fetch-with-cli = true" >> ~/.cargo/Cargo.toml
- when:
condition:
or:
- equal: [ *macos_build_executor, << parameters.platform >> ]
steps:
- run:
name: Special case for OSX x86_64 builds
command: |
rustup target add x86_64-apple-darwin
- when:
condition:
equal: [ *arm_linux_test_executor, << parameters.platform >> ]
steps:
- run:
name: Install nightly Rust to build the fuzzers
command: |
rustup install nightly
install_extra_tools:
steps:
- run:
name: Install cargo deny, about, edit
command: |
# Until we are able to update rustc to at least 1.81.0,
# we need special handling of the cargo-about command.
rustup install 1.83.0
cargo +1.83.0 install --locked --version 0.6.6 cargo-about
if [[ ! -f "$HOME/.cargo/bin/cargo-deny$EXECUTABLE_SUFFIX" ]]; then
cargo install --locked --version 0.14.21 cargo-deny
cargo install --locked --version 0.12.2 cargo-edit
cargo install --locked --version 0.12.0 cargo-fuzz
fi
if [[ ! -f "$HOME/.cargo/bin/cargo-nextest$EXECUTABLE_SUFFIX" ]]; then
cargo install --locked --version 0.9.70 cargo-nextest
fi
fetch_dependencies:
steps:
- run:
name: Fetch dependencies
command: cargo fetch --locked
install_xtask:
steps:
- restore_cache:
keys:
- "<< pipeline.parameters.xtask_version >>"
- run:
name: Install xtask
command: |
if [[ ! -f "$HOME/.cargo/bin/xtask$EXECUTABLE_SUFFIX" ]]; then
cargo install --locked --path xtask
fi
- save_cache:
key: "<< pipeline.parameters.xtask_version >>"
paths:
- ~/.cargo/bin/xtask
- ~/.cargo/bin/xtask.exe
xtask_lint:
steps:
- restore_cache:
keys:
- "<< pipeline.parameters.merge_version >>-lint"
- run: xtask lint
- when:
condition:
equal: [ "dev", "<< pipeline.git.branch >>" ]
steps:
- save_cache:
key: "<< pipeline.parameters.merge_version >>-lint"
paths:
- target
xtask_release_preverify:
steps:
- run: xtask release pre-verify
xtask_check_helm:
steps:
- run:
name: Validate helm manifests
command: |
# Install Helm
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
# Install kubeconform
KUBECONFORM_INSTALL=$(mktemp -d)
curl -L https://github.com/yannh/kubeconform/releases/latest/download/kubeconform-linux-amd64.tar.gz | tar xz -C "${KUBECONFORM_INSTALL}"
# Create list of kube versions
CURRENT_KUBE_VERSIONS=$(curl -s -L https://raw.githubusercontent.com/kubernetes/website/main/data/releases/schedule.yaml \
| yq -o json '.' \
| jq --raw-output '.schedules[] | select((now | strftime("%Y-%m-%dT00:00:00Z")) as $date | .releaseDate < $date and .endOfLifeDate > $date) | select(.previousPatches != null) | .previousPatches[].release')
TEMPLATE_DIR=$(mktemp -d)
MINOR_VERSION="${kube_version%.*}"
SUCCEEDED=false
# For each k8s minor version (e.g.: 1.28) we will try to validate against the most recent patch release (e.g. 1.28.3)
# We use curl --head to check if support is available. If it isn't we then try the next most recent release.
# As soon as we find an available release we try to use it. If we don't find an available release for a minor version, then we will ignore that silently
for kube_version in ${CURRENT_KUBE_VERSIONS}; do
if [[ "${kube_version%.*}" == "${MINOR_VERSION}" ]]; then
if [[ ${SUCCEEDED} == true ]]; then
continue
fi
else
MINOR_VERSION="${kube_version%.*}"
SUCCEEDED=false
fi
# Sometimes the database has not been updated with schema details. If that happens, just skip the kubeconform checks until the database is updated"
if ! curl --head --silent --output /dev/null --fail "https://github.com/yannh/kubernetes-json-schema/tree/master/v${kube_version}"; then
echo "Skipping validation for kubernetes version: ${kube_version} until the schema database is updated."
continue
fi
echo "Validating against schema version: ${kube_version}"
# Use helm to template our chart against kube_version
helm template --kube-version "${kube_version}" router helm/chart/router --set autoscaling.enabled=true > "${TEMPLATE_DIR}/router-${kube_version}.yaml"
# Execute kubeconform on our templated charts to ensure they are good
"${KUBECONFORM_INSTALL}/kubeconform" \
--kubernetes-version "${kube_version}" \
--strict \
--schema-location default \
--verbose \
"${TEMPLATE_DIR}/router-${kube_version}.yaml"
SUCCEEDED=true
done
xtask_check_compliance:
steps:
- restore_cache:
keys:
- "<< pipeline.parameters.merge_version >>-compliance"
# cargo-deny fetches a rustsec advisory DB, which has to happen on github.com over https
- run: git config --global --unset-all url.ssh://[email protected]
- run: xtask check-compliance
- when:
condition:
equal: [ "dev", "<< pipeline.git.branch >>" ]
steps:
- save_cache:
key: "<< pipeline.parameters.merge_version >>-compliance"
paths:
- target
xtask_test:
parameters:
variant:
type: string
default: "default"
steps:
- restore_cache:
keys:
- "<< pipeline.parameters.merge_version >>-test-<< parameters.variant >>"
- run:
name: Run tests
environment:
# Use the settings from the "ci" profile in nextest configuration.
NEXTEST_PROFILE: ci
# Temporary disable lib backtrace since it crashing on MacOS
# TODO: remove this workaround once we update to Xcode >= 15.1.0
# See: https://github.com/apollographql/router/pull/5462
RUST_LIB_BACKTRACE: 0
command: xtask test --workspace --locked --features ci,snapshot
- run:
name: Delete large files from cache
command: |
find target/debug/deps -type f -size +50M -delete
rm target/debug/router*
- when:
condition:
equal: [ "dev", "<< pipeline.git.branch >>" ]
steps:
- save_cache:
key: "<< pipeline.parameters.merge_version >>-test-<< parameters.variant >>"
paths:
- target
- store_test_results:
# The results from nextest that power the CircleCI Insights.
path: ./target/nextest/ci/junit.xml
fuzz_build:
steps:
- run: cargo +nightly fuzz build
jobs:
lint:
environment:
<<: *common_job_environment
parameters:
platform:
type: executor
executor: << parameters.platform >>
steps:
- checkout
- setup_environment:
platform: << parameters.platform >>
- xtask_lint
check_helm:
environment:
<<: *common_job_environment
parameters:
platform:
type: executor
executor: << parameters.platform >>
steps:
- when:
condition:
equal: [ *amd_linux_helm_executor, << parameters.platform >> ]
steps:
- checkout
- xtask_check_helm
check_compliance:
environment:
<<: *common_job_environment
parameters:
platform:
type: executor
executor: << parameters.platform >>
steps:
- checkout
- setup_environment:
platform: << parameters.platform >>
- xtask_check_compliance
test:
environment:
<<: *common_job_environment
parameters:
platform:
type: executor
fuzz:
type: boolean
default: false
executor: << parameters.platform >>
steps:
- checkout
- setup_environment:
platform: << parameters.platform >>
- xtask_test
- when:
condition:
and:
- equal: [ true, << parameters.fuzz >> ]
- equal: [ *arm_linux_test_executor, << parameters.platform >> ]
steps:
- fuzz_build
test_updated:
environment:
<<: *common_job_environment
parameters:
platform:
type: executor
default: amd_linux_test
from_test_updated_cargo_deps_workflow:
type: boolean
default: false
executor: << parameters.platform >>
steps:
- checkout
- setup_environment:
platform: << parameters.platform >>
- run:
name: Update all Rust dependencies
command: |
rm Cargo.lock
cargo fetch
- xtask_test:
variant: "updated"
- when:
condition:
equal: [ true, << parameters.from_test_updated_cargo_deps_workflow >> ]
steps:
- slack/notify:
event: fail
custom: |
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ":x: The `test_updated_cargo_deps` workflow has **failed** for `${CIRCLE_JOB}` on `${CIRCLE_PROJECT_REPONAME}`'s `${CIRCLE_BRANCH}`!"
}
},
{
"type": "actions",
"elements": [
{
"type": "button",
"action_id": "success_tagged_deploy_view",
"text": {
"type": "plain_text",
"text": "View Job"
},
"url": "${CIRCLE_BUILD_URL}"
}
]
}
]
}
- slack/notify:
event: pass
custom: |
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ":white_check_mark: The `test_updated_cargo_deps` workflow has passed for `${CIRCLE_JOB}` on `${CIRCLE_PROJECT_REPONAME}`'s `${CIRCLE_BRANCH}`."
}
},
{
"type": "actions",
"elements": [
{
"type": "button",
"action_id": "success_tagged_deploy_view",
"text": {
"type": "plain_text",
"text": "View Job"
},
"url": "${CIRCLE_BUILD_URL}"
}
]
}
]
}
pre_verify_release:
environment:
<<: *common_job_environment
parameters:
platform:
type: executor
executor: << parameters.platform >>
steps:
- checkout
- setup_environment:
platform: << parameters.platform >>
- xtask_release_preverify
build_release:
parameters:
platform:
type: executor
nightly:
type: boolean
default: false
executor: << parameters.platform >>
environment:
<<: *common_job_environment
RELEASE_BIN: router
APPLE_TEAM_ID: "YQK948L752"
APPLE_USERNAME: "[email protected]"
REPO_URL: << pipeline.project.git_url >>
steps:
- checkout
- setup_environment:
platform: << parameters.platform >>
- when:
condition:
or:
- equal: [ *macos_build_executor, << parameters.platform >> ]
steps:
- when:
condition:
equal: [ true, << parameters.nightly >> ]
steps:
- run: cargo xtask release prepare nightly
- run:
command: >
cargo xtask dist --target aarch64-apple-darwin
- run:
command: >
cargo xtask dist --target x86_64-apple-darwin
- run:
command: >
mkdir -p artifacts
- run:
command: >
cargo xtask package
--target aarch64-apple-darwin
--apple-team-id ${APPLE_TEAM_ID}
--apple-username ${APPLE_USERNAME}
--cert-bundle-base64 ${MACOS_CERT_BUNDLE_BASE64}
--cert-bundle-password ${MACOS_CERT_BUNDLE_PASSWORD}
--keychain-password ${MACOS_KEYCHAIN_PASSWORD}
--notarization-password ${MACOS_NOTARIZATION_PASSWORD}
--output artifacts/
- run:
command: >
cargo xtask package
--target x86_64-apple-darwin
--apple-team-id ${APPLE_TEAM_ID}
--apple-username ${APPLE_USERNAME}
--cert-bundle-base64 ${MACOS_CERT_BUNDLE_BASE64}
--cert-bundle-password ${MACOS_CERT_BUNDLE_PASSWORD}
--keychain-password ${MACOS_KEYCHAIN_PASSWORD}
--notarization-password ${MACOS_NOTARIZATION_PASSWORD}
--output artifacts/
- when:
condition:
and:
- equal: [ *amd_linux_build_executor, << parameters.platform >> ]
- equal: [ true, << parameters.nightly >> ]
steps:
- run:
name: Helm install
command: |
# Install Helm
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
- run:
name: helm-docs install
command: |
# install golang (to ${HOME}/go)
curl -OLs https://go.dev/dl/go1.21.3.linux-amd64.tar.gz
tar -C "${HOME}" -xf go1.21.3.linux-amd64.tar.gz
# install helm-docs
PATH="${HOME}/go/bin" GOPATH="${HOME}/.local" GO111MODULE=on go install github.com/norwoodj/helm-docs/cmd/helm-docs@latest
- when:
condition:
or:
- equal: [ *amd_linux_build_executor, << parameters.platform >> ]
- equal: [ *arm_linux_build_executor, << parameters.platform >> ]
- equal: [ *windows_build_executor, << parameters.platform >> ]
steps:
# This will set the version to include current date and commit hash
- when:
condition:
equal: [ true, << parameters.nightly >> ]
steps:
- run: cargo xtask release prepare nightly
- run:
command: >
cargo xtask dist
- run:
command: >
mkdir -p artifacts
- run:
command: >
cargo xtask package --output artifacts/
- persist_to_workspace:
root: artifacts
paths:
- "*"
- store_artifacts:
path: artifacts/
- when:
condition:
and:
- equal: [ *amd_linux_build_executor, << parameters.platform >> ]
- equal: [ true, << parameters.nightly >> ]
- matches:
pattern: "^https:\\/\\/github\\.com\\/apollographql\\/router.*$"
value: << pipeline.project.git_url >>
steps:
- setup_remote_docker:
# CircleCI Image Policy
# https://circleci.com/docs/remote-docker-images-support-policy/
version: docker23
docker_layer_caching: true
- run:
name: Docker build
command: |
# Source of the new image will be ser to the repo URL.
# This will have the effect of setting org.opencontainers.image.source and org.opencontainers.image.author to the originating pipeline
# Therefore the docker image will have the same permissions as the originating project.
# See: https://docs.github.com/en/packages/learn-github-packages/connecting-a-repository-to-a-package#connecting-a-repository-to-a-container-image-using-the-command-line
BASE_VERSION=$(cargo metadata --format-version=1 --no-deps | jq --raw-output '.packages[0].version')
ARTIFACT_URL="https://output.circle-artifacts.com/output/job/${CIRCLE_WORKFLOW_JOB_ID}/artifacts/0/artifacts/router-v${BASE_VERSION}-x86_64-unknown-linux-gnu.tar.gz"
VERSION="v$(echo "${BASE_VERSION}" | tr "+" "-")"
ROUTER_TAG=ghcr.io/apollographql/nightly/router
echo "REPO_URL: ${REPO_URL}"
echo "BASE_VERSION: ${BASE_VERSION}"
echo "ARTIFACT_URL: ${ARTIFACT_URL}"
echo "VERSION: ${VERSION}"
echo "ROUTER_TAG: ${ROUTER_TAG}"
# Create a multi-arch builder which works properly under qemu
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
docker context create buildx-build
docker buildx create --driver docker-container --use buildx-build
docker buildx inspect --bootstrap
# Note: GH Token owned by apollo-bot2, no expire
echo ${GITHUB_OCI_TOKEN} | docker login ghcr.io -u apollo-bot2 --password-stdin
# TODO: Can't figure out how to build multi-arch image from ARTIFACT_URL right now. Figure out later...
# Build and push debug image
docker buildx build --load --platform linux/amd64 --build-arg CIRCLE_TOKEN="${CIRCLE_TOKEN}" --build-arg REPO_URL="${REPO_URL}" --build-arg ARTIFACT_URL="${ARTIFACT_URL}" --build-arg DEBUG_IMAGE="true" --build-arg ROUTER_RELEASE=${VERSION} -f dockerfiles/Dockerfile.router -t ${ROUTER_TAG}:${VERSION}-debug .
docker push ${ROUTER_TAG}:${VERSION}-debug
# Build and push release image
docker buildx build --load --platform linux/amd64 --build-arg CIRCLE_TOKEN="${CIRCLE_TOKEN}" --build-arg REPO_URL="${REPO_URL}" --build-arg ARTIFACT_URL="${ARTIFACT_URL}" --build-arg ROUTER_RELEASE=${VERSION} -f dockerfiles/Dockerfile.router -t ${ROUTER_TAG}:${VERSION} .
docker push ${ROUTER_TAG}:${VERSION}
# save containers for analysis
mkdir built-containers
docker save -o built-containers/router_${VERSION}-debug.tar ${ROUTER_TAG}:${VERSION}-debug
docker save -o built-containers/router_${VERSION}.tar ${ROUTER_TAG}:${VERSION}
- persist_to_workspace:
root: .
paths:
- "built-containers/*.tar"
- run:
name: Helm build
command: |
# Package up the helm chart
helm package helm/chart/router
# Make sure we have the newest chart
CHART=$(ls -t router*.tgz| head -1)
# Note: GH Token owned by apollo-bot2, no expire
echo ${GITHUB_OCI_TOKEN} | helm registry login -u apollo-bot2 --password-stdin ghcr.io
# Push chart to repository
helm push ${CHART} oci://ghcr.io/apollographql/helm-charts-nightly
- when:
condition:
equal: [ true, << parameters.nightly >> ]
steps:
- slack/notify:
event: fail
custom: |
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ":x: A `nightly` release run has **failed** for `${CIRCLE_JOB}` on `${CIRCLE_PROJECT_REPONAME}`'s `${CIRCLE_BRANCH}`!"
}
},
{
"type": "actions",
"elements": [
{
"type": "button",
"action_id": "success_tagged_deploy_view",
"text": {
"type": "plain_text",
"text": "View Job"
},
"url": "${CIRCLE_BUILD_URL}"
}
]
}
]
}
- slack/notify:
event: pass
custom: |
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ":white_check_mark: A `nightly` build has completed for `${CIRCLE_JOB}` on `${CIRCLE_PROJECT_REPONAME}`'s `${CIRCLE_BRANCH}`."
}
},
{
"type": "actions",
"elements": [
{
"type": "button",
"action_id": "success_tagged_deploy_view",
"text": {
"type": "plain_text",
"text": "View Job"
},
"url": "${CIRCLE_BUILD_URL}"
}
]
}
]
}
publish_github_release:
docker:
- image: cimg/base:current
resource_class: small
environment:
<<: *common_job_environment
VERSION: << pipeline.git.tag >>
steps:
- when:
condition:
not:
equal: [ "https://github.com/apollographql/router", << pipeline.project.git_url >> ]
steps:
- run:
command: >
echo "Not publishing any github release."
- when:
condition:
equal: [ "https://github.com/apollographql/router", << pipeline.project.git_url >> ]
steps:
- checkout
- setup_remote_docker:
# CircleCI Image Policy
# https://circleci.com/docs/remote-docker-images-support-policy/
version: 20.10.24
docker_layer_caching: true
- attach_workspace:
at: artifacts
- gh/setup
- run:
command: >
cd artifacts && sha256sum *.tar.gz > sha256sums.txt
- run:
command: >
cd artifacts && md5sum *.tar.gz > md5sums.txt
- run:
command: >
cd artifacts && sha1sum *.tar.gz > sha1sums.txt
- run:
name: Create GitHub Release
command: >
case "$VERSION" in
# If the VERSION contains a dash, consider it a pre-release version.
# This is in-line with SemVer's expectations/designations!
*-*) gh release create $VERSION --prerelease --notes-file /dev/null --title $VERSION artifacts/* ;;
# In all other cases, publish it as the latest version.
*) gh release create $VERSION --notes-file /dev/null --title $VERSION artifacts/* ;;
esac
- run:
name: Docker build
command: |
ROUTER_TAG=ghcr.io/apollographql/router
# Create a multi-arch builder which works properly under qemu
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
docker context create buildx-build
docker buildx create --driver docker-container --use buildx-build
docker buildx inspect --bootstrap
# Note: GH Token owned by apollo-bot2, no expire
echo ${GITHUB_OCI_TOKEN} | docker login ghcr.io -u apollo-bot2 --password-stdin
# To prevent overwrite, check to see if our images already exists
# If the manifest command succeeds, the images already exist
docker manifest inspect ${ROUTER_TAG}:${VERSION} > /dev/null && exit 1
docker manifest inspect ${ROUTER_TAG}:${VERSION}-debug > /dev/null && exit 1
# Build and push debug image
docker buildx build --platform linux/amd64,linux/arm64 --push --build-arg DEBUG_IMAGE="true" --build-arg ROUTER_RELEASE=${VERSION} -f dockerfiles/Dockerfile.router -t ${ROUTER_TAG}:${VERSION}-debug .
# Build and push release image
docker buildx build --platform linux/amd64,linux/arm64 --push --build-arg ROUTER_RELEASE=${VERSION} -f dockerfiles/Dockerfile.router -t ${ROUTER_TAG}:${VERSION} .