middleman-deploy/lib/middleman-deploy/methods/rsync.rb

35 lines
958 B
Ruby
Raw Normal View History

module Middleman
module Deploy
module Methods
class Rsync < Base
attr_reader :clean, :flags, :host, :path, :port, :user
2014-05-29 11:57:30 +02:00
def initialize(server_instance, options = {})
super(server_instance, options)
@clean = self.options.clean
@flags = self.options.flags
@host = self.options.host
@path = self.options.path
@port = self.options.port
@user = self.options.user
end
def process
# Append "@" to user if provided.
2015-08-16 20:06:10 +02:00
user = "#{self.user}@" if user && !user.empty?
2015-08-16 20:06:10 +02:00
dest_url = "#{user}#{host}:#{path}"
flags = self.flags || '-avz'
2015-08-16 20:06:10 +02:00
command = "rsync #{flags} '-e ssh -p #{port}' #{build_dir}/ #{dest_url}"
2015-08-16 20:06:10 +02:00
command += ' --delete' if clean
2015-08-16 20:06:10 +02:00
puts "## Deploying via rsync to #{dest_url} port=#{port}"
2014-02-26 12:04:08 +01:00
exec command
end
end
end
end
end