Class: Lobstr::Deploy
- Inherits:
-
Base
- Object
- Base
- Lobstr::Deploy
show all
- Defined in:
- lib/lobstr/deploy.rb
Instance Attribute Summary
Attributes inherited from Base
#app, #branch, #config, #environment, #ssh
Instance Method Summary
collapse
Methods inherited from Base
#connect, #local_task, #parse_target, #remote_task
Constructor Details
#initialize(target, config_file = 'config/lobstr.yml', &block) ⇒ Deploy
3
4
5
6
7
8
9
10
11
12
|
# File 'lib/lobstr/deploy.rb', line 3
def initialize(target, config_file = 'config/lobstr.yml', &block)
@branch,@environment = parse_target(target)
@config = Lobstr::Config.new(config_file).parse(@environment)
@app = @config['app']
if block_given?
return instance_eval(&block)
else
return self
end
end
|
Instance Method Details
#bundle_install(options = {}) ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/lobstr/deploy.rb', line 54
def bundle_install(options = {})
if config.has_key? 'bundler'
options = @config['bundler'].merge(options)
else
options = {
'deployment' => nil,
'path' => 'vendor/bundle',
'without' => 'development test'
}.merge(options)
end
options_string = ''
options.each { |k,v| options_string += "--#{k} #{v} " }
remote_task "bundle install #{options_string}"
end
|
#deploy ⇒ Object
14
15
16
17
18
19
20
21
|
# File 'lib/lobstr/deploy.rb', line 14
def deploy
connect do
update
bundle_install
restart true
notify
end
end
|
#export_foreman(format = 'upstart', location = '/etc/init', options = {}) ⇒ Object
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/lobstr/deploy.rb', line 69
def export_foreman(format='upstart', location='/etc/init', options={})
valid_formats = ['bluepill','inittab','runit','upstart']
unless valid_formats.include? format
raise Lobstr::Error::InvalidExportFormat
end
if @config.has_key? 'foreman'
options = @config['foreman'].merge(options)
else
options = {
'app' => @config['app'],
'log' => "#{@config['path']}/log",
'user' => @config['ssh_user'],
'procfile' => "#{@config['path']}/Procfile"
}.merge(options)
end
options_string = ''
options.each { |k,v| options_string += "--#{k} #{v} " }
remote_task "foreman export #{format} #{location} #{options_string}"
end
|
#notify(event = :deployment) ⇒ Object
43
44
45
|
# File 'lib/lobstr/deploy.rb', line 43
def notify(event = :deployment)
"notify of #{event}"
end
|
#restart(sudo = true) ⇒ Object
32
33
34
35
|
# File 'lib/lobstr/deploy.rb', line 32
def restart(sudo = true)
sudoit = (sudo) ? 'sudo' : ''
remote_task "#{sudoit} /etc/init.d/#{@config['app']}"
end
|
#rollback ⇒ Object
37
38
39
40
41
|
# File 'lib/lobstr/deploy.rb', line 37
def rollback
remote_task "cd #{@config['path']}"
remote_task "git fetch origin"
remote_task "git reset --hard HEAD@{1}"
end
|
#setup(&block) ⇒ Object
47
48
49
50
51
52
|
# File 'lib/lobstr/deploy.rb', line 47
def setup(&block)
return instance_eval(&block) if block_given?
remote_task "git clone #{@config['repos']} #{@config['path']}"
bundle_install
export_foreman
end
|
#update ⇒ Object
23
24
25
26
27
28
29
30
|
# File 'lib/lobstr/deploy.rb', line 23
def update
remote_task "cd #{@config['path']}"
remote_task "git fetch origin"
remote_task "git reset --hard #{@branch}"
remote_task "cd #{@config['path']}"
remote_task 'git reflog delete --rewrite HEAD@{1}'
remote_task 'git reflog delete --rewrite HEAD@{1}'
end
|