Skip to content

Conversation

@swiatekm
Copy link
Contributor

@swiatekm swiatekm commented Jul 21, 2025

What does this PR do?

Mounts the Go build cache into the golang-crossbuild container. To facilitate this and allow the container to generate the build cache, it also changes the crossbuild container to run as the host user.

This has been tested locally on both Mac and Linux, and the CI passes for this PR. It probably requires somewhat more careful testing, as permission changes in the host build cache could potentially result in breakage for unified releases.

Why is it important?

This reduces the build time of agent during packaging by around 75%. On my machine, the same-architecture build goes from 2 minutes to 25 seconds.

Checklist

  • I have read and understood the pull request guidelines of this project.
  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • [ ] I have made corresponding changes to the documentation
  • [ ] I have made corresponding change to the default configuration files
  • [ ] I have added tests that prove my fix is effective or that my feature works
  • [ ] I have added an entry in ./changelog/fragments using the changelog tool
  • [ ] I have added an integration test or an E2E test

How to test this PR locally

Run mage crossbuild and time it.

Related issues

@swiatekm swiatekm added skip-changelog chore Tasks that just need to be done, they are neither bug, nor enhancements backport-active-all Automated backport with mergify to all the active branches labels Jul 21, 2025
@swiatekm swiatekm marked this pull request as ready for review July 28, 2025 13:05
@swiatekm swiatekm requested a review from a team as a code owner July 28, 2025 13:05
@swiatekm swiatekm requested review from a team, pchila, pkoutsovasilis and straistaru July 28, 2025 13:05
Copy link
Member

@v1v v1v left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to test these set of changes in some of the other BK pipelines:

Can you please run them and copy the link to those builds in this PR please?

@swiatekm
Copy link
Contributor Author

@v1v both of them succeeded at the build steps, but failed at the publishing step, even though I set them to dry-run. Not sure if that's in some way an effect of this change or if I made a mistake.

See:

@v1v
Copy link
Member

v1v commented Jul 29, 2025

That's an expected error, I think it does not support feature branches:

The specified project directory '/release/project-configs/chore/crossbuild-build-cache' does not exist.

https://buildkite.com/elastic/elastic-agent-package/builds/7168#01985144-a389-4509-af44-f1717edd59b2/282-310
https://buildkite.com/elastic/elastic-agent-binary-dra/builds/4211#0198518a-dc7c-4bb0-ad62-f7d65c48a0b9/145-173

As far as I see, you can override them with DRA_BRANCH=main:


I'm gonna run them again:

using the env variables:

DRA_BRANCH="main"
DRA_DRY_RUN="--dry-run"
DRA_PROJECT_ARTIFACT_ID="agent-core"
DRA_PROJECT_ID="elastic-agent-core"
DRA_VERSION=9.2.0
DRA_WORKFLOW="snapshot"

@pchila
Copy link
Member

pchila commented Jul 29, 2025

both of them succeeded at the build steps, but failed at the publishing step, even though I set them to dry-run. Not sure if that's in some way an effect of this change or if I made a mistake.

You would need to define DRA_BRANCH="main" (or another release branch) and DRA_DRY_RUN="--dry-run" like in this build https://buildkite.com/elastic/elastic-agent-package/builds/7181

Just be careful because without the appropriate DRA_DRY_RUN value you will end up overwriting DRAs built from the release branches with one from your PR

@swiatekm swiatekm requested a review from v1v July 29, 2025 17:32
Copy link
Member

@v1v v1v left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I've just left a comment; however, I'm not an expert in the build system. Please take my +1 as only an acknowledgment.

v1v
v1v previously approved these changes Jul 29, 2025
Copy link
Member

@v1v v1v left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I've just left a comment; however, I'm not an expert in the build system. Please take my +1 as only an acknowledgment.

@pierrehilbert pierrehilbert added the Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team label Aug 5, 2025
@elasticmachine
Copy link
Collaborator

