Class: DPL::Provider::Scalingo
- Inherits:
-
DPL::Provider
- Object
- DPL::Provider
- DPL::Provider::Scalingo
- Defined in:
- lib/dpl/provider/scalingo.rb
Instance Method Summary collapse
- #check_auth ⇒ Object
-
#initialize(context, options) ⇒ Scalingo
constructor
A new instance of Scalingo.
- #install_deploy_dependencies ⇒ Object
- #push_app ⇒ Object
- #remove_key ⇒ Object
- #scalingo(command, env = [], input = '') ⇒ Object
- #setup_key(file, _type = nil) ⇒ Object
- #token ⇒ Object
- #username ⇒ Object
Constructor Details
#initialize(context, options) ⇒ Scalingo
Returns a new instance of Scalingo.
24 25 26 27 28 29 30 31 32 |
# File 'lib/dpl/provider/scalingo.rb', line 24 def initialize(context, ) super @options = @remote = [:remote] || 'scalingo-dpl' @branch = [:branch] || 'master' @region = [:region] || 'agora-fr1' @timeout = [:timeout] || '60' @debug = ![:debug].nil? end |
Instance Method Details
#check_auth ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/dpl/provider/scalingo.rb', line 34 def check_auth if token scalingo("login --api-token #{token}") elsif username && @options[:password] scalingo('login', [], "echo -e \"#{username}\n#{@options[:password]}\"") end end |
#install_deploy_dependencies ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/dpl/provider/scalingo.rb', line 9 def install_deploy_dependencies download_url = 'https://cli-dl.scalingo.io/release/scalingo_latest_linux_amd64.tar.gz' command = 'curl' command = "#{command} --silent" if !@debug command = "#{command} --remote-name --location #{download_url}" = 'v' if @debug = "#{}zxf" command = "#{command} && tar -#{} scalingo_latest_linux_amd64.tar.gz" \ ' && mv scalingo_*_linux_amd64/scalingo .' \ ' && rm scalingo_latest_linux_amd64.tar.gz' \ ' && rm -r scalingo_*_linux_amd64' error "Couldn't install Scalingo CLI." if !context.shell command end |
#push_app ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/dpl/provider/scalingo.rb', line 54 def push_app install_deploy_dependencies if @options[:app] if !scalingo("--app #{@options[:app]} git-setup --remote #{@remote}") error 'Failed to add the Git remote.' end end if !context.shell "git push #{@remote} #{@branch} --force" error "Couldn't push your app." end end |
#remove_key ⇒ Object
48 49 50 51 52 |
# File 'lib/dpl/provider/scalingo.rb', line 48 def remove_key if !scalingo('keys-remove dpl_tmp_key') error "Couldn't remove SSH key." end end |
#scalingo(command, env = [], input = '') ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/dpl/provider/scalingo.rb', line 76 def scalingo(command, env = [], input = '') env << "SCALINGO_REGION=#{@region}" if !@region.empty? if @debug env << 'DEBUG=1' else command += ' > /dev/null' end command = "#{env.join(' ')} timeout #{@timeout} ./scalingo #{command}" command = "#{input} | #{command}" if input != '' puts "Execute #{command}" if @debug context.shell command end |
#setup_key(file, _type = nil) ⇒ Object
42 43 44 45 46 |
# File 'lib/dpl/provider/scalingo.rb', line 42 def setup_key(file, _type = nil) if !scalingo("keys-add dpl_tmp_key #{file}") error "Couldn't add SSH key." end end |
#token ⇒ Object
72 73 74 |
# File 'lib/dpl/provider/scalingo.rb', line 72 def token @options[:api_key] || @options[:api_token] end |
#username ⇒ Object
68 69 70 |
# File 'lib/dpl/provider/scalingo.rb', line 68 def username @options[:username] || @options[:user] end |