class Dvm::CLI

Public Class Methods

new(root, repo) click to toggle source
# File lib/dvm/cli.rb, line 7
def initialize(root, repo)
  @root = root
  @repo = repo
end
run(argv) click to toggle source
# File lib/dvm/cli.rb, line 213
def self.run(argv)
  if argv.length >0
    action = argv[0]
    if action == 'remote'
      puts '1'

    elsif action == 'update'
      CLI.new(Dir.getwd, '').update
    elsif action == 'start'
      CLI.new(Dir.getwd, '').start
    elsif action == 'stop'
      CLI.new(Dir.getwd, '').stop
    elsif action == 'restart'
      CLI.new(Dir.getwd, '').restart
    elsif action == 'deploy'
      cli = CLI.new Dir.getwd, ''
      cli.stop
      cli.update
      cli.start
    else
      root = Dir.getwd
      repo = action

      if action.start_with? 'g:'
        repo = "git@github.com:#{action[2..-1]}.git"
      elsif action.start_with? 'b:'
        repo = "git@bitbucket.org:#{action[2..-1]}.git"
      end

      if argv[1]
        root = File.join root, argv[1]
      else
        root = File.join root, File.basename(repo, File.extname(repo))
      end

      CLI.new(root, repo).init_install

    end
  else

  end
end

Public Instance Methods

assets_precompile() click to toggle source
# File lib/dvm/cli.rb, line 114
def assets_precompile
  log_action 'Rails assets precompile'
  run_cmd "cd #{current};RAILS_ENV=production bundle exec rake assets:precompile"
end
bundle_install() click to toggle source
# File lib/dvm/cli.rb, line 126
def bundle_install
  log_action 'Rails bundle install'
  run_cmd "cd #{current};RAILS_ENV=production bundle install --deployment"
end
checkout() click to toggle source
# File lib/dvm/cli.rb, line 72
def checkout
  version = `cd #{scm};git rev-parse --short HEAD`.strip
  vd = release version
  FileUtils.makedirs vd
  run_cmd "cd #{scm};git archive master | tar -x -f - -C #{vd}"
  run_cmd "echo #{version} > #{vd}/REVISION"
  new_version version
  version
end
clone() click to toggle source
# File lib/dvm/cli.rb, line 67
def clone
  run_cmd "git clone --bare #{@repo} #{scm}"
end
copy_config() click to toggle source
# File lib/dvm/cli.rb, line 83
def copy_config
  Dir.glob(current_path('config', '**', '*.example')).each do |c|
    puts c
    FileUtils.cp c, share_path('config', c.split('config')[1..-1].join('config')[1..-1].split('.')[0..-2].join('.'))
  end
end
current() click to toggle source
# File lib/dvm/cli.rb, line 20
def current
  path 'current'
end
current_path(*p) click to toggle source
# File lib/dvm/cli.rb, line 24
def current_path(*p)
  File.join current, p
end
db_setup() click to toggle source
# File lib/dvm/cli.rb, line 120
def db_setup
  log_action 'Rails db setup'
  run_cmd "cd #{current};RAILS_ENV=production bundle exec rake db:setup"
end
drop_version(version) click to toggle source
# File lib/dvm/cli.rb, line 62
def drop_version(version)

end
init_install() click to toggle source
# File lib/dvm/cli.rb, line 132
def init_install
  log_action 'Git clone'
  clone
  link_current checkout

  log_action 'Copy & Link config files'
  shared_dirs.each { |e| FileUtils.makedirs share_path(e) }
  shared_files.each { |e| FileUtils.makedirs File.dirname(share_path(e)) }
  copy_config
  link_shared

  bundle_install
  vam_install
  assets_precompile

  puts '======= Deploy success ======'.colorize :green
end
log_action(action) click to toggle source
# File lib/dvm/cli.rb, line 172
def log_action(action)
  puts "\n======= #{action} =======".colorize :blue
end
new_version(version) click to toggle source
# File lib/dvm/cli.rb, line 58
def new_version(version)

end
path(p) click to toggle source
# File lib/dvm/cli.rb, line 12
def path(p)
  File.join @root, p
end
pull() click to toggle source
# File lib/dvm/cli.rb, line 151
def pull
  run_cmd "cd #{scm};git fetch origin master:master"
end
release(v) click to toggle source
# File lib/dvm/cli.rb, line 32
def release(v)
  File.join releases, v
end
releases() click to toggle source
# File lib/dvm/cli.rb, line 28
def releases
  path 'releases'
end
restart() click to toggle source
# File lib/dvm/cli.rb, line 207
def restart
  stop
  start
end
run_cmd(cmd) click to toggle source
# File lib/dvm/cli.rb, line 177
def run_cmd(cmd)
  puts "#RUN[ #{cmd} ]"
  system cmd
end
scm() click to toggle source
# File lib/dvm/cli.rb, line 16
def scm
  path 'scm'
end
share() click to toggle source
# File lib/dvm/cli.rb, line 36
def share
  path 'share'
end
share_path(*p) click to toggle source
# File lib/dvm/cli.rb, line 40
def share_path(*p)
  File.join share, p
end
shared_dirs() click to toggle source
# File lib/dvm/cli.rb, line 44
def shared_dirs
  %w(public/upload log vendor)
end
shared_files() click to toggle source
# File lib/dvm/cli.rb, line 48
def shared_files
  Dir.glob(current_path('config', '**', '*.example')).collect do |c|
    File.join 'config', c.split('config')[1..-1].join('config')[1..-1].split('.')[0..-2].join('.')
  end
end
start() click to toggle source
# File lib/dvm/cli.rb, line 183
def start
  if Dir.exist? current
    `cd #{current};bundle exec pumactl start`
  elsif File.exist? 'Gemfile'
    `pumactl start`
  else
    puts 'Start server failed.'.colorize :red
  end
  puts 'Start server success.'.colorize :green
end
stop() click to toggle source
# File lib/dvm/cli.rb, line 195
def stop
  if Dir.exist? current
    `cd #{current};kill -9 \`cat tmp/server.pid\``
  elsif File.exist? 'Gemfile'
    `kill -9 \`cat tmp/server.pid\``
  else
    puts 'Stop server failed.'.colorize :red
  end
  puts 'Stop server success.'.colorize :green
end
update() click to toggle source
# File lib/dvm/cli.rb, line 156
def update
  log_action 'Git pull'
  pull
  link_current checkout

  log_action 'Link config files'
  link_shared

  bundle_install
  vam_install
  assets_precompile

  puts '======= Deploy success ======'.colorize :green
end
vam_install() click to toggle source
# File lib/dvm/cli.rb, line 108
def vam_install
  log_action 'Vam install'
  run_cmd "cd #{current};vam install" if File.exist? File.join(current, 'Vamfile')
end
version(order) click to toggle source
# File lib/dvm/cli.rb, line 54
def version(order)

end