Class: DPL::Provider::Scalingo

Inherits:
DPL::Provider show all
Defined in:
lib/dpl/provider/scalingo.rb

Instance Method Summary collapse

Constructor Details

#initialize(context, options) ⇒ Scalingo

Returns a new instance of Scalingo.



16
17
18
19
20
21
# File 'lib/dpl/provider/scalingo.rb', line 16

def initialize(context, options)
  super
  @options = options
  @remote = options[:remote] || "scalingo"
  @branch = options[:branch] || "master"
end

Instance Method Details

#check_authObject



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/dpl/provider/scalingo.rb', line 27

def check_auth
  token = @options[:api_key] || @options[:api_token]
  if token
    context.shell "timeout 2 ./scalingo login --api-token #{token} 2> /dev/null > /dev/null"
  elsif @options[:username] && @options[:password]
    context.shell "echo -e \"#{@options[:username]}\n#{@options[:password]}\" | timeout 2 ./scalingo login 2> /dev/null > /dev/null"
  end
  if !logged_in
    error "Couldn't connect to Scalingo API."
  end
end

#install_deploy_dependenciesObject



10
11
12
13
14
# File 'lib/dpl/provider/scalingo.rb', line 10

def install_deploy_dependencies
  unless context.shell "curl -OL https://cli-dl.scalingo.io/release/scalingo_latest_linux_amd64.tar.gz && tar -zxvf 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."
  end
end

#logged_inObject



23
24
25
# File 'lib/dpl/provider/scalingo.rb', line 23

def logged_in
  context.shell "DISABLE_INTERACTIVE=true ./scalingo login 2> /dev/null > /dev/null"
end

#push_appObject



57
58
59
60
61
62
63
64
# File 'lib/dpl/provider/scalingo.rb', line 57

def push_app
  if @options[:app]
    context.shell "git remote add #{@remote} [email protected]:#{@options[:app]}.git 2> /dev/null > /dev/null"
  end
  unless context.shell "git push #{@remote} #{@branch} -f"
    error "Couldn't push your app."
  end
end

#remove_keyObject



48
49
50
51
52
53
54
55
# File 'lib/dpl/provider/scalingo.rb', line 48

def remove_key
  if !logged_in
    error "Couldn't connect to Scalingo API."
  end
  unless context.shell "./scalingo keys-remove dpl_tmp_key"
    error "Couldn't remove ssh key."
  end
end

#setup_key(file, type = nil) ⇒ Object



39
40
41
42
43
44
45
46
# File 'lib/dpl/provider/scalingo.rb', line 39

def setup_key(file, type = nil)
  if !logged_in
    error "Couldn't connect to Scalingo API."
  end
  unless context.shell "./scalingo keys-add dpl_tmp_key #{file}"
    error "Couldn't add ssh key."
  end
end