Class: GitDeploy

Inherits:
Thor
  • Object
show all
Includes:
Configuration, SSHMethods
Defined in:
lib/git_deploy.rb,
lib/git_deploy/ssh_methods.rb,
lib/git_deploy/configuration.rb

Defined Under Namespace

Modules: Configuration, SSHMethods Classes: Generator

Constant Summary collapse

LOCAL_DIR =
File.expand_path('..', __FILE__)

Instance Method Summary collapse

Instance Method Details

#hooksObject



49
50
51
52
53
54
55
# File 'lib/git_deploy.rb', line 49

def hooks
  hooks_dir = File.join(LOCAL_DIR, 'hooks')
  remote_dir = "#{deploy_to}/.git/hooks"
  system "sed -i'' -e 's/production/#{options[:env]}/' #{hooks_dir}/post-receive.sh" unless options[:env] == 'production'
  scp_upload "#{hooks_dir}/post-receive.sh" => "#{remote_dir}/post-receive"
  run "chmod +x #{remote_dir}/post-receive"
end

#initObject



18
19
20
21
# File 'lib/git_deploy.rb', line 18

def init
  require 'git_deploy/generator'
  Generator::start([])
end

#log(n = nil) ⇒ Object



71
72
73
74
# File 'lib/git_deploy.rb', line 71

def log(n = nil)
  tail_args = options.tail? ? '-f' : "-n#{n || options.lines}"
  run "tail #{tail_args} #{deploy_to}/log/deploy.log"
end

#restartObject



58
59
60
# File 'lib/git_deploy.rb', line 58

def restart
  run "cd #{deploy_to} && deploy/restart | tee -a log/deploy.log"
end

#rollbackObject



63
64
65
66
# File 'lib/git_deploy.rb', line 63

def rollback
  run "cd #{deploy_to} && git reset --hard ORIG_HEAD"
  invoke :restart
end

#setupObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/git_deploy.rb', line 26

def setup
  sudo = options.sudo? ? "#{sudo_cmd} " : ''

  unless run_test("test -x #{deploy_to}")
    run ["#{sudo}mkdir -p #{deploy_to}"] do |cmd|
      cmd << "#{sudo}chown $USER #{deploy_to}" if options.sudo?
      cmd
    end
  end

  run [] do |cmd|
    cmd << "chmod g+ws #{deploy_to}" if options.shared?
    cmd << "cd #{deploy_to}"
    cmd << "git init #{options.shared? ? '--shared' : ''}"
    cmd << "sed -i'' -e 's/master/#{branch}/' .git/HEAD" unless branch == 'master'
    cmd << "git config --bool receive.denyNonFastForwards false" if options.shared?
    cmd << "git config receive.denyCurrentBranch ignore"
  end

  invoke :hooks
end

#upload(*files) ⇒ Object



77
78
79
80
81
82
83
84
85
# File 'lib/git_deploy.rb', line 77

def upload(*files)
  files = files.map { |f| Dir[f.strip] }.flatten
  abort "Error: Specify at least one file to upload" if files.empty?

  scp_upload files.inject({}) { |all, file|
    all[file] = File.join(deploy_to, file)
    all
  }
end