Sha256: 4d987ea1f2b9a80a8adea8f1c51a96dd027b1ff12fec121f9295990efd6bee7f

Contents?: true

Size: 1.6 KB

Versions: 6

Compression:

Stored size: 1.6 KB

Contents

#!/usr/bin/env ruby

def unquote(line)
  if line  
    line.match(/["'](.*)["']/)
    $1
  end
end

def find_project_root
  current = Dir.pwd
  until (File.exists? 'Capfile')
    Dir.chdir '..'
    return nil if current == Dir.pwd
    current = Dir.pwd
  end
  @project_root = current
end

begin
  require 'rubygems'
  require 'net/ssh'
  
  stage = ARGV.shift
  
  find_project_root or raise 'Call me from inside a Rails project'
  
  data = if stage
    deploy_file = Dir['config/deploy/*.rb'].find do |file|
      file.match(/\/#{stage}.rb$/)
    end
    deploy_file or raise "Unknown stage: #{stage}"
    
    File.open(deploy_file).readlines
  else
    []
  end + File.open("config/deploy.rb").readlines

  user        = unquote data.find{ |line| line =~ /^set :user,/}
  server      = unquote data.find{ |line| line =~ /^server / }
  deploy_to   = unquote data.find{ |line| line =~ /^set :deploy_to,/}
  environment = unquote data.find{ |line| line =~ /^set :rails_env,/}
  (user and server and deploy_to and environment) or raise "Could not find required data (user, server, deploy target and environment).\nUsage: dump-for DEPLOYMENT_STAGE"
  
  path = deploy_to + "/current"
  if path.match /#\{.*\}/
    puts %(NOTE: "#{path}" is not a valid path.)
    puts %(NOTE: You will need to fetch the dump yourself.)
    raise ""
  end

  command = %(ssh #{user}@#{server} -t "cd #{path} && dumple #{environment} --for_download")
  system command

  puts "Downloading dump_for_download..."
  exec "scp #{user}@#{server}:~/dumps/dump_for_download.dump #{@project_root}"
  
rescue Exception => e
  $stderr.puts e.message
  exit 1
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
geordi-0.3.2 bin/dump-for
geordi-0.3.1 bin/dump-for
geordi-0.3.0 bin/dump-for
geordi-0.2.7 bin/dump-for
geordi-0.2.6 bin/dump-for
geordi-0.2.5 bin/dump-for