Skip to content

Commit 238e728

Browse files
committed
chore: pythonify BK definitions for docker and coverage
We used to manage these definitions in the BK with no versioning or source control, let's move them to python as all the others so that they stay in sync with the latest and greatest updates to the supported platforms and instance types. Signed-off-by: Riccardo Mancini <[email protected]>
1 parent f101299 commit 238e728

File tree

3 files changed

+81
-8
lines changed

3 files changed

+81
-8
lines changed

.buildkite/common.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ def __init__(self, with_build_step=True, **kwargs):
276276
if with_build_step:
277277
build_cmds, self.shared_build = shared_build()
278278
self.build_group_per_arch(
279-
"🏗️ Build", build_cmds, depends_on_build=False, set_key=True
279+
"🏗️ Build", build_cmds, depends_on_build=False, set_key=self.shared_build
280280
)
281281
else:
282282
self.shared_build = None
@@ -314,9 +314,25 @@ def _adapt_group(self, group):
314314
for step in group["steps"]:
315315
step["command"] = prepend + step["command"]
316316
if self.shared_build is not None:
317-
step["depends_on"] = self.build_key(
318-
get_arch_for_instance(step["agents"]["instance"])
319-
)
317+
if "depends_on" not in step:
318+
step["depends_on"] = []
319+
elif isinstance(step["depends_on"], str):
320+
step["depends_on"] = [step["depends_on"]]
321+
elif isinstance(step["depends_on"], list):
322+
pass
323+
else:
324+
raise ValueError(
325+
f"depends_on should be a string or a list but is {type(step['depends_on'])}"
326+
)
327+
328+
step["depends_on"].append(self.shared_build)
329+
step["depends_on"] = [
330+
self.build_key(
331+
dep, get_arch_for_instance(step["agents"]["instance"])
332+
)
333+
for dep in step["depends_on"]
334+
]
335+
320336
return group
321337

322338
def build_group(self, *args, **kwargs):
@@ -332,17 +348,17 @@ def build_group(self, *args, **kwargs):
332348
group(*args, **combined), depends_on_build=depends_on_build
333349
)
334350

335-
def build_key(self, arch):
351+
def build_key(self, key, arch):
336352
"""Return the Buildkite key for the build step, for the specified arch"""
337-
return self.shared_build.replace("$(uname -m)", arch).replace(".tar.gz", "")
353+
return key.replace("$(uname -m)", arch).replace(".tar.gz", "")
338354

339355
def build_group_per_arch(self, label, *args, **kwargs):
340356
"""
341357
Build a group, parametrizing over the architectures only.
342358
343359
kwargs consumed by this method and not passed down to `group`:
344360
- `depends_on_build` (default: `True`): Whether the steps in this group depend on the artifacts from the shared compilation steps
345-
- `set_key`: If True, causes the generated steps to have a "key" field
361+
- `set_key`: If a string, causes the generated steps to have a "key" field replacing "$(uname -m)" with arch and removing trailing tar.gz
346362
"""
347363
depends_on_build = kwargs.pop("depends_on_build", True)
348364
set_key = kwargs.pop("set_key", None)
@@ -351,7 +367,7 @@ def build_group_per_arch(self, label, *args, **kwargs):
351367
if set_key:
352368
for step in grp["steps"]:
353369
step["key"] = self.build_key(
354-
get_arch_for_instance(step["agents"]["instance"])
370+
set_key, get_arch_for_instance(step["agents"]["instance"])
355371
)
356372
return self.add_step(grp, depends_on_build=depends_on_build)
357373

.buildkite/pipeline_coverage.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env python3
2+
# Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
"""Generate Buildkite pipelines dynamically"""
6+
7+
from common import BKPipeline
8+
9+
pipeline = BKPipeline(with_build_step=False)
10+
11+
pipeline.build_group(
12+
":coverage: Coverage",
13+
pipeline.devtool_test(
14+
devtool_opts="--no-build",
15+
pytest_opts="integration_tests/build/test_coverage.py",
16+
),
17+
)
18+
print(pipeline.to_json())
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env python3
2+
# Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
"""
6+
Buildkite pipeline for testing popular Docker containers
7+
"""
8+
9+
from common import BKPipeline, random_str
10+
11+
pipeline = BKPipeline()
12+
13+
rootfs_tar = f"rootfs_$(uname -m)_{random_str(k=8)}.tar.gz"
14+
15+
pipeline.build_group_per_arch(
16+
":ship: Rootfs build",
17+
[
18+
"sudo yum install -y systemd-container",
19+
"cd tools/test-popular-containers",
20+
"sudo ./build_rootfs.sh",
21+
f'tar czf "{rootfs_tar}" *.ext4',
22+
f'buildkite-agent artifact upload "{rootfs_tar}"',
23+
],
24+
depends_on_build=False,
25+
set_key=rootfs_tar,
26+
)
27+
28+
pipeline.build_group(
29+
":whale: Docker Popular Containers",
30+
[
31+
"./tools/devtool download_ci_artifacts",
32+
f'buildkite-agent artifact download "{rootfs_tar}"',
33+
f'tar -C tools/test-popular-containers xzf "{rootfs_tar}"',
34+
'./tools/devtool sh "cd ./tools/test-popular-containers; PYTHONPATH=../../tests ./test-docker-rootfs.py"',
35+
],
36+
depends_on=rootfs_tar,
37+
)
38+
39+
print(pipeline.to_json())

0 commit comments

Comments
 (0)