-
Notifications
You must be signed in to change notification settings - Fork 465
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
Support for Docker multistage build cache #337
Conversation
lib/mrsk/commands/builder/native.rb
Outdated
docker(:build, *build_options, build_context), | ||
docker(:push, config.absolute_image), | ||
docker(:push, config.latest_image) | ||
end | ||
end |
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.
Instead of doing conditionals on all of these, I think maybe we should have Mrsk::Commands::Builder::Native::Cached
?
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.
Good point!
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.
Done, added Mrsk::Commands::Builder::Native::Cached
builder.
lib/mrsk/configuration/builder.rb
Outdated
[ | ||
"type=gha", | ||
@options["cache"]&.fetch("options", nil), | ||
].compact.join(",") |
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.
Extract this as cache_config_for_gha
or similar.
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.
Done.
lib/mrsk/configuration/builder.rb
Outdated
"type=registry", | ||
@options["cache"]&.fetch("options", nil), | ||
"ref=#{@server}/#{cache_image}" | ||
].compact.join(",") |
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.
Extract this as cache_config_for_registry
or similar.
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.
Done.
remove_context(local["arch"]), | ||
remove_context(remote["arch"]) | ||
remove_context(config.builder.local_arch), | ||
remove_context(config.builder.remote_arch) |
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.
Maybe setup a delegate_to
for config.builder for remote/local_arch|host.
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.
Added delegation of all used public methods from Mrsk::Configuration::Builder
to builder_config
. Lines became shorter, readability improved.
Nice use of the extracted builder config object 👍 |
David, thanks for your comments. Will take a look later today. |
lib/mrsk/configuration/builder.rb
Outdated
case @options["cache"]["type"] | ||
when 'gha' | ||
"type=gha" | ||
when 'registry' |
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.
Consistently use " not '
lib/mrsk/configuration/builder.rb
Outdated
if cached? | ||
case @options["cache"]["type"] | ||
when 'gha' | ||
"type=gha" |
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.
Use cache_from_config_for_gha
to remain at the same level of abstraction.
lib/mrsk/configuration/builder.rb
Outdated
[ | ||
"type=registry", | ||
"ref=#{@server}/#{cache_image}" | ||
].compact.join(",") |
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.
Turn into single line.
lib/mrsk/configuration/builder.rb
Outdated
[ | ||
"type=gha", | ||
@options["cache"]&.fetch("options", nil), | ||
].compact.join(",") |
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.
Turn into single line.
lib/mrsk/configuration/builder.rb
Outdated
"type=registry", | ||
@options["cache"]&.fetch("options", nil), | ||
"ref=#{@server}/#{cache_image}" | ||
].compact.join(",") |
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.
Turn into single line.
*build_options, | ||
build_context | ||
end | ||
end |
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.
Add CR
Just a few more minor points. Looking good! |
Fixed all code style comments. This is why I proposed Rubocop :) |
This PR implements support for Docker build cache and closes #329.
Currently I added support for two cache types: gha and registry. Both cache types allow to specified additional options that will be used in
cache-to
param. Registry cache also allows to specify image to be used for cache, by default application image is used with-build-cache
suffix.I've tested this on Rails 7 application. Both gha and registry cache works and saves about 40% of build time.