Class: DPL::Provider
- Inherits:
-
Object
show all
- Includes:
- FileUtils
- Defined in:
- lib/dpl/provider.rb,
lib/dpl/provider/heroku.rb,
lib/dpl/provider/dot_cloud.rb,
lib/dpl/provider/nodejitsu.rb,
lib/dpl/provider/heroku/git.rb,
lib/dpl/provider/engine_yard.rb,
lib/dpl/provider/heroku/anvil.rb
Defined Under Namespace
Modules: Heroku
Classes: DotCloud, EngineYard, Nodejitsu
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(context, options) ⇒ Provider
Returns a new instance of Provider.
48
49
50
|
# File 'lib/dpl/provider.rb', line 48
def initialize(context, options)
@context, @options = context, options
end
|
Instance Attribute Details
#context ⇒ Object
Returns the value of attribute context.
46
47
48
|
# File 'lib/dpl/provider.rb', line 46
def context
@context
end
|
#options ⇒ Object
Returns the value of attribute options.
46
47
48
|
# File 'lib/dpl/provider.rb', line 46
def options
@options
end
|
Class Method Details
.experimental(name) ⇒ Object
23
24
25
|
# File 'lib/dpl/provider.rb', line 23
def self.experimental(name)
puts "", "!!! #{name} support is experimental !!!", ""
end
|
.new(context, options) ⇒ Object
13
14
15
16
17
18
19
20
21
|
# File 'lib/dpl/provider.rb', line 13
def self.new(context, options)
return super if self < Provider
context.fold("Installing deploy dependencies") do
name = super.option(:provider).to_s.downcase.gsub(/[^a-z]/, '')
raise Error, 'could not find provider %p' % options[:provider] unless name = constants.detect { |c| c.to_s.downcase == name }
const_get(name).new(context, options)
end
end
|
.npm_g(name, command = name) ⇒ Object
42
43
44
|
# File 'lib/dpl/provider.rb', line 42
def self.npm_g(name, command = name)
system "npm install -g #{name}" if `which #{command}`.chop.empty?
end
|
.pip(name, command = name) ⇒ Object
38
39
40
|
# File 'lib/dpl/provider.rb', line 38
def self.pip(name, command = name)
system "pip install #{name}" if `which #{command}`.chop.empty?
end
|
.requires(name, options = {}) ⇒ Object
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/dpl/provider.rb', line 27
def self.requires(name, options = {})
version = options[:version] || '> 0'
load = options[:load] || name
gem(name, version)
rescue LoadError
system("gem install %s -v %p" % [name, version])
Gem.clear_paths
ensure
require load
end
|
Instance Method Details
#check_app ⇒ Object
88
89
|
# File 'lib/dpl/provider.rb', line 88
def check_app
end
|
#create_key(file) ⇒ Object
91
92
93
|
# File 'lib/dpl/provider.rb', line 91
def create_key(file)
system "ssh-keygen -t rsa -N \"\" -C #{option(:key_name)} -f #{file}"
end
|
#deploy ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/dpl/provider.rb', line 56
def deploy
rm_rf ".dpl"
mkdir_p ".dpl"
context.fold("Preparing deploy") do
check_auth
check_app
if needs_key?
create_key(".dpl/id_rsa")
setup_key(".dpl/id_rsa.pub")
setup_git_ssh(".dpl/git-ssh", ".dpl/id_rsa")
end
end
context.fold("Deploying application") { push_app }
Array(options[:run]).each do |command|
if command == 'restart'
context.fold("Restarting application") { restart }
else
context.fold("Running %p" % command) { run(command) }
end
end
ensure
remove_key if needs_key?
end
|
#error(message) ⇒ Object
116
117
118
|
# File 'lib/dpl/provider.rb', line 116
def error(message)
raise Error, message
end
|
#log(message) ⇒ Object
108
109
110
|
# File 'lib/dpl/provider.rb', line 108
def log(message)
$stderr.puts(message)
end
|
#needs_key? ⇒ Boolean
84
85
86
|
# File 'lib/dpl/provider.rb', line 84
def needs_key?
true
end
|
#option(name) ⇒ Object
52
53
54
|
# File 'lib/dpl/provider.rb', line 52
def option(name)
options.fetch(name) { raise Error, "missing #{name}" }
end
|
#run(command) ⇒ Object
112
113
114
|
# File 'lib/dpl/provider.rb', line 112
def run(command)
error "running commands not supported"
end
|
#setup_git_ssh(path, key_path) ⇒ Object
95
96
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/dpl/provider.rb', line 95
def setup_git_ssh(path, key_path)
key_path = File.expand_path(key_path)
path = File.expand_path(path)
File.open(path, 'w') do |file|
file.write "#!/bin/sh\n"
file.write "exec ssh -o StrictHostKeychecking=no -o CheckHostIP=no -o UserKnownHostsFile=/dev/null -i #{key_path} -- \"$@\"\n"
end
chmod(0740, path)
ENV['GIT_SSH'] = path
end
|