-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
[Elastic Logging Plugin] Refactor of build tooling for docker plugin #15441
[Elastic Logging Plugin] Refactor of build tooling for docker plugin #15441
Conversation
Still fighting with dependencies. |
jenkins, test this |
We already have docker + k8s dependencies. What do the new dependencies add we are missing so far? We made an effort allowing Beats to be build and run on environments that do not have docker support altogether (e.g. AIX or BSD). Problem with docker as dependency is that it doesn't even build on some alternative platforms. Given the urgency of this change I'm fine with fixing this later on if it is indeed an issue. I think it's more an issue when calling top-level |
return errors.Wrap(err, "Error locating temp dir") | ||
} | ||
tarPath := filepath.Join(tmpDir, "tarRoot.tar") | ||
err = sh.RunV("tar", "cf", tarPath, "./") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We switch to the Beats root directory for this tar
command?
Btw. stdlib also has the archive/tar package.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yah, we send the entire beats directory to the docker context to actually build the plugin, since we depend on libbeat and so on. Eventually I really want to find a faster way to do this. Maybe just copy over libbeat
to vendor during the build or something? We honestly might not even need to do this step inside docker at all, and just copy a finished binary to our "2nd stage" container. I don't know enough about our release process to tell.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we reuse devtools.CrossBuild
to build the beat binary as we do in other beats?
If tarring files here is really needed, I would try to avoid using Chdir
, this can have undesired effects when running targets in parallel (Chdir
changes the dir for the whole process), or if this code is moved somewhere at some moment.
You can try to use the -C
flag of tar
, or use archive/tar
as suggested.
We were missing the
Really? I was under the impression that the release process required docker. I mean, technically you can run |
@fearful-symmetry our first release is failing because of the structure of the tarball (https://github.com/elastic/infra/issues/16748#issuecomment-573046527). |
Right. Forget what I said. We use the docker images to crossbuild for the target platform. The docker client libs do not always correctly crossbuild. But the plugin implements |
Yah, that doesn't surprise me. This plugin is a bit weird in the sense that we have no concept of a cross-compile, since a docker plugin at a platform-independent container, although at a low-level it's a linux-only artifact. |
@jmlrt Alright, latest commit should fix your issue. Do you have a way of testing? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM since it fixes the RM issues.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is blocking other things I am ok with merging it, but I think that some things would need to be polished.
Most notably, we're no longer shelling out docker commands, and are now using the docker client API. This gives us more control over what docker is doing, and will make it easier to improve this process later on. This also cleans up the build process, and removes some code smell issues.
In dockerbuild.go
we are using the docker commands and it hasn't been so problematic so far, but we could consider using the API also there if it works well here.
I am not sure though if for example docker build
is cleaner to do with the API.
return errors.Errorf("not in dockerlogbeat directory: %s", dockerLogBeatDir) | ||
} | ||
|
||
// change back to the root beats dir so we can send the proper build context to docker | ||
err = os.Chdir("../..") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we use devtools.XPackBeatDir
here? and then we wouldn't need to check that we are in the expected directory.
err = os.Chdir("../..") | |
err = os.Chdir(devtools.XPackBeatDir()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried this, for for whatever reason, it kept on trying to navigate to x-pack/x-pack
so...I gave up.
return errors.Wrap(err, "Error locating temp dir") | ||
} | ||
tarPath := filepath.Join(tmpDir, "tarRoot.tar") | ||
err = sh.RunV("tar", "cf", tarPath, "./") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we reuse devtools.CrossBuild
to build the beat binary as we do in other beats?
If tarring files here is really needed, I would try to avoid using Chdir
, this can have undesired effects when running targets in parallel (Chdir
changes the dir for the whole process), or if this code is moved somewhere at some moment.
You can try to use the -C
flag of tar
, or use archive/tar
as suggested.
x-pack/dockerlogbeat/magefile.go
Outdated
} | ||
|
||
//check to see if we have a plugin we need to remove | ||
plugins, err := cli.PluginList(context.Background(), filters.Args{}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we directly use PluginInspect
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the last hour changes. Let's get this merged as is blocking other things, and please follow up with the other issues in other PRs.
…lastic#15441) * refactor of build tooling for docker plugin (cherry picked from commit b19bdf4)
This is an extensive refactor of the build scripts for the docker plugin. The infra folks were running into a lot of issues, and I'm hoping this addresses most of them.
Most notably, we're no longer shelling out docker commands, and are now using the docker client API. This gives us more control over what docker is doing, and will make it easier to improve this process later on. This also cleans up the build process, and removes some code smell issues.
There's no doubt a bunch of improvements we can still make here, but considering how close we are to 7.6, I want to make sure this just works and barring any low-hanging fruit, we can do optimizations later.
@kvch I requested you since we added a new docker dep, and I want to make sure I did it right.