mkpipeline.sh 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/usr/bin/env bash
  2. # Copyright Materialize, Inc. and contributors. All rights reserved.
  3. #
  4. # Use of this software is governed by the Business Source License
  5. # included in the LICENSE file at the root of this repository.
  6. #
  7. # As of the Change Date specified in that file, in accordance with
  8. # the Business Source License, use of this software will be governed
  9. # by the Apache License, Version 2.0.
  10. #
  11. # mkpipeline.sh — dynamically renders a pipeline.yml for Buildkite.
  12. # This script's path is hardcoded into the Buildkite UI. It bootstraps the CI
  13. # process by building the CI builder image, in which all other dependencies
  14. # are installed. Unfortunately that means this script needs to be written in
  15. # Bash, since our Python tools are only available once the CI builder image has
  16. # been built.
  17. set -euo pipefail
  18. pipeline=${1:-test}
  19. bootstrap_steps=
  20. tmpfile=$(mktemp)
  21. for arch in x86_64 aarch64; do
  22. for flavor in stable nightly min; do
  23. (
  24. if ! MZ_DEV_CI_BUILDER_ARCH=$arch bin/ci-builder exists $flavor; then
  25. echo "$arch:$flavor" >> "$tmpfile"
  26. fi
  27. ) &
  28. done
  29. done
  30. wait
  31. while IFS=: read -r arch flavor; do
  32. queue=builder-linux-x86_64
  33. if [[ $arch == aarch64 ]]; then
  34. queue=builder-linux-aarch64-mem
  35. fi
  36. tag=$(MZ_DEV_CI_BUILDER_ARCH=$arch bin/ci-builder tag "$flavor")
  37. bootstrap_steps+="
  38. - label: bootstrap $flavor $arch
  39. command: bin/ci-builder exists $flavor || bin/ci-builder push $flavor
  40. concurrency: 1
  41. concurrency_group: \"ci-builder:$tag\"
  42. agents:
  43. queue: $queue
  44. "
  45. done < "$tmpfile"
  46. rm "$tmpfile"
  47. if [ -n "$bootstrap_steps" ]; then
  48. exec buildkite-agent pipeline upload <<EOF
  49. steps:
  50. $bootstrap_steps
  51. - wait
  52. - label: mkpipeline
  53. env:
  54. CI_BAZEL_BUILD: 1
  55. CI_BAZEL_REMOTE_CACHE: "https://bazel-remote.dev.materialize.com"
  56. command: bin/ci-builder run min bin/pyactivate -m ci.mkpipeline $pipeline $@
  57. priority: 200
  58. agents:
  59. queue: hetzner-x86-64-4cpu-8gb-mkpipeline
  60. retry:
  61. automatic:
  62. - exit_status: -1
  63. signal_reason: none
  64. limit: 2
  65. - signal_reason: agent_stop
  66. limit: 2
  67. EOF
  68. else
  69. exec bin/ci-builder run min bin/pyactivate -m ci.mkpipeline "$pipeline" "$@"
  70. fi