diff --git a/.buildkite/metricbeat/pipeline.yml b/.buildkite/metricbeat/pipeline.yml index 7082869ba665..8be300f55806 100644 --- a/.buildkite/metricbeat/pipeline.yml +++ b/.buildkite/metricbeat/pipeline.yml @@ -164,7 +164,9 @@ steps: - label: ":ubuntu: Metricbeat: Crosscompile" key: "mandatory-cross-compile" - command: "make -C metricbeat crosscompile" + command: | + source .buildkite/scripts/qemu.sh + make -C metricbeat crosscompile retry: automatic: - limit: 1 diff --git a/.buildkite/scripts/packaging/packaging.sh b/.buildkite/scripts/packaging/packaging.sh index 98258068cee1..aeaa97db0388 100755 --- a/.buildkite/scripts/packaging/packaging.sh +++ b/.buildkite/scripts/packaging/packaging.sh @@ -1,26 +1,14 @@ #!/usr/bin/env bash # # Centralise the mage package for a given beat in Buildkite. -# It enables multi-arch builds to avoid the exec format errors when -# attempting to build arm64 inside arm64 workers. -# -# For further details, see https://github.com/elastic/elastic-agent/pull/6948 -# and https://github.com/elastic/golang-crossbuild/pull/507 # set -ueo pipefail BEAT_DIR=${1:?-"Error: Beat directory must be specified."} -if [[ "$(uname -m)" == "aarch64" || "$(uname -m)" == "arm64" ]]; then - echo "Skipping qemu installation on arm64 worker" -else - BINFMT_IMAGE="tonistiigi/binfmt:qemu-v9.2.2" - - # Make sure to uninstall first to avoid conflicts - docker run --privileged --rm "$BINFMT_IMAGE" --uninstall qemu-* - docker run --privileged --rm "$BINFMT_IMAGE" --install all -fi +# shellcheck source=/dev/null +source .buildkite/scripts/qemu.sh cd $BEAT_DIR mage package diff --git a/.buildkite/scripts/qemu.sh b/.buildkite/scripts/qemu.sh new file mode 100755 index 000000000000..65488931d2e1 --- /dev/null +++ b/.buildkite/scripts/qemu.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +# +# It enables multi-arch builds to avoid the exec format errors when +# attempting to build arm64 inside arm64 workers. +# +# For further details, see https://github.com/elastic/elastic-agent/pull/6948 +# and https://github.com/elastic/golang-crossbuild/pull/507 +# +set -euo pipefail + +if [[ "$(uname -m)" == "aarch64" || "$(uname -m)" == "arm64" ]]; then + echo "Skipping qemu installation on arm64 worker" +else + BINFMT_IMAGE="tonistiigi/binfmt:qemu-v9.2.2" + + # Make sure to uninstall first to avoid conflicts + docker run --privileged --rm "$BINFMT_IMAGE" --uninstall qemu-* + docker run --privileged --rm "$BINFMT_IMAGE" --install all +fi diff --git a/.buildkite/x-pack/pipeline.xpack.dockerlogbeat.yml b/.buildkite/x-pack/pipeline.xpack.dockerlogbeat.yml index 85b8634b90f0..4f74f99ae0b6 100644 --- a/.buildkite/x-pack/pipeline.xpack.dockerlogbeat.yml +++ b/.buildkite/x-pack/pipeline.xpack.dockerlogbeat.yml @@ -64,6 +64,7 @@ steps: - label: ":ubuntu: x-pack/dockerlogbeat: Ubuntu x86_64 Unit Tests" key: "mandatory-linux-unit-test" command: | + source .buildkite/scripts/qemu.sh cd x-pack/dockerlogbeat mage build unitTest retry: