Class: Docksync::Rsync::Install

Inherits:
Object
  • Object
show all
Defined in:
lib/docksync/rsync/install.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Install

Returns a new instance of Install.



6
7
8
9
# File 'lib/docksync/rsync/install.rb', line 6

def initialize(options)
  @options = options
  @cid = @options[:cid]
end

Instance Method Details

#app_rootObject



48
49
50
51
52
# File 'lib/docksync/rsync/install.rb', line 48

def app_root
  dockerfile = @options[:cwd] + "/Dockerfile"
  data = File.read(dockerfile).split("\n").grep(/WORKDIR/)
  workdir = data.first.split(' ').last
end

#container_copy_command(src) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/docksync/rsync/install.rb', line 31

def container_copy_command(src)
  full_cid = docker_inspect
  dest = "/var/lib/docker/aufs/mnt/#{full_cid}/tmp/"
  cmd = %Q|boot2docker ssh "cp #{src} #{dest}"|
  puts "Running: #{cmd}" unless @options[:mute]
  cmd
end

#copy_scriptObject

hacky way to copy file to the container



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/docksync/rsync/install.rb', line 17

def copy_script
  puts "Copying install-rsync.sh script to container"
  # temporarily use home since boot2docker host mounts /Users
  src = File.expand_path("../../bash/install-rsync.sh", __FILE__)
  tmp = "#{ENV['HOME']}/#{File.basename(src)}"
  FileUtils.cp(src, tmp)

  # copy to actual container
  system(container_copy_command(tmp))

  # clean up
  FileUtils.rm_f(tmp)
end

#docker_inspectObject



39
40
41
# File 'lib/docksync/rsync/install.rb', line 39

def docker_inspect
  `docker inspect -f '{{.Id}}' #{@cid}`.strip
end

#runObject



11
12
13
14
# File 'lib/docksync/rsync/install.rb', line 11

def run
  copy_script
  run_script
end

#run_scriptObject



43
44
45
46
# File 'lib/docksync/rsync/install.rb', line 43

def run_script
  puts "Installing rsync to container"
  puts `docker exec #{@cid} /bin/bash -e /tmp/install-rsync.sh #{app_root}`
end