Add local/remote builder combo for multiarch
This commit is contained in:
@@ -5,6 +5,10 @@ class Mrsk::Commands::Builder < Mrsk::Commands::Base
|
||||
docker :buildx, :create, "--use", "--name", "mrsk"
|
||||
end
|
||||
|
||||
def remove
|
||||
docker :buildx, :rm, "mrsk"
|
||||
end
|
||||
|
||||
def push
|
||||
docker :buildx, :build, "--push", "--platform linux/amd64,linux/arm64", "-t", config.absolute_image, "."
|
||||
end
|
||||
@@ -12,4 +16,22 @@ class Mrsk::Commands::Builder < Mrsk::Commands::Base
|
||||
def pull
|
||||
docker :pull, config.absolute_image
|
||||
end
|
||||
|
||||
|
||||
def create_context(arch, host)
|
||||
docker :context, :create, "mrsk-#{arch}", "--description", "'MRSK #{arch} Native Host'", "--docker", "'host=#{host}'"
|
||||
end
|
||||
|
||||
def remove_context(arch)
|
||||
docker :context, :rm, "mrsk-#{arch}"
|
||||
end
|
||||
|
||||
|
||||
def create_with_context(arch)
|
||||
docker :buildx, :create, "--use", "--name", "mrsk", "mrsk-#{arch}"
|
||||
end
|
||||
|
||||
def append_context(arch)
|
||||
docker :buildx, :create, "--append", "--name", "mrsk", "mrsk-#{arch}"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,7 +3,7 @@ require "active_support/core_ext/string/inquiry"
|
||||
require "erb"
|
||||
|
||||
class Mrsk::Configuration
|
||||
delegate :service, :image, :servers, :env, :labels, :registry, to: :config, allow_nil: true
|
||||
delegate :service, :image, :servers, :env, :labels, :registry, :builder, to: :config, allow_nil: true
|
||||
|
||||
class << self
|
||||
def load_file(file)
|
||||
|
||||
@@ -23,5 +23,71 @@ namespace :mrsk do
|
||||
task :pull do
|
||||
on(MRSK.config.hosts) { execute *MRSK.builder.pull }
|
||||
end
|
||||
|
||||
desc "Create a local buildx setup to produce multi-arch images"
|
||||
task :create do
|
||||
run_locally do
|
||||
execute *MRSK.builder.create
|
||||
end
|
||||
end
|
||||
|
||||
desc "Remove local buildx setup"
|
||||
task :remove do
|
||||
run_locally do
|
||||
execute *MRSK.builder.remove
|
||||
end
|
||||
end
|
||||
|
||||
namespace :remote do
|
||||
desc "Create local and remote buildx setup for fully native multi-arch builds"
|
||||
task create: %w[ create:context create:buildx ]
|
||||
|
||||
namespace :create do
|
||||
task :context do
|
||||
if MRSK.config.builder &&
|
||||
(local = MRSK.config.builder["local"]) &&
|
||||
(remote = MRSK.config.builder["remote"])
|
||||
run_locally do
|
||||
execute *MRSK.builder.create_context(local["arch"], local["host"])
|
||||
execute *MRSK.builder.create_context(remote["arch"], remote["host"])
|
||||
end
|
||||
else
|
||||
error "Missing configuration of builder:local/remote in config"
|
||||
end
|
||||
end
|
||||
|
||||
task :buildx do
|
||||
if MRSK.config.builder &&
|
||||
(local = MRSK.config.builder["local"]) &&
|
||||
(remote = MRSK.config.builder["remote"])
|
||||
run_locally do
|
||||
execute *MRSK.builder.create_with_context(local["arch"])
|
||||
execute *MRSK.builder.append_context(remote["arch"])
|
||||
end
|
||||
else
|
||||
error "Missing configuration of builder:local/remote in config"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
desc "Remove local and remote buildx setup"
|
||||
task remove: %w[ remove:context mrsk:build:remove ]
|
||||
|
||||
namespace :remove do
|
||||
task :context do
|
||||
if MRSK.config.builder &&
|
||||
(local = MRSK.config.builder["local"]) &&
|
||||
(remote = MRSK.config.builder["remote"])
|
||||
run_locally do
|
||||
execute *MRSK.builder.remove_context(local["arch"])
|
||||
execute *MRSK.builder.remove_context(remote["arch"])
|
||||
end
|
||||
else
|
||||
error "Missing configuration of builder:local/remote in config"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user