Add file mapping to accessories
This commit is contained in:
@@ -3,10 +3,27 @@ require "mrsk/cli/base"
|
||||
class Mrsk::Cli::Accessory < Mrsk::Cli::Base
|
||||
desc "boot [NAME]", "Boot accessory service on host"
|
||||
def boot(name)
|
||||
invoke :upload, [ name ]
|
||||
|
||||
accessory = MRSK.accessory(name)
|
||||
on(accessory.host) { execute *accessory.run }
|
||||
end
|
||||
|
||||
desc "upload [NAME]", "Upload accessory files to host"
|
||||
def upload(name)
|
||||
accessory = MRSK.accessory(name)
|
||||
on(accessory.host) do
|
||||
accessory.files.each do |(local, remote)|
|
||||
if Pathname.new(local).exist?
|
||||
execute :mkdir, "-p", Pathname.new(remote).dirname.to_s
|
||||
upload! local.to_s, remote.to_s
|
||||
else
|
||||
raise "Missing file: #{local}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
desc "reboot [NAME]", "Reboot accessory on host (stop container, remove container, start new container)"
|
||||
def reboot(name)
|
||||
invoke :stop, [ name ]
|
||||
|
||||
@@ -2,7 +2,7 @@ require "mrsk/commands/base"
|
||||
|
||||
class Mrsk::Commands::Accessory < Mrsk::Commands::Base
|
||||
attr_reader :accessory_config
|
||||
delegate :service_name, :image, :host, :port, :env_args, :volume_args, :label_args, to: :accessory_config
|
||||
delegate :service_name, :image, :host, :port, :files, :env_args, :volume_args, :label_args, to: :accessory_config
|
||||
|
||||
def initialize(config, name:)
|
||||
super(config)
|
||||
|
||||
@@ -43,8 +43,15 @@ class Mrsk::Configuration::Assessory
|
||||
argumentize_env_with_secrets env
|
||||
end
|
||||
|
||||
def files
|
||||
specifics["files"]&.to_h do |local_to_remote_mapping|
|
||||
local_file, remote_file = local_to_remote_mapping.split(":")
|
||||
[ expand_local_file_path(local_file), expand_remote_file_path(remote_file) ]
|
||||
end || {}
|
||||
end
|
||||
|
||||
def volumes
|
||||
specifics["volumes"] || []
|
||||
(specifics["volumes"] || []) + remote_files_as_volumes
|
||||
end
|
||||
|
||||
def volume_args
|
||||
@@ -57,4 +64,19 @@ class Mrsk::Configuration::Assessory
|
||||
def default_labels
|
||||
{ "service" => service_name }
|
||||
end
|
||||
|
||||
def expand_local_file_path(local_file)
|
||||
Pathname.new(File.expand_path(local_file))
|
||||
end
|
||||
|
||||
def expand_remote_file_path(remote_file)
|
||||
service_name + remote_file
|
||||
end
|
||||
|
||||
def remote_files_as_volumes
|
||||
specifics["files"]&.collect do |local_to_remote_mapping|
|
||||
_, remote_file = local_to_remote_mapping.split(":")
|
||||
"#{expand_remote_file_path(remote_file)}:#{remote_file}"
|
||||
end || []
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user