Class: Awestruct::Deploy::RSyncDeploy

Inherits:
Base
  • Object
show all
Defined in:
lib/awestruct/deploy/rsync_deploy.rb

Constant Summary

Constants inherited from Base

Base::UNCOMMITTED_CHANGES

Instance Method Summary collapse

Methods inherited from Base

#compress_site, #existing_changes, #gzip_file, #gzip_site, #init_scm, #is_gzipped, #run

Constructor Details

#initialize(site_config, deploy_config) ⇒ RSyncDeploy

Returns a new instance of RSyncDeploy.



9
10
11
12
13
14
# File 'lib/awestruct/deploy/rsync_deploy.rb', line 9

def initialize(site_config, deploy_config)
  super
  @host      = deploy_config['host']
  @path      = File.join( deploy_config['path'], '/' )
  @exclude   = deploy_config['exclude']
end

Instance Method Details

#publish_siteObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/awestruct/deploy/rsync_deploy.rb', line 16

def publish_site
  exclude_option = (!@exclude.nil? and !@exclude.empty?) ? "--exclude=" + Shellwords.escape(@exclude) : nil
  site_path = Shellwords.escape(@site_path)
  host = Shellwords.escape(@host)
  path = Shellwords.escape(@path)

  cmd = "rsync -r -l -i --no-p --no-g --chmod=Dg+sx,ug+rw --delete #{exclude_option} #{site_path} #{host}:#{path}"

  Open3.popen3( cmd ) do |stdin, stdout, stderr|
    stdin.close
    threads = []
    threads << Thread.new(stdout) do |i|
      while ( ! i.eof? )
        line = i.readline
        head = line[0,9]
        file = line[10..-1].chomp
        case head
        when '<f.sT....'
          $LOG.info " updating #{file}" if $LOG.info?
        when 'cd+++++++'
          $LOG.info " creating #{file}" if $LOG.info?
        when '<f+++++++'
          $LOG.info " adding #{file}" if $LOG.info?
        when '<f..T....'
          # ignoring unchanged files
          $LOG.debug " no change to #{file}" if $LOG.debug?
        when '*deleting'
          $LOG.info " deleting #{file}" if $LOG.info?
        else
          $LOG.debug line if $LOG.debug
        end
      end
    end
    threads << Thread.new(stderr) do |i|
      while ( ! i.eof? )
        line = i.readline
        $LOG.error line if $LOG.error?
      end
    end
    threads.each{|t|t.join}
  end
end