Pinging @elastic/elastic-agent-control-plane (Team:Elastic-Agent-Control-Plane)

@swiatekm swiatekm force-pushed the chore/crossbuild-build-cache branch from b17602c to 61582a5 Compare August 25, 2025 14:35
@swiatekm swiatekm force-pushed the chore/crossbuild-build-cache branch from 55db0ea to 3374450 Compare September 10, 2025 15:41
@elastic-sonarqube
Copy link

Quality Gate passed Quality Gate passed

Issues
0 New issues
0 Fixed issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarQube

@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

History

cc @swiatekm

@swiatekm
Copy link
Contributor Author

Looks like the cache is around 5 GB per platform, which is a fair amount.

Copy link
Contributor

@pkoutsovasilis pkoutsovasilis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thx for addressing my comments

@swiatekm
Copy link
Contributor Author

I tested the dra publishing pipelines again and didn't see any issues, merging.

@swiatekm swiatekm merged commit fd4de6b into main Sep 15, 2025
23 checks passed
@swiatekm swiatekm deleted the chore/crossbuild-build-cache branch September 15, 2025 13:46
@github-actions
Copy link
Contributor

@Mergifyio backport 8.18 8.19 9.0 9.1

@mergify
Copy link
Contributor

mergify bot commented Sep 15, 2025

backport 8.18 8.19 9.0 9.1

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Sep 15, 2025
* Mount Go build cache into crossbuild container

* Run crossbuild container as host user

* Update dev-tools/mage/crossbuild.go

Co-authored-by: Victor Martinez <victormartinezrubio@gmail.com>

* Fix formatting

* Control mounting mod cache with env variable

* Control mounting build cache with env variable

* Use a volume for Go build cache

---------

Co-authored-by: Victor Martinez <victormartinezrubio@gmail.com>
(cherry picked from commit fd4de6b)
mergify bot pushed a commit that referenced this pull request Sep 15, 2025
* Mount Go build cache into crossbuild container

* Run crossbuild container as host user

* Update dev-tools/mage/crossbuild.go

Co-authored-by: Victor Martinez <victormartinezrubio@gmail.com>

* Fix formatting

* Control mounting mod cache with env variable

* Control mounting build cache with env variable

* Use a volume for Go build cache

---------

Co-authored-by: Victor Martinez <victormartinezrubio@gmail.com>
(cherry picked from commit fd4de6b)
mergify bot pushed a commit that referenced this pull request Sep 15, 2025
* Mount Go build cache into crossbuild container

* Run crossbuild container as host user

* Update dev-tools/mage/crossbuild.go

Co-authored-by: Victor Martinez <victormartinezrubio@gmail.com>

* Fix formatting

* Control mounting mod cache with env variable

* Control mounting build cache with env variable

* Use a volume for Go build cache

---------

Co-authored-by: Victor Martinez <victormartinezrubio@gmail.com>
(cherry picked from commit fd4de6b)
mergify bot pushed a commit that referenced this pull request Sep 15, 2025
* Mount Go build cache into crossbuild container

* Run crossbuild container as host user

* Update dev-tools/mage/crossbuild.go

Co-authored-by: Victor Martinez <victormartinezrubio@gmail.com>

* Fix formatting

* Control mounting mod cache with env variable

* Control mounting build cache with env variable

* Use a volume for Go build cache

---------

Co-authored-by: Victor Martinez <victormartinezrubio@gmail.com>
(cherry picked from commit fd4de6b)
swiatekm added a commit that referenced this pull request Sep 15, 2025
* Mount Go build cache into crossbuild container

* Run crossbuild container as host user

* Update dev-tools/mage/crossbuild.go



* Fix formatting

* Control mounting mod cache with env variable

* Control mounting build cache with env variable

* Use a volume for Go build cache

---------


(cherry picked from commit fd4de6b)

