class Docksync::Rsync::Install

Public Class Methods

new(options) click to toggle source
# File lib/docksync/rsync/install.rb, line 6
def initialize(options)
  @options = options
  @cid = @options[:cid]
end

Public Instance Methods

app_root() click to toggle source
# 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) click to toggle source
# 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_script() click to toggle source

hacky way to copy file to the container

# 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_inspect() click to toggle source
# File lib/docksync/rsync/install.rb, line 39
def docker_inspect
  `docker inspect -f '{{.Id}}' #{@cid}`.strip
end
run() click to toggle source
# File lib/docksync/rsync/install.rb, line 11
def run
  copy_script
  run_script
end
run_script() click to toggle source
# 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