Skip to content

Commit

Permalink
fix: throttle the job number on buildjet arm runners
Browse files Browse the repository at this point in the history
  • Loading branch information
russkel committed Dec 11, 2024
1 parent 84462ee commit a4ca1d1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
11 changes: 9 additions & 2 deletions platform_cli/groups/packaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions platform_cli/groups/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
[
Expand All @@ -368,6 +373,7 @@ def _build_deb_in_docker(
],
platform=docker_plaform,
tty=True,
envs=envs,
)

def create(self, cli: click.Group):
Expand Down

0 comments on commit a4ca1d1

Please sign in to comment.