Files
kamal/lib/mrsk/commands/builder/multiarch/remote.rb
2023-06-18 19:02:10 +04:00

52 lines
1.4 KiB
Ruby

class Mrsk::Commands::Builder::Multiarch::Remote < Mrsk::Commands::Builder::Multiarch
def create
combine \
create_contexts,
create_local_buildx,
append_remote_buildx
end
def remove
combine \
remove_contexts,
super
end
private
def builder_name
super + "-remote"
end
def builder_name_with_arch(arch)
"#{builder_name}-#{arch}"
end
def create_local_buildx
docker :buildx, :create, "--name", builder_name, builder_name_with_arch(config.builder.local_arch), "--platform", "linux/#{config.builder.local_arch}"
end
def append_remote_buildx
docker :buildx, :create, "--append", "--name", builder_name, builder_name_with_arch(config.builder.remote_arch), "--platform", "linux/#{config.builder.remote_arch}"
end
def create_contexts
combine \
create_context(config.builder.local_arch, config.builder.local_host),
create_context(config.builder.remote_arch, config.builder.remote_host)
end
def create_context(arch, host)
docker :context, :create, builder_name_with_arch(arch), "--description", "'#{builder_name} #{arch} native host'", "--docker", "'host=#{host}'"
end
def remove_contexts
combine \
remove_context(config.builder.local_arch),
remove_context(config.builder.remote_arch)
end
def remove_context(arch)
docker :context, :rm, builder_name_with_arch(arch)
end
end