Class: Miniploy::Deploy
- Inherits:
-
Object
show all
- Includes:
- DSL
- Defined in:
- lib/miniploy/deploy.rb
Instance Attribute Summary
Attributes included from DSL
#app, #bundle_add, #repository, #ssh_args, #target
Instance Method Summary
collapse
Methods included from DSL
#app_path, #append, #bundle_run, hook, #rake, #run, #run_path
Constructor Details
#initialize(filepath = 'config/miniploy.rb') ⇒ Deploy
Returns a new instance of Deploy.
5
6
7
8
9
10
11
|
# File 'lib/miniploy/deploy.rb', line 5
def initialize(filepath = 'config/miniploy.rb')
instance_eval File.read(filepath) + <<-eoh
local_variables.each do |v|
self.send "\#{v}=", eval(v.to_s) rescue nil
end
eoh
end
|
Instance Method Details
#setup ⇒ Object
13
14
15
16
17
18
19
20
|
# File 'lib/miniploy/deploy.rb', line 13
def setup
run "git clone --depth 1 #{repository} #{app_path}"
run "mkdir -p #{app_path}/tmp/run"
setup_bundler
rake 'db:create'
rake 'db:migrate'
after_setup
end
|
#setup_bundler ⇒ Object
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/miniploy/deploy.rb', line 22
def setup_bundler
return unless use_bundler?
bundle_add.each do |gem|
append "#{app_path}/Gemfile", "gem 'unicorn'"
end
run <<-eoh.gsub(/\A +/, '').chomp
bundle install --without development test \\
--gemfile #{app_path}/Gemfile --path $HOME/.bundle
eoh
end
|
#ssh(cmd) ⇒ Object
33
34
35
|
# File 'lib/miniploy/deploy.rb', line 33
def ssh(cmd)
system('ssh', ssh_args, target, cmd)
end
|
#update ⇒ Object
37
38
39
40
41
42
|
# File 'lib/miniploy/deploy.rb', line 37
def update
run "cd #{app_path} && git fetch origin && git reset --hard origin"
setup_bundler
rake 'db:migrate'
after_update
end
|
#use_bundler? ⇒ Boolean
44
45
46
|
# File 'lib/miniploy/deploy.rb', line 44
def use_bundler?
ssh "test -f #{app_path}/Gemfile"
end
|