Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mage: optionally mount module cache for crossbuild #16837

Merged
merged 5 commits into from
Mar 6, 2020

Conversation

axw
Copy link
Member

@axw axw commented Mar 5, 2020

What does this PR do?

Introduce another mage variable, CrossBuildMountModcache,
which defaults to false. When set to true, the host's
module cache ($GOPATH/pkg/mod) will be mounted into the
crossbuild Docker containers, read-only. To ensure the
cache is up-to-date, we run go mod download on the host
before starting the Docker containers.

Also, fix mage buildGoDaemon to stop assuming that
tsg/go-daemon is vendored. Instead, use
go list -m github.com/tsg/go-daemon to find the module
directory in either the vendor directory or the module cache.

Why is it important?

This is necessary to support beats that do not use vendoring, such as apm-server.

Checklist

  • 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

How to test this PR locally

cd filebeat && PLATFORMS=linux/amd64 mage package

Introduce another mage variable, CrossBuildMountModcache,
which defaults to false. When set to true, the host's
module cache ($GOPATH/pkg/mod) will be mounted into the
crossbuild Docker containers, read-only. To ensure the
cache is up-to-date, we run "go mod download" on the host
before starting the Docker containers.

Also, fix buildGoDaemon to stop assuming that tsg/go-daemon
is vendored. Instead, use "go list -m github.com/tsg/go-daemon"
to find the directory in either the vendor directory or
the module cache.
@axw axw force-pushed the mage-crossbuild-modcache branch from 9a07d2e to 3b388ee Compare March 6, 2020 01:58
gotool.ListModulePath wipes out the GOFLAGS
environment variable, to force looking in the
module cache unless otherwise specified.

This breaks findElasticBeatsDir for community
beats that vendor libbeat. In this case, we
should explicitly pass "-mod=vendor" when
UseVendor is true.
@axw axw mentioned this pull request Mar 6, 2020
4 tasks
Copy link
Contributor

@kvch kvch left a comment

Choose a reason for hiding this comment

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

After the changes, it is ready to go.

Rather than having arguments for ListModulePath,
create separate functions for listing in the module
cache and vendor directory. Create an unexported
function in dev-tools/mage which calls the appropriate
one depending on the value of UseVendor.
@axw axw force-pushed the mage-crossbuild-modcache branch from 46cc306 to 95f21ec Compare March 6, 2020 10:01
Inline defaultConfigFileParams, otherwise the OSSBeatDir
and LibbeatDir calls end up calling ElasticBeatsDir at
package init time, before apm-server uas an opportunity
to set UseVendor=false.
- Fix ordering of -mod=vendor arg
- Cache beats dir for beatgen, before creating the new module
@axw axw added the needs_backport PR is waiting to be backported to other branches. label Mar 6, 2020
@axw axw merged commit bbf9d66 into elastic:master Mar 6, 2020
@axw axw deleted the mage-crossbuild-modcache branch March 6, 2020 12:41
axw added a commit to axw/beats that referenced this pull request Mar 11, 2020
* mage: optionally mount module cache for crossbuild

Introduce another mage variable, CrossBuildMountModcache,
which defaults to false. When set to true, the host's
module cache ($GOPATH/pkg/mod) will be mounted into the
crossbuild Docker containers, read-only. To ensure the
cache is up-to-date, we run "go mod download" on the host
before starting the Docker containers.

Also, fix buildGoDaemon to stop assuming that tsg/go-daemon
is vendored. Instead, use "go list -m github.com/tsg/go-daemon"
to find the directory in either the vendor directory or
the module cache.

Rather than having arguments for ListModulePath, create separate
functions for listing in the module cache and vendor directory. Create
an unexported function in dev-tools/mage which calls the appropriate
one depending on the value of UseVendor. We now use this in
"findElasticBeatsDir".

Inline defaultConfigFileParams, otherwise the OSSBeatDir and
LibbeatDir calls end up calling ElasticBeatsDir at package init time,
before apm-server uas an opportunity to set UseVendor=false.

(cherry picked from commit bbf9d66)
@axw axw added v7.7.0 and removed needs_backport PR is waiting to be backported to other branches. labels Mar 11, 2020
axw added a commit that referenced this pull request Mar 12, 2020
* mage: optionally mount module cache for crossbuild

Introduce another mage variable, CrossBuildMountModcache,
which defaults to false. When set to true, the host's
module cache ($GOPATH/pkg/mod) will be mounted into the
crossbuild Docker containers, read-only. To ensure the
cache is up-to-date, we run "go mod download" on the host
before starting the Docker containers.

Also, fix buildGoDaemon to stop assuming that tsg/go-daemon
is vendored. Instead, use "go list -m github.com/tsg/go-daemon"
to find the directory in either the vendor directory or
the module cache.

Rather than having arguments for ListModulePath, create separate
functions for listing in the module cache and vendor directory. Create
an unexported function in dev-tools/mage which calls the appropriate
one depending on the value of UseVendor. We now use this in
"findElasticBeatsDir".

Inline defaultConfigFileParams, otherwise the OSSBeatDir and
LibbeatDir calls end up calling ElasticBeatsDir at package init time,
before apm-server uas an opportunity to set UseVendor=false.

(cherry picked from commit bbf9d66)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants