Class: Docksync::Rsync::Sync
- Inherits:
-
Object
- Object
- Docksync::Rsync::Sync
- Defined in:
- lib/docksync/rsync/sync.rb
Instance Method Summary collapse
- #command ⇒ Object
- #docker_ps_for_port ⇒ Object
- #dockerhost ⇒ Object
- #dockerport ⇒ Object
- #get_excludes(file) ⇒ Object
- #get_src ⇒ Object
-
#initialize(options) ⇒ Sync
constructor
A new instance of Sync.
- #leave ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(options) ⇒ Sync
Returns a new instance of Sync.
4 5 6 7 |
# File 'lib/docksync/rsync/sync.rb', line 4 def initialize() @options = @cid = @options[:cid] end |
Instance Method Details
#command ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/docksync/rsync/sync.rb', line 46 def command # --numeric-ids don't map uid/gid values by user/group name # --safe-links ignore symlinks that point outside the tree # -a, --archive recursion and preserve almost everything (-rlptgoD) # -x, --one-file-system don't cross filesystem boundaries # -z, --compress compress file data during the transfer # -S, --sparse handle sparse files efficiently # -v, --verbose verbose exclude = %w/.git tmp log/ exclude += get_excludes('.gitignore') exclude += get_excludes('.dockerignore') exclude = exclude.uniq.map{|path| "--exclude='#{path}'"}.join(' ') = "--delete --numeric-ids --safe-links -axzSv #{exclude}" src = get_src dest = "rsync://#{dockerhost}:#{dockerport}/volume/" "rsync #{} #{src} #{dest}" end |
#docker_ps_for_port ⇒ Object
16 17 18 |
# File 'lib/docksync/rsync/sync.rb', line 16 def docker_ps_for_port `docker ps | grep #{@cid}` end |
#dockerhost ⇒ Object
9 10 11 12 13 14 |
# File 'lib/docksync/rsync/sync.rb', line 9 def dockerhost host = `boot2docker ip 2>&1 | grep address | awk '{print $NF}'`.strip # old version of boot2docker host = `boot2docker ip`.strip if host.empty? host = '192.168.59.103' if host.empty? host end |
#dockerport ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/docksync/rsync/sync.rb', line 20 def dockerport out = docker_ps_for_port md = out.match(/0\.0\.0\.0\:(\d+)->873/) if md md[1] else msg = "Could not find expose port 873. Are you sure you exposed port 837 for #{@cid} container?".colorize(:red) if @options[:mute] return msg else puts msg leave end end end |
#get_excludes(file) ⇒ Object
65 66 67 68 69 70 71 72 73 |
# File 'lib/docksync/rsync/sync.rb', line 65 def get_excludes(file) exclude = [] path = "#{@options[:cwd]}/#{file}" if File.exist?(path) exclude = File.read(path).split("\n") end result = exclude.map {|i| i.strip}.reject {|i| i =~ /^#/ || i.empty?} result end |
#get_src ⇒ Object
75 76 77 78 |
# File 'lib/docksync/rsync/sync.rb', line 75 def get_src src = @options[:cwd] || '.' src[-1] == '/' ? src : "#{src}/" end |
#leave ⇒ Object
36 37 38 |
# File 'lib/docksync/rsync/sync.rb', line 36 def leave exit 0 end |
#run ⇒ Object
40 41 42 43 44 |
# File 'lib/docksync/rsync/sync.rb', line 40 def run puts "Executing: #{command}" system(command) raise "rsync execution returned failure" if ($?.exitstatus != 0) end |