From a4ca1d190a5d8cf173cfb07b058bf0cddb1d41e9 Mon Sep 17 00:00:00 2001 From: Russ Webber Date: Thu, 12 Dec 2024 10:52:19 +1100 Subject: [PATCH] fix: throttle the job number on buildjet arm runners --- platform_cli/groups/packaging.py | 11 +++++++++-- platform_cli/groups/release.py | 6 ++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/platform_cli/groups/packaging.py b/platform_cli/groups/packaging.py index 3db9f99..aeea707 100644 --- a/platform_cli/groups/packaging.py +++ b/platform_cli/groups/packaging.py @@ -4,6 +4,7 @@ from psutil import cpu_count import shutil import os +import math from platform_cli.groups.base import PlatformCliGroup from platform_cli.helpers import call, stdout_call, echo @@ -251,8 +252,14 @@ def build(version: str, output: str, no_tests: bool): # type: ignore reportUnus bloom_args += " --ignore-shlibs-missing-info" call(f"bloom-generate {pkg_type} --ros-distro {get_ros_distro()} {bloom_args}") - cores = cpu_count() if cpu_count() else 1 - call(f"DEB_BUILD_OPTIONS=parallel={cores} fakeroot debian/rules binary") + + jobs = cpu_count() if cpu_count() else 1 + if os.environ.get("BUILDJET_THROTTLE", None): + # the number of RAM to cores on the ARM runners are insufficient, so we can't have a 1:1 job:core ratio + echo("Throttling number of jobs due to Buildjet ARM64 Runner limitations", "yellow") + jobs = math.floor(jobs * 0.75) + + call(f"DEB_BUILD_OPTIONS=parallel={jobs} fakeroot debian/rules binary") # the .deb and .ddeb files are in the parent directory # move .deb/.ddeb files into the output folder diff --git a/platform_cli/groups/release.py b/platform_cli/groups/release.py index 9b4782f..13dfdab 100644 --- a/platform_cli/groups/release.py +++ b/platform_cli/groups/release.py @@ -353,6 +353,11 @@ def _build_deb_in_docker( # Make the .debs directory writable by all users os.chmod(host_debs_path, 0o777) + envs = {} + if os.environ.get('RUNNER_ARCH', None) == 'ARM64': + print(os.environ) + envs['BUILDJET_THROTTLE'] = '1' + docker.run( docker_image_name_with_digest, [ @@ -368,6 +373,7 @@ def _build_deb_in_docker( ], platform=docker_plaform, tty=True, + envs=envs, ) def create(self, cli: click.Group):