-
Notifications
You must be signed in to change notification settings - Fork 288
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
Add option to use native binaries in dep factory #2683
Add option to use native binaries in dep factory #2683
Conversation
d616d12
to
b885139
Compare
Codecov Report
@@ Coverage Diff @@
## main #2683 +/- ##
==========================================
+ Coverage 57.87% 58.35% +0.48%
==========================================
Files 311 312 +1
Lines 25561 25594 +33
==========================================
+ Hits 14793 14935 +142
+ Misses 9452 9341 -111
- Partials 1316 1318 +2
Continue to review full report at Codecov.
|
b885139
to
1ea2fb0
Compare
2d8a4d6
to
32f1a58
Compare
Until now, the executable builder always decided if docker needed to be used or not, based on an env var. This made the constructor take all the arguments, even when some of them aren't needed. Moreover, in order to build local native executables programmatically through the factory, we needed to set an env var and force the use of a "fake" tools image. Now the factory has an specific option to use docker or not. If it's not set, it will default to the value of the env var, keeping current behavior. But it allows to override it.
32f1a58
to
6b0ad30
Compare
pkg/dependencies/factory.go
Outdated
// UserExecutablesDockerClient forces a specific DockerClient to build | ||
// Executables as opposed to follow the normal building flow | ||
// This is only for testing | ||
func (f *Factory) UserExecutablesDockerClient(client executables.DockerClient) *Factory { |
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.
Is it supposed to be this?
func (f *Factory) UserExecutablesDockerClient(client executables.DockerClient) *Factory { | |
func (f *Factory) UseExecutablesDockerClient(client executables.DockerClient) *Factory { |
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 only used for testing, it might be clearer to mention in the method name that it is for Testing. But I would understand not doing that if we want to extend it to be able to pass it in other situations
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.
Fixed typo
As for adding Testing
to the method, unless you feel strongly about this, I prefer to keep it just in the description doc. In general, I think method names should indicate what they do, not what they are used for.
pkg/dependencies/factory.go
Outdated
executablesImage string | ||
executablesInDocker bool |
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 we have a WithDocker
, why not call this something like containerExecutables
, and then if we have WithPodman
in the future, it would use the same logic here? Just want to see if that is possible vs calling everything executableInDocker
or InitInDocker
or something, but I understand that it would be more refactoring and something we can pick up later when we actually support the different ones.
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.
containerExecutables
seems a bit ambiguous. If you prefer executablesInContainer
, I'm ok with that.
However, as you are saying, if we want to support more container runtimes/clients, there would more stuff we would need to change.
Co-authored-by: Joey Wang <jiayiwang7@yahoo.com>
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: g-gaston The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
* Add option to use native binaries in dep factory Until now, the executable builder always decided if docker needed to be used or not, based on an env var. This made the constructor take all the arguments, even when some of them aren't needed. Moreover, in order to build local native executables programmatically through the factory, we needed to set an env var and force the use of a "fake" tools image. Now the factory has an specific option to use docker or not. If it's not set, it will default to the value of the env var, keeping current behavior. But it allows to override it. * Fix typo in factory method name * Fixed typo in doc comment Co-authored-by: Joey Wang <jiayiwang7@yahoo.com> * Fixed typo in doc comment * Nest executables fields in factory * Remove unnecessary tests Co-authored-by: Joey Wang <jiayiwang7@yahoo.com>
Description of changes
Until now, the executable builder always decided if docker needed to be used or not, based on an env var. This made the constructor take all the arguments, even when some of them aren't needed. Moreover, in order to build local native executables programmatically through the factory, we needed to set an env var and force the use of a "fake" tools image.
Now the factory has an specific option to use docker or not. If it's not set, it will default to the value of the env var, keeping current behavior. But it allows to override it.
The executables builder has changed quite a bit. Now we have two constructors for it, one for the docker implementation and another one for the local binaries one. The deps factory decided which one to call.
I also separated the builder construction from the container initialization. I added a helper that does both together in order to keep the refactor of all usages at a minimum.
You'll see a lot of tests (and some changes) that seem unrelated to this feature. They are. The code was difficult to test and was missing a lot of tests, so I had to change some things around in order to be able to test. It's not perfect but I think it's better than what we had. If we want to make it good, we probably need a bigger more focused refactor, most probably splitting this package and moving things around.
Testing (if applicable)
Unit tests
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.