Class: GitDeploy
- Inherits:
-
Thor
show all
- Includes:
- Configuration, SSHMethods
- Defined in:
- lib/git_deploy.rb,
lib/git_deploy/changelog.rb,
lib/git_deploy/remote_path.rb,
lib/git_deploy/ssh_methods.rb,
lib/git_deploy/configuration.rb
Defined Under Namespace
Modules: Changelog, Configuration, RemotePath, SSHMethods
Classes: Generator
Constant Summary
collapse
- LOCAL_DIR =
File.expand_path('..', __FILE__)
Instance Method Summary
collapse
Instance Method Details
#download(*files) ⇒ Object
132
133
134
135
136
137
138
139
140
141
|
# File 'lib/git_deploy.rb', line 132
def download(*files)
require_remote!
abort "Error: Specify at least one file to download" if files.empty?
scp_download files.inject({}) { |all, file|
file = file.strip
all[File.join(deploy_to, file)] = file
all
}
end
|
#hooks ⇒ Object
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/git_deploy.rb', line 62
def hooks
require_remote!
remote_hook = "#{deploy_to}/.git/hooks/post-receive"
if run_test("[ -f #{remote_hook} ]") && !options[:force]
abort "Error: Remote already has a post-receive hook. Use --force to overwrite."
end
hooks_dir = File.join(LOCAL_DIR, 'hooks')
remote_dir = "#{deploy_to}/.git/hooks"
scp_upload "#{hooks_dir}/post-receive.sh" => "#{remote_dir}/post-receive"
run "chmod +x #{remote_dir}/post-receive"
end
|
#init ⇒ Object
20
21
22
23
|
# File 'lib/git_deploy.rb', line 20
def init
require 'git_deploy/generator'
Generator.start(['--template', options[:template]])
end
|
#log(n = nil) ⇒ Object
113
114
115
116
117
|
# File 'lib/git_deploy.rb', line 113
def log(n = nil)
require_remote!
tail_args = options.tail? ? '-f' : "-n#{n || options.lines}"
run "tail #{tail_args} #{deploy_to}/log/deploy.log"
end
|
#rerun ⇒ Object
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/git_deploy.rb', line 84
def rerun
require_remote!
run <<-BASH, :echo => false
bash -e -c '
cd '#{deploy_to}'
declare -a revs=( $(git rev-parse HEAD@{1} HEAD) )
deploy/after_push ${revs[@]} 2>&1 | tee -a log/deploy.log
'
BASH
end
|
#restart ⇒ Object
78
79
80
81
|
# File 'lib/git_deploy.rb', line 78
def restart
require_remote!
run "cd #{deploy_to} && deploy/restart 2>&1 | tee -a log/deploy.log"
end
|
#rollback ⇒ Object
96
97
98
99
100
101
102
103
104
105
106
107
108
|
# File 'lib/git_deploy.rb', line 96
def rollback
require_remote!
run <<-BASH, :echo => false
bash -e -c '
cd '#{deploy_to}'
declare -a revs=( $(git rev-parse HEAD HEAD@{1}) )
git reset --hard ${revs[1]}
callback=after_push
[ -x deploy/rollback ] && callback=rollback
deploy/$callback ${revs[@]} 2>&1 | tee -a log/deploy.log
'
BASH
end
|
#setup ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/git_deploy.rb', line 29
def setup
require_remote!
remote_hook = "#{deploy_to}/.git/hooks/post-receive"
if run_test("[ -f #{remote_hook} ]") && !options[:force]
abort "Error: Remote already has a post-receive hook. Use --force to overwrite."
end
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}"
unless run_test("[ -d #{deploy_to}/.git ]")
cmd << "git init #{options.shared? ? '--shared' : ''}"
cmd << "sed -i'' -e 's/master/#{branch}/' .git/HEAD" unless branch == 'master'
end
cmd << "git config --bool receive.denyNonFastForwards false" if options.shared?
cmd << "git config receive.denyCurrentBranch ignore"
end
invoke :hooks, [], force: options[:force]
end
|
#upload(*files) ⇒ Object
120
121
122
123
124
125
126
127
128
129
|
# File 'lib/git_deploy.rb', line 120
def upload(*files)
require_remote!
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
|