Class: DPL::Provider::Deis
- Inherits:
-
DPL::Provider
- Object
- DPL::Provider
- DPL::Provider::Deis
- Defined in:
- lib/dpl/provider/deis.rb
Instance Method Summary collapse
- #builder_hostname ⇒ Object
- #check_app ⇒ Object
- #check_auth ⇒ Object
- #cleanup ⇒ Object
- #controller_host ⇒ Object
- #install_deploy_dependencies ⇒ Object
- #install_url ⇒ Object
- #needs_key? ⇒ Boolean
- #push_app ⇒ Object
- #remove_key ⇒ Object
- #repository_url ⇒ Object
- #run(command) ⇒ Object
- #setup_git_ssh(path, key_path) ⇒ Object
- #setup_key(file) ⇒ Object
- #verbose_flag ⇒ Object
- #wait_for_git_access ⇒ Object
Instance Method Details
#builder_hostname ⇒ Object
83 84 85 86 87 |
# File 'lib/dpl/provider/deis.rb', line 83 def builder_hostname host_tokens = controller_host.split(".") host_tokens[0] = [host_tokens[0], "builder"].join("-") host_tokens.join(".") end |
#check_app ⇒ Object
25 26 27 28 29 |
# File 'lib/dpl/provider/deis.rb', line 25 def check_app unless context.shell "./deis apps:info --app=#{option(:app)}" error 'Application could not be verified.' end end |
#check_auth ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/dpl/provider/deis.rb', line 17 def check_auth unless context.shell "./deis login #{option(:controller)}" \ " --username=#{option(:username)}" \ " --password=#{option(:password)}" error 'Login failed.' end end |
#cleanup ⇒ Object
105 106 107 108 109 110 |
# File 'lib/dpl/provider/deis.rb', line 105 def cleanup return if [:skip_cleanup] context.shell "mv deis ~/deis" super context.shell "mv ~/deis deis" end |
#controller_host ⇒ Object
89 90 91 |
# File 'lib/dpl/provider/deis.rb', line 89 def controller_host option(:controller).gsub(/https?:\/\//, "").split(":")[0] end |
#install_deploy_dependencies ⇒ Object
5 6 7 |
# File 'lib/dpl/provider/deis.rb', line 5 def install_deploy_dependencies context.shell "curl -sSL #{install_url} | bash -x -s #{option(:cli_version)}" end |
#install_url ⇒ Object
9 10 11 |
# File 'lib/dpl/provider/deis.rb', line 9 def install_url return "https://raw.githubusercontent.com/teamhephy/workflow-cli/master/install-v2.sh" end |
#needs_key? ⇒ Boolean
13 14 15 |
# File 'lib/dpl/provider/deis.rb', line 13 def needs_key? true end |
#push_app ⇒ Object
93 94 95 96 97 |
# File 'lib/dpl/provider/deis.rb', line 93 def push_app unless context.shell "bash -c 'git push #{verbose_flag} #{repository_url} HEAD:refs/heads/master -f 2>&1 | tr -dc \"[:alnum:][:space:][:punct:]\" | sed -E \"s/remote: (\\[1G)+//\" | sed \"s/\\[K$//\"; exit ${PIPESTATUS[0]}'" error 'Deploying application failed.' end end |
#remove_key ⇒ Object
73 74 75 76 77 |
# File 'lib/dpl/provider/deis.rb', line 73 def remove_key unless context.shell "./deis keys:remove #{option(:key_name)}" error 'Removing keys failed.' end end |
#repository_url ⇒ Object
79 80 81 |
# File 'lib/dpl/provider/deis.rb', line 79 def repository_url "ssh://git@#{builder_hostname}:2222/#{option(:app)}.git" end |
#run(command) ⇒ Object
99 100 101 102 103 |
# File 'lib/dpl/provider/deis.rb', line 99 def run(command) unless context.shell "./deis run -a #{option(:app)} -- #{command}" error 'Running command failed.' end end |
#setup_git_ssh(path, key_path) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/dpl/provider/deis.rb', line 37 def setup_git_ssh(path, key_path) key_path = File.(key_path) path = File.(path) File.open(path, 'w') do |file| file.write "#!/bin/sh\n" file.write "exec ssh #{verbose_flag} -o StrictHostKeychecking=no -o CheckHostIP=no -o UserKnownHostsFile=/dev/null -i #{key_path} \"$@\"\n" end chmod(0740, path) context.env['GIT_SSH'] = path wait_for_git_access end |
#setup_key(file) ⇒ Object
31 32 33 34 35 |
# File 'lib/dpl/provider/deis.rb', line 31 def setup_key(file) unless context.shell "./deis keys:add #{file}" error 'Adding keys failed.' end end |
#verbose_flag ⇒ Object
112 113 114 |
# File 'lib/dpl/provider/deis.rb', line 112 def verbose_flag '-v' if [:verbose] end |
#wait_for_git_access ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/dpl/provider/deis.rb', line 52 def wait_for_git_access() retry_count=0 max_retries=30 #Get the deis git remote host and port remote_uri=repository_url.split("ssh://")[1].split("/")[0] remote_host, remote_port = remote_uri.split(":") puts "Git remote is #{remote_host} at port #{remote_port}" #Try and connect to the github remote via ssh. while retry_count < max_retries puts "Waiting for ssh key to propagate..." if context.shell "#{context.env['GIT_SSH']} #{remote_host} -p #{remote_port} 2>&1 | grep -c 'PTY allocation request failed' > /dev/null" puts "SSH connection established." break end retry_count += 1 sleep(1) end end |