diff --git a/lib/mrsk/commands/builder/multiarch/remote.rb b/lib/mrsk/commands/builder/multiarch/remote.rb index 125e11bd..fd919d87 100644 --- a/lib/mrsk/commands/builder/multiarch/remote.rb +++ b/lib/mrsk/commands/builder/multiarch/remote.rb @@ -1,19 +1,53 @@ require "mrsk/commands/builder/multiarch" class Mrsk::Commands::Builder::Multiarch::Remote < Mrsk::Commands::Builder::Multiarch - def create(arch) - super + [ "mrsk-#{arch}", "--platform", "linux/#{arch}" ] + def create + combine \ + create_contexts, + create_local_buildx, + append_remote_buildx end - def append(arch) - docker :buildx, :create, "--append", "--name", "mrsk", "mrsk-#{arch}", "--platform", "linux/#{arch}" + def remove + combine \ + remove_contexts, + super end - def create_context(arch, host) - docker :context, :create, "mrsk-#{arch}", "--description", "'MRSK #{arch} Native Host'", "--docker", "'host=#{host}'" - end + private + def create_local_buildx + docker :buildx, :create, "--use", "--name", "mrsk", "mrsk-#{local["arch"]}", "--platform", "linux/#{local["arch"]}" + end - def remove_context(arch) - docker :context, :rm, "mrsk-#{arch}" - end + def append_remote_buildx + docker :buildx, :create, "--append", "--name", "mrsk", "mrsk-#{remote["arch"]}", "--platform", "linux/#{remote["arch"]}" + end + + def create_contexts + combine \ + create_context(local["arch"], local["host"]), + create_context(remote["arch"], remote["host"]) + end + + def create_context(arch, host) + docker :context, :create, "mrsk-#{arch}", "--description", "'MRSK #{arch} Native Host'", "--docker", "'host=#{host}'" + end + + def remove_contexts + combine \ + remove_context(local["arch"]), + remove_context(remote["arch"]) + end + + def remove_context(arch) + docker :context, :rm, "mrsk-#{arch}" + end + + def local + config.builder["local"] + end + + def remote + config.builder["remote"] + end end diff --git a/lib/tasks/mrsk/build.rake b/lib/tasks/mrsk/build.rake index c19c7b48..286f18d1 100644 --- a/lib/tasks/mrsk/build.rake +++ b/lib/tasks/mrsk/build.rake @@ -9,11 +9,12 @@ namespace :mrsk do task :push do run_locally do begin - info "Building images may take a while [#{MRSK.builder.name}] (run with VERBOSE=1 for progress logging)" + debug "Using builder: #{MRSK.builder.name}" + info "Building images may take a while (run with VERBOSE=1 for progress logging)" execute *MRSK.builder.push rescue SSHKit::Command::Failed => e error "Missing compatible builder, so creating a new one first" - Rake::Task["mrsk:build:create"].invoke + execute *MRSK.builder.create execute *MRSK.builder.push end end unless ENV["VERSION"] @@ -27,56 +28,16 @@ namespace :mrsk do desc "Create a local build setup" task :create do run_locally do - if MRSK.builder.remote? - Rake::Task["mrsk:build:remote:create"].invoke - else - execute *MRSK.builder.create - end + debug "Using builder: #{MRSK.builder.name}" + execute *MRSK.builder.create end end desc "Remove local build setup" task :remove do run_locally do - if MRSK.builder.remote? - Rake::Task["mrsk:build:remote:create"].invoke - else - execute *MRSK.builder.remove - end - 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 - run_locally do - execute *MRSK.builder.create_context(local["arch"], local["host"]) - execute *MRSK.builder.create_context(remote["arch"], remote["host"]) - end - end - - task :buildx do - run_locally do - execute *MRSK.builder.create_with_context(local["arch"]) - execute *MRSK.builder.append_context(remote["arch"]) - end - end - end - - - desc "Remove local and remote buildx setup" - task remove: %w[ remove:context mrsk:build:remove ] - - namespace :remove do - task :context do - run_locally do - execute *MRSK.builder.remove_context(local["arch"]) - execute *MRSK.builder.remove_context(remote["arch"]) - end - end + debug "Using builder: #{MRSK.builder.name}" + execute *MRSK.builder.remove end end end