Skip to content

Commit 703dd7e

Browse files
[8.18] (backport #17995) Build artifacts only for those that match host arch (#18072)
* Build artifacts only for those that match host arch (#17995) * Build artifacts only for those that match host arch Previously when doing platform specific builds (x86_64, arm) BOTH sets of artifacts were produced regarless of host. This increases CI run times and is needless resource consumption. This commit makes the rake tasks compile artifacts for only the host arch it is being run on. * set ARCH for building observabilitysre image * Parallelize system package steps across different build hosts This follows the pattern for prepping docker artifacts by preparing artifacts for a target architecture on a specific build host. This allows us to process x86 and arm packages in parallel across builders. Note that there is no requirement today for the system packages to be built on an arch that matches the target, spearating out to a separate builder opens up that opportunity for us though. (cherry picked from commit f2e4948) # Conflicts: # .buildkite/pull_request_pipeline.yml # rakelib/artifacts.rake * fix merge conflicts * Ensure acceptance test artifacts are being built for correct arch (#18079) * Ensure acceptance test artifacts are being built for correct arch With the improvment in #17995 we only build packages that match the architecture of the host. This is specified with an enviornment variable. Previously the acceptance tests did not need to specifcy the architecture when building packages. This commit updates the builder to build packages with the correct arch. * Ensure ARCH is set for docker acceptance tests * fix merge conflict --------- Co-authored-by: Cas Donoghue <[email protected]>
1 parent 65a6109 commit 703dd7e

File tree

4 files changed

+58
-33
lines changed

4 files changed

+58
-33
lines changed

.buildkite/aarch64_pipeline.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ steps:
133133
- label: "Docker [{{matrix}}] flavor acceptance"
134134
command:
135135
set -euo pipefail
136-
136+
export ARCH="aarch64"
137137
source .buildkite/scripts/common/vm-agent.sh && ci/docker_acceptance_tests.sh {{matrix}}
138138
retry:
139139
automatic:

.buildkite/scripts/dra/generatesteps.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ def to_bk_key_friendly_string(key):
1717

1818
def package_x86_step(branch, workflow_type):
1919
step = f'''
20-
- label: ":package: Build packages / {branch}-{workflow_type.upper()} DRA artifacts"
21-
key: "logstash_build_packages_dra"
20+
- label: ":package: Build x86 packages / {branch}-{workflow_type.upper()} DRA artifacts"
21+
key: "logstash_build_x86_packages_dra"
2222
agents:
2323
provider: gcp
2424
imageProject: elastic-images-prod
@@ -28,12 +28,37 @@ def package_x86_step(branch, workflow_type):
2828
command: |
2929
export WORKFLOW_TYPE="{workflow_type}"
3030
export PATH="/opt/buildkite-agent/.rbenv/bin:/opt/buildkite-agent/.pyenv/bin:$PATH"
31+
export ARCH="x86_64"
3132
eval "$(rbenv init -)"
3233
.buildkite/scripts/dra/build_packages.sh
3334
artifact_paths:
3435
- "**/*.hprof"
3536
'''
37+
return step
3638

39+
def package_arm_step(branch, workflow_type):
40+
# Note: this is currently using an x86 host. We can use a true arm host later
41+
# if we want. System packages dont rely on matching host arch to target artifact arch
42+
# This just parallelizes the packaging for each across different build hosts for shorter
43+
# total time
44+
step = f'''
45+
- label: ":package: Build arm packages / {branch}-{workflow_type.upper()} DRA artifacts"
46+
key: "logstash_build_arm_packages_dra"
47+
agents:
48+
provider: gcp
49+
imageProject: elastic-images-prod
50+
image: family/platform-ingest-logstash-ubuntu-2204
51+
machineType: "n2-standard-16"
52+
diskSizeGb: 200
53+
command: |
54+
export WORKFLOW_TYPE="{workflow_type}"
55+
export PATH="/opt/buildkite-agent/.rbenv/bin:/opt/buildkite-agent/.pyenv/bin:$PATH"
56+
ARCH="aarch64"
57+
eval "$(rbenv init -)"
58+
.buildkite/scripts/dra/build_packages.sh
59+
artifact_paths:
60+
- "**/*.hprof"
61+
'''
3762
return step
3863

3964
def package_x86_docker_step(branch, workflow_type):
@@ -106,6 +131,7 @@ def publish_dra_step(branch, workflow_type, depends_on):
106131
def build_steps_to_yaml(branch, workflow_type):
107132
steps = []
108133
steps.extend(yaml.safe_load(package_x86_step(branch, workflow_type)))
134+
steps.extend(yaml.safe_load(package_arm_step(branch, workflow_type)))
109135
steps.extend(yaml.safe_load(package_x86_docker_step(branch, workflow_type)))
110136
steps.extend(yaml.safe_load(package_aarch64_docker_step(branch, workflow_type)))
111137

.buildkite/scripts/exhaustive-tests/generate-steps.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ def acceptance_linux_steps() -> list[typing.Any]:
125125
source .buildkite/scripts/common/vm-agent.sh
126126
echo "--- Building all artifacts"
127127
./gradlew clean bootstrap
128+
export ARCH="x86_64"
128129
rake artifact:deb artifact:rpm
129130
"""),
130131
"artifact_paths": [
@@ -162,6 +163,7 @@ def acceptance_docker_steps()-> list[typing.Any]:
162163
"command": LiteralScalarString(f"""#!/usr/bin/env bash
163164
set -euo pipefail
164165
source .buildkite/scripts/common/vm-agent.sh
166+
export ARCH="x86_64"
165167
ci/docker_acceptance_tests.sh {flavor}"""),
166168
"retry": {"automatic": [{"limit": 3}]},
167169
})

rakelib/artifacts.rake

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,13 @@ namespace "artifact" do
2222
VERSION_QUALIFIER = ENV["VERSION_QUALIFIER"].to_s.strip.empty? ? nil : ENV["VERSION_QUALIFIER"]
2323
LOCAL_ARTIFACTS = ENV["LOCAL_ARTIFACTS"] || "true"
2424
PACKAGE_SUFFIX = SNAPSHOT_BUILD ? "-SNAPSHOT" : ""
25-
25+
# Normalize ARCH environment variable to either x86_64 or arm64, defaulting to arm64
26+
ARCH = case ENV["ARCH"]
27+
when "x86_64"
28+
"x86_64"
29+
else
30+
"arm64" # default for aarch64, arm64, or any other value (including nil)
31+
end
2632
## TODO: Install new service files
2733
def package_files
2834
res = [
@@ -172,9 +178,11 @@ namespace "artifact" do
172178
#with bundled JDKs
173179
license_details = ['ELASTIC-LICENSE']
174180
@bundles_jdk = true
175-
create_archive_pack(license_details, "x86_64", "linux", "windows", "darwin")
176-
create_archive_pack(license_details, "arm64", "linux", "darwin")
177-
181+
if ARCH == "x86_64"
182+
create_archive_pack(license_details, "x86_64", "linux", "windows", "darwin")
183+
else
184+
create_archive_pack(license_details, "arm64", "linux", "darwin")
185+
end
178186
#without JDK
179187
safe_system("./gradlew bootstrap") #force the build of Logstash jars
180188
@bundles_jdk = false
@@ -186,8 +194,7 @@ namespace "artifact" do
186194
task "archives_docker" => ["prepare", "generate_build_metadata"] do
187195
license_details = ['ELASTIC-LICENSE']
188196
@bundles_jdk = true
189-
create_archive_pack(license_details, "x86_64", "linux", "darwin")
190-
create_archive_pack(license_details, "arm64", "linux", "darwin")
197+
create_archive_pack(license_details, ARCH, "linux", "darwin")
191198
safe_system("./gradlew bootstrap") # force the build of Logstash jars
192199
end
193200

@@ -237,8 +244,11 @@ namespace "artifact" do
237244
#with bundled JDKs
238245
@bundles_jdk = true
239246
license_details = ['APACHE-LICENSE-2.0', "-oss", oss_exclude_paths]
240-
create_archive_pack(license_details, "x86_64", "linux", "windows", "darwin")
241-
create_archive_pack(license_details, "arm64", "linux", "darwin")
247+
if ARCH == "x86_64"
248+
create_archive_pack(license_details, "x86_64", "linux", "windows", "darwin")
249+
else
250+
create_archive_pack(license_details, "arm64", "linux", "darwin")
251+
end
242252

243253
#without JDK
244254
@bundles_jdk = false
@@ -252,20 +262,16 @@ namespace "artifact" do
252262
#with bundled JDKs
253263
@bundles_jdk = true
254264
license_details = ['APACHE-LICENSE-2.0', "-oss", oss_exclude_paths]
255-
create_archive_pack(license_details, "x86_64", "linux", "darwin")
256-
create_archive_pack(license_details, "arm64", "linux", "darwin")
265+
create_archive_pack(license_details, ARCH, "linux", "darwin")
257266
safe_system("./gradlew bootstrap") # force the build of Logstash jars
258267
end
259268

260269
desc "Build an RPM of logstash with all dependencies"
261270
task "rpm" => ["prepare", "generate_build_metadata"] do
262271
#with bundled JDKs
263272
@bundles_jdk = true
264-
puts("[artifact:rpm] building rpm package x86_64")
265-
package_with_jdk("centos", "x86_64")
266-
267-
puts("[artifact:rpm] building rpm package arm64")
268-
package_with_jdk("centos", "arm64")
273+
puts("[artifact:rpm] building rpm package #{ARCH}")
274+
package_with_jdk("centos", ARCH)
269275

270276
#without JDKs
271277
@bundles_jdk = false
@@ -277,11 +283,8 @@ namespace "artifact" do
277283
task "rpm_oss" => ["prepare-oss", "generate_build_metadata"] do
278284
#with bundled JDKs
279285
@bundles_jdk = true
280-
puts("[artifact:rpm] building rpm OSS package x86_64")
281-
package_with_jdk("centos", "x86_64", :oss)
282-
283-
puts("[artifact:rpm] building rpm OSS package arm64")
284-
package_with_jdk("centos", "arm64", :oss)
286+
puts("[artifact:rpm] building rpm OSS package #{ARCH}")
287+
package_with_jdk("centos", ARCH, :oss)
285288

286289
#without JDKs
287290
@bundles_jdk = false
@@ -293,11 +296,8 @@ namespace "artifact" do
293296
task "deb" => ["prepare", "generate_build_metadata"] do
294297
#with bundled JDKs
295298
@bundles_jdk = true
296-
puts("[artifact:deb] building deb package for x86_64")
297-
package_with_jdk("ubuntu", "x86_64")
298-
299-
puts("[artifact:deb] building deb package for OS: linux arm64")
300-
package_with_jdk("ubuntu", "arm64")
299+
puts("[artifact:deb] building deb package for #{ARCH}")
300+
package_with_jdk("ubuntu", ARCH)
301301

302302
#without JDKs
303303
@bundles_jdk = false
@@ -309,11 +309,8 @@ namespace "artifact" do
309309
task "deb_oss" => ["prepare-oss", "generate_build_metadata"] do
310310
#with bundled JDKs
311311
@bundles_jdk = true
312-
puts("[artifact:deb_oss] building deb OSS package x86_64")
313-
package_with_jdk("ubuntu", "x86_64", :oss)
314-
315-
puts("[artifact:deb_oss] building deb OSS package arm64")
316-
package_with_jdk("ubuntu", "arm64", :oss)
312+
puts("[artifact:deb_oss] building deb OSS package #{ARCH}")
313+
package_with_jdk("ubuntu", ARCH, :oss)
317314

318315
#without JDKs
319316
@bundles_jdk = false

0 commit comments

Comments
 (0)