From 3cb067f6343281ccc47dc7ab8ee6b351c13c7fce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Huertas?= Date: Fri, 25 Sep 2026 20:00:04 +0200 Subject: [PATCH 1/4] Added genrule to detect system resources --- genrules/BUILD | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/genrules/BUILD b/genrules/BUILD index c5ca8dd..0492102 100644 --- a/genrules/BUILD +++ b/genrules/BUILD @@ -65,3 +65,62 @@ build_test( ":foo_TXT_4KB_1", ], ) + +# Remote Execution Environment Detection +# These genrules detect system resources where builds are running. + +genrule( + name = "get_cpu_info", + outs = ["cpu_info.txt"], + cmd = "(" + + "echo '=== CPU Info ===' && " + + "(grep -E 'processor|model name|cpu cores|physical id' /proc/cpuinfo || echo 'cpuinfo unavailable') && " + + "echo '' && " + + "echo '=== CPU Count ===' && " + + "(nproc || echo 'nproc unavailable')" + + ") 2>&1 | tee $@ >&2", + tags = ["no-cache"], +) + +genrule( + name = "get_memory_info", + outs = ["memory_info.txt"], + cmd = "(" + + "echo '=== Memory Info ===' && " + + "(grep -E 'MemTotal|MemAvailable' /proc/meminfo || echo 'meminfo unavailable') && " + + "echo '' && " + + "echo '=== Free Memory ===' && " + + "(free -h || echo 'free unavailable')" + + ") 2>&1 | tee $@ >&2", + tags = ["no-cache"], +) + +genrule( + name = "get_system_info", + outs = ["system_info.txt"], + cmd = "(" + + "echo '=== System Info ===' && " + + "echo '=== Hostname ===' && " + + "(hostname || echo 'unavailable') && " + + "echo '' && " + + "echo '=== Kernel ===' && " + + "(uname -a || echo 'unavailable') && " + + "echo '' && " + + "echo '=== Container/OS ===' && " + + "(cat /etc/os-release || echo 'unavailable') && " + + "echo '' && " + + "echo '=== Disk Space ===' && " + + "(df -h / || echo 'unavailable')" + + ") 2>&1 | tee $@ >&2", + tags = ["no-cache"], +) + +# Convenience target to get all info at once +filegroup( + name = "remote_exec_info", + srcs = [ + ":get_cpu_info", + ":get_memory_info", + ":get_system_info", + ], +) From bb90b78b5233f8960bc8153e7d8b85f01a4f3b94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Huertas?= Date: Wed, 30 Sep 2026 17:53:20 +0200 Subject: [PATCH 2/4] Added aws and gcp instance type genrules --- genrules/BUILD | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/genrules/BUILD b/genrules/BUILD index 0492102..cb228b3 100644 --- a/genrules/BUILD +++ b/genrules/BUILD @@ -69,6 +69,27 @@ build_test( # Remote Execution Environment Detection # These genrules detect system resources where builds are running. +genrule( + name = "get_aws_instance_type", + outs = ["aws_instance.txt"], + # Uses '||' to prevent the genrule from failing if the server isn't reachable + cmd = "TOKEN=$$(curl -s -X PUT 'http://169.254.169.254/latest/api/token' -H 'X-aws-ec2-metadata-token-ttl-seconds: 21600') && curl -s -H \"X-aws-ec2-metadata-token: $$TOKEN\" http://169.254.169.254/latest/meta-data/instance-type > $@ || echo 'Not AWS or unavailable' > $@", + exec_properties = { + "dockerNetwork": "standard", + }, + tags = ["no-cache", "no-sandbox"], +) + +genrule( + name = "get_gcp_machine_type", + outs = ["gcp_machine.txt"], + cmd = "curl -s -H 'Metadata-Flavor: Google' http://metadata.google.internal/computeMetadata/v1/instance/machine-type > $@ || echo 'Not GCP or unavailable' > $@", + exec_properties = { + "dockerNetwork": "standard", + }, + tags = ["no-cache", "no-sandbox"], +) + genrule( name = "get_cpu_info", outs = ["cpu_info.txt"], @@ -119,6 +140,8 @@ genrule( filegroup( name = "remote_exec_info", srcs = [ + ":get_aws_instance_type", + ":get_gcp_machine_type", ":get_cpu_info", ":get_memory_info", ":get_system_info", From 2c12167476b220e768dd1dbe4f1691e647327731 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Huertas?= Date: Fri, 9 Oct 2026 19:11:28 +0200 Subject: [PATCH 3/4] Added additional metadata for aws and gcp --- genrules/BUILD | 46 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/genrules/BUILD b/genrules/BUILD index cb228b3..5a4a684 100644 --- a/genrules/BUILD +++ b/genrules/BUILD @@ -72,22 +72,56 @@ build_test( genrule( name = "get_aws_instance_type", outs = ["aws_instance.txt"], - # Uses '||' to prevent the genrule from failing if the server isn't reachable - cmd = "TOKEN=$$(curl -s -X PUT 'http://169.254.169.254/latest/api/token' -H 'X-aws-ec2-metadata-token-ttl-seconds: 21600') && curl -s -H \"X-aws-ec2-metadata-token: $$TOKEN\" http://169.254.169.254/latest/meta-data/instance-type > $@ || echo 'Not AWS or unavailable' > $@", + # Fetches key AWS instance metadata for performance comparison + cmd = "(" + + "TOKEN=$$(curl -s -X PUT 'http://169.254.169.254/latest/api/token' -H 'X-aws-ec2-metadata-token-ttl-seconds: 21600') && " + + "echo '=== AWS Instance Metadata ===' && " + + "echo 'Instance Type:' && " + + "curl -s -H \"X-aws-ec2-metadata-token: $$TOKEN\" http://169.254.169.254/latest/meta-data/instance-type && echo '' && " + + "echo 'AMI ID:' && " + + "curl -s -H \"X-aws-ec2-metadata-token: $$TOKEN\" http://169.254.169.254/latest/meta-data/ami-id && echo '' && " + + "echo 'Availability Zone:' && " + + "curl -s -H \"X-aws-ec2-metadata-token: $$TOKEN\" http://169.254.169.254/latest/meta-data/placement/availability-zone && echo '' && " + + "echo 'Instance Lifecycle:' && " + + "curl -s -H \"X-aws-ec2-metadata-token: $$TOKEN\" http://169.254.169.254/latest/meta-data/instance-life-cycle && echo '' && " + + "echo 'Instance ID:' && " + + "curl -s -H \"X-aws-ec2-metadata-token: $$TOKEN\" http://169.254.169.254/latest/meta-data/instance-id" + + ") > $@ 2>&1 || echo 'Not AWS or unavailable' > $@", exec_properties = { "dockerNetwork": "standard", }, - tags = ["no-cache", "no-sandbox"], + tags = [ + "no-cache", + "no-sandbox", + ], ) genrule( name = "get_gcp_machine_type", outs = ["gcp_machine.txt"], - cmd = "curl -s -H 'Metadata-Flavor: Google' http://metadata.google.internal/computeMetadata/v1/instance/machine-type > $@ || echo 'Not GCP or unavailable' > $@", + # Fetches key GCP instance metadata for performance comparison + cmd = "(" + + "echo '=== GCP Instance Metadata ===' && " + + "echo 'Machine Type:' && " + + "curl -s -H 'Metadata-Flavor: Google' http://metadata.google.internal/computeMetadata/v1/instance/machine-type && echo '' && " + + "echo 'Image:' && " + + "curl -s -H 'Metadata-Flavor: Google' http://metadata.google.internal/computeMetadata/v1/instance/image && echo '' && " + + "echo 'Zone:' && " + + "curl -s -H 'Metadata-Flavor: Google' http://metadata.google.internal/computeMetadata/v1/instance/zone && echo '' && " + + "echo 'Preemptible:' && " + + "curl -s -H 'Metadata-Flavor: Google' http://metadata.google.internal/computeMetadata/v1/instance/scheduling/preemptible && echo '' && " + + "echo 'Instance ID:' && " + + "curl -s -H 'Metadata-Flavor: Google' http://metadata.google.internal/computeMetadata/v1/instance/id && echo '' && " + + "echo 'Instance Name:' && " + + "curl -s -H 'Metadata-Flavor: Google' http://metadata.google.internal/computeMetadata/v1/instance/name" + + ") > $@ 2>&1 || echo 'Not GCP or unavailable' > $@", exec_properties = { "dockerNetwork": "standard", }, - tags = ["no-cache", "no-sandbox"], + tags = [ + "no-cache", + "no-sandbox", + ], ) genrule( @@ -141,8 +175,8 @@ filegroup( name = "remote_exec_info", srcs = [ ":get_aws_instance_type", - ":get_gcp_machine_type", ":get_cpu_info", + ":get_gcp_machine_type", ":get_memory_info", ":get_system_info", ], From 53cc5b7604119e4c8ba277290fc221038fcc5c4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Huertas?= Date: Tue, 13 Oct 2026 20:44:35 +0200 Subject: [PATCH 4/4] AWS and GCP genrules now fetch all metadata --- genrules/BUILD | 34 +++++++--------------------------- 1 file changed, 7 insertions(+), 27 deletions(-) diff --git a/genrules/BUILD b/genrules/BUILD index 5a4a684..a35865f 100644 --- a/genrules/BUILD +++ b/genrules/BUILD @@ -72,21 +72,12 @@ build_test( genrule( name = "get_aws_instance_type", outs = ["aws_instance.txt"], - # Fetches key AWS instance metadata for performance comparison + # Fetches AWS instance metadata cmd = "(" + - "TOKEN=$$(curl -s -X PUT 'http://169.254.169.254/latest/api/token' -H 'X-aws-ec2-metadata-token-ttl-seconds: 21600') && " + - "echo '=== AWS Instance Metadata ===' && " + - "echo 'Instance Type:' && " + - "curl -s -H \"X-aws-ec2-metadata-token: $$TOKEN\" http://169.254.169.254/latest/meta-data/instance-type && echo '' && " + - "echo 'AMI ID:' && " + - "curl -s -H \"X-aws-ec2-metadata-token: $$TOKEN\" http://169.254.169.254/latest/meta-data/ami-id && echo '' && " + - "echo 'Availability Zone:' && " + - "curl -s -H \"X-aws-ec2-metadata-token: $$TOKEN\" http://169.254.169.254/latest/meta-data/placement/availability-zone && echo '' && " + - "echo 'Instance Lifecycle:' && " + - "curl -s -H \"X-aws-ec2-metadata-token: $$TOKEN\" http://169.254.169.254/latest/meta-data/instance-life-cycle && echo '' && " + - "echo 'Instance ID:' && " + - "curl -s -H \"X-aws-ec2-metadata-token: $$TOKEN\" http://169.254.169.254/latest/meta-data/instance-id" + - ") > $@ 2>&1 || echo 'Not AWS or unavailable' > $@", + "curl -sL https://raw.githubusercontent.com/aws/amazon-ec2-utils/main/ec2-metadata -o /tmp/ec2-metadata && " + + "chmod +x /tmp/ec2-metadata && " + + "/tmp/ec2-metadata --all" + + ") > $@ 2>&1 || echo 'ec2-metadata failed or unavailable' > $@", exec_properties = { "dockerNetwork": "standard", }, @@ -99,21 +90,10 @@ genrule( genrule( name = "get_gcp_machine_type", outs = ["gcp_machine.txt"], - # Fetches key GCP instance metadata for performance comparison + # Fetches GCP instance metadata cmd = "(" + "echo '=== GCP Instance Metadata ===' && " + - "echo 'Machine Type:' && " + - "curl -s -H 'Metadata-Flavor: Google' http://metadata.google.internal/computeMetadata/v1/instance/machine-type && echo '' && " + - "echo 'Image:' && " + - "curl -s -H 'Metadata-Flavor: Google' http://metadata.google.internal/computeMetadata/v1/instance/image && echo '' && " + - "echo 'Zone:' && " + - "curl -s -H 'Metadata-Flavor: Google' http://metadata.google.internal/computeMetadata/v1/instance/zone && echo '' && " + - "echo 'Preemptible:' && " + - "curl -s -H 'Metadata-Flavor: Google' http://metadata.google.internal/computeMetadata/v1/instance/scheduling/preemptible && echo '' && " + - "echo 'Instance ID:' && " + - "curl -s -H 'Metadata-Flavor: Google' http://metadata.google.internal/computeMetadata/v1/instance/id && echo '' && " + - "echo 'Instance Name:' && " + - "curl -s -H 'Metadata-Flavor: Google' http://metadata.google.internal/computeMetadata/v1/instance/name" + + "curl -s -H 'Metadata-Flavor: Google' 'http://metadata.google.internal/computeMetadata/v1/instance/?recursive=true' | python3 -m json.tool" + ") > $@ 2>&1 || echo 'Not GCP or unavailable' > $@", exec_properties = { "dockerNetwork": "standard",