Class: DPL::Provider
- Inherits:
-
Object
show all
- Includes:
- FileUtils
- Defined in:
- lib/dpl/provider.rb,
lib/dpl/provider/s3.rb,
lib/dpl/provider/npm.rb,
lib/dpl/provider/deis.rb,
lib/dpl/provider/pypi.rb,
lib/dpl/provider/appfog.rb,
lib/dpl/provider/heroku.rb,
lib/dpl/provider/cloud66.rb,
lib/dpl/provider/divshot.rb,
lib/dpl/provider/hackage.rb,
lib/dpl/provider/modulus.rb,
lib/dpl/provider/ninefold.rb,
lib/dpl/provider/releases.rb,
lib/dpl/provider/rubygems.rb,
lib/dpl/provider/dot_cloud.rb,
lib/dpl/provider/nodejitsu.rb,
lib/dpl/provider/openshift.rb,
lib/dpl/provider/ops_works.rb,
lib/dpl/provider/heroku/git.rb,
lib/dpl/provider/cloud_files.rb,
lib/dpl/provider/engine_yard.rb,
lib/dpl/provider/cloudcontrol.rb,
lib/dpl/provider/heroku/anvil.rb,
lib/dpl/provider/cloud_foundry.rb,
lib/dpl/provider/heroku/git_deploy_key.rb
Direct Known Subclasses
Appfog, Cloud66, CloudControl, CloudFiles, CloudFoundry, Deis, Divshot, DotCloud, EngineYard, Hackage, Heroku::Git, Modulus, NPM, Ninefold, Nodejitsu, Openshift, OpsWorks, PyPI, Releases, RubyGems, S3
Defined Under Namespace
Modules: Heroku
Classes: Appfog, Cloud66, CloudControl, CloudFiles, CloudFoundry, Deis, Divshot, DotCloud, EngineYard, Hackage, Modulus, NPM, Ninefold, Nodejitsu, Openshift, OpsWorks, PyPI, Releases, RubyGems, S3
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(context, options) ⇒ Provider
Returns a new instance of Provider.
77
78
79
|
# File 'lib/dpl/provider.rb', line 77
def initialize(context, options)
@context, @options = context, options
end
|
Instance Attribute Details
#context ⇒ Object
Returns the value of attribute context.
75
76
77
|
# File 'lib/dpl/provider.rb', line 75
def context
@context
end
|
#options ⇒ Object
Returns the value of attribute options.
75
76
77
|
# File 'lib/dpl/provider.rb', line 75
def options
@options
end
|
Class Method Details
.apt_get(name, command = name) ⇒ Object
63
64
65
|
# File 'lib/dpl/provider.rb', line 63
def self.apt_get(name, command = name)
context.shell("sudo apt-get -qq install #{name}", retry: true) if `which #{command}`.chop.empty?
end
|
.context ⇒ Object
55
56
57
|
# File 'lib/dpl/provider.rb', line 55
def self.context
self
end
|
.experimental(name) ⇒ Object
40
41
42
|
# File 'lib/dpl/provider.rb', line 40
def self.experimental(name)
puts "", "!!! #{name} support is experimental !!!", ""
end
|
.new(context, options) ⇒ Object
30
31
32
33
34
35
36
37
38
|
# File 'lib/dpl/provider.rb', line 30
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-z0-9]/, '')
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
71
72
73
|
# File 'lib/dpl/provider.rb', line 71
def self.npm_g(name, command = name)
context.shell("npm install -g #{name}", retry: true) if `which #{command}`.chop.empty?
end
|
.pip(name, command = name) ⇒ Object
67
68
69
|
# File 'lib/dpl/provider.rb', line 67
def self.pip(name, command = name)
context.shell("sudo pip install #{name}", retry: true) if `which #{command}`.chop.empty?
end
|
.requires(name, options = {}) ⇒ Object
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/dpl/provider.rb', line 44
def self.requires(name, options = {})
version = options[:version] || '> 0'
load = options[:load] || name
gem(name, version)
rescue LoadError
context.shell("gem install %s -v %p" % [name, version], retry: true)
Gem.clear_paths
ensure
require load
end
|
.shell(command, options = {}) ⇒ Object
59
60
61
|
# File 'lib/dpl/provider.rb', line 59
def self.shell(command, options = {})
system(command)
end
|
Instance Method Details
#check_app ⇒ Object
140
141
|
# File 'lib/dpl/provider.rb', line 140
def check_app
end
|
#cleanup ⇒ Object
124
125
126
127
128
129
|
# File 'lib/dpl/provider.rb', line 124
def cleanup
return if options[:skip_cleanup]
context.shell "mv .dpl ~/dpl"
context.shell "git stash --all"
context.shell "mv ~/dpl .dpl"
end
|
#create_key(file) ⇒ Object
143
144
145
|
# File 'lib/dpl/provider.rb', line 143
def create_key(file)
context.shell "ssh-keygen -t rsa -N \"\" -C #{option(:key_name)} -f #{file}"
end
|
#deploy ⇒ Object
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
# File 'lib/dpl/provider.rb', line 87
def deploy
setup_git_credentials
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
cleanup
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
if needs_key?
remove_key rescue nil
end
end
|
#error(message) ⇒ Object
173
174
175
|
# File 'lib/dpl/provider.rb', line 173
def error(message)
raise Error, message
end
|
#log(message) ⇒ Object
165
166
167
|
# File 'lib/dpl/provider.rb', line 165
def log(message)
$stderr.puts(message)
end
|
#needs_key? ⇒ Boolean
136
137
138
|
# File 'lib/dpl/provider.rb', line 136
def needs_key?
true
end
|
#option(name, *alternatives) ⇒ Object
81
82
83
84
85
|
# File 'lib/dpl/provider.rb', line 81
def option(name, *alternatives)
options.fetch(name) do
alternatives.any? ? option(*alternatives) : raise(Error, "missing #{name}")
end
end
|
#run(command) ⇒ Object
169
170
171
|
# File 'lib/dpl/provider.rb', line 169
def run(command)
error "running commands not supported"
end
|
#setup_git_credentials ⇒ Object
147
148
149
150
|
# File 'lib/dpl/provider.rb', line 147
def setup_git_credentials
context.shell "git config user.email >/dev/null 2>/dev/null || git config user.email `whoami`@localhost"
context.shell "git config user.name >/dev/null 2>/dev/null || git config user.name `whoami`@localhost"
end
|
#setup_git_ssh(path, key_path) ⇒ Object
152
153
154
155
156
157
158
159
160
161
162
163
|
# File 'lib/dpl/provider.rb', line 152
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
|
#sha ⇒ Object
120
121
122
|
# File 'lib/dpl/provider.rb', line 120
def sha
@sha ||= ENV['TRAVIS_COMMIT'] || `git rev-parse HEAD`.strip
end
|
#uncleanup ⇒ Object
131
132
133
134
|
# File 'lib/dpl/provider.rb', line 131
def uncleanup
return if options[:skip_cleanup]
context.shell "git stash pop"
end
|