Inroduce Native::Cached builder

This commit is contained in:
Igor Alexandrov
2023-06-18 22:45:04 +04:00
parent 4df3389d09
commit aa28ee0f3e
4 changed files with 41 additions and 26 deletions

View File

@@ -7,8 +7,10 @@ class Mrsk::Commands::Builder < Mrsk::Commands::Base
def target
case
when !config.builder.multiarch?
when !config.builder.multiarch? && !config.builder.cache?
native
when !config.builder.multiarch? && config.builder.cache?
native_cached
when config.builder.local? && config.builder.remote?
multiarch_remote
when config.builder.remote?
@@ -22,6 +24,10 @@ class Mrsk::Commands::Builder < Mrsk::Commands::Base
@native ||= Mrsk::Commands::Builder::Native.new(config)
end
def native_cached
@native ||= Mrsk::Commands::Builder::Native::Cached.new(config)
end
def native_remote
@native ||= Mrsk::Commands::Builder::Native::Remote.new(config)
end

View File

@@ -1,32 +1,17 @@
class Mrsk::Commands::Builder::Native < Mrsk::Commands::Builder::Base
def create
# No-op on native without cache
if config.builder.cache?
docker :buildx, :create, "--use", "--driver=docker-container"
end
end
def remove
# No-op on native without cache
if config.builder.cache?
docker :buildx, :rm, builder_name
end
end
def push
if config.builder.cache?
docker :buildx, :build,
"--push",
*build_options,
build_context
else
combine \
docker(:build, *build_options, build_context),
docker(:push, config.absolute_image),
docker(:push, config.latest_image)
end
combine \
docker(:build, *build_options, build_context),
docker(:push, config.absolute_image),
docker(:push, config.latest_image)
end
def info

View File

@@ -0,0 +1,16 @@
class Mrsk::Commands::Builder::Native::Cached < Mrsk::Commands::Builder::Native
def create
docker :buildx, :create, "--use", "--driver=docker-container"
end
def remove
docker :buildx, :rm, builder_name
end
def push
docker :buildx, :build,
"--push",
*build_options,
build_context
end
end