Co-authored-by: Mikołaj Świątek <mail@mikolajswiatek.com>
Co-authored-by: Victor Martinez <victormartinezrubio@gmail.com>
swiatekm added a commit that referenced this pull request Sep 15, 2025
* Mount Go build cache into crossbuild container

* Run crossbuild container as host user

* Update dev-tools/mage/crossbuild.go



* Fix formatting

* Control mounting mod cache with env variable

* Control mounting build cache with env variable

* Use a volume for Go build cache

---------


(cherry picked from commit fd4de6b)

Co-authored-by: Mikołaj Świątek <mail@mikolajswiatek.com>
Co-authored-by: Victor Martinez <victormartinezrubio@gmail.com>
swiatekm added a commit that referenced this pull request Sep 15, 2025
* Mount Go build cache into crossbuild container

* Run crossbuild container as host user

* Update dev-tools/mage/crossbuild.go



* Fix formatting

* Control mounting mod cache with env variable

* Control mounting build cache with env variable

* Use a volume for Go build cache

---------


(cherry picked from commit fd4de6b)

Co-authored-by: Mikołaj Świątek <mail@mikolajswiatek.com>
Co-authored-by: Victor Martinez <victormartinezrubio@gmail.com>
swiatekm added a commit that referenced this pull request Sep 15, 2025
* Mount Go build cache into crossbuild container

* Run crossbuild container as host user

* Update dev-tools/mage/crossbuild.go



* Fix formatting

* Control mounting mod cache with env variable

* Control mounting build cache with env variable

* Use a volume for Go build cache

---------


(cherry picked from commit fd4de6b)

Co-authored-by: Mikołaj Świątek <mail@mikolajswiatek.com>
Co-authored-by: Victor Martinez <victormartinezrubio@gmail.com>
v1v added a commit that referenced this pull request Sep 16, 2025
* upstream: (26 commits)
  fix: ensure EDOT subprocess shuts down gracefully on agent termination (#9886)
  [main][Automation] Update versions (#9976)
  Add Collector reference docs and automation (#9953)
  [beatreceivers] Integrate beatsauthextension (#9257)
  [main][Automation] Update versions (#9941)
  Update OTel components to v0.132.0/v1.38.0 (#9954)
  Enhancement/5235 wrap errors when marking upgrade (#9366)
  Mount Go build cache into crossbuild container (#9094)
  Liveness agent state (#9673)
  [main][Automation] Bump VM Image version to 1757725254 (#9942)
  Enhancement/5235 correctly wrap errors from copyActionDir and copyRunDirectory (#9349)
  [main][Automation] Update elastic/beats to afc53c0479ac (#9874)
  Add -coverpkg option when running unit test to calculate coverage across packages (#9913)
  Cache binaries downloaded for packaging locally (#9133)
  [main][Automation] Update versions (#9897)
  Disable flaky test TestBeatsReceiverLogs (#9891)
  Allow overriding AGENT_PACKAGE_VERSION and MANIFEST_URL when USE_PACKAGE_VERSION=true (#9864)
  add ingest-docs team as CODEOWNERS for release notes and docset.yml (#9865)
  fix: correct spelling of 'output' in various templates and monitoring code (#9827)
  k8s: Add comment around hostUsers for Universal Profiling deployments (#9847)
  ...
intxgo pushed a commit to intxgo/elastic-agent that referenced this pull request Sep 24, 2025
* Mount Go build cache into crossbuild container

* Run crossbuild container as host user

* Update dev-tools/mage/crossbuild.go

Co-authored-by: Victor Martinez <victormartinezrubio@gmail.com>

* Fix formatting

* Control mounting mod cache with env variable

* Control mounting build cache with env variable

* Use a volume for Go build cache

---------

Co-authored-by: Victor Martinez <victormartinezrubio@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-active-all Automated backport with mergify to all the active branches chore Tasks that just need to be done, they are neither bug, nor enhancements skip-changelog Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants