Class: DPL::Provider::GAE

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

Constant Summary collapse

BASE =
'https://dl.google.com/dl/cloudsdk/channels/rapid/'
NAME =
'google-cloud-sdk'
EXT =
'.tar.gz'
INSTALL =
'~'
BOOTSTRAP =
"#{INSTALL}/#{NAME}/bin/bootstrapping/install.py"
GCLOUD =
"#{INSTALL}/#{NAME}/bin/gcloud"

Instance Attribute Summary

Attributes inherited from DPL::Provider

#context, #options

Instance Method Summary collapse

Methods inherited from DPL::Provider

apt_get, #check_app, #cleanup, #commit_msg, context, #create_key, #default_text_charset, #default_text_charset?, #deploy, deprecated, #detect_encoding?, #encoding_for, #error, experimental, #initialize, #log, new, npm_g, #option, pip, requires, #run, #setup_git_credentials, #setup_git_ssh, #sha, shell, #uncleanup, #user_agent, #warn

Constructor Details

This class inherits a constructor from DPL::Provider

Instance Method Details

#check_authObject



46
47
48
49
50
# File 'lib/dpl/provider/gae.rb', line 46

def check_auth
  unless with_python_2_7("#{GCLOUD} -q auth activate-service-account --key-file #{keyfile}")
    error 'Authentication failed.'
  end
end

#configObject



64
65
66
# File 'lib/dpl/provider/gae.rb', line 64

def config
  options[:config] || 'app.yaml'
end

#install_deploy_dependenciesObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/dpl/provider/gae.rb', line 18

def install_deploy_dependencies
  if File.exists? GCLOUD
    return
  end

  $stderr.puts 'Python 2.7 Version'

  unless with_python_2_7("python -c 'import sys; print(sys.version)'")
    error 'Could not use python2.7'
  end

  $stderr.puts 'Downloading Google Cloud SDK ...'

  unless context.shell("curl -L #{BASE + NAME + EXT} | gzip -d | tar -x -C #{INSTALL}")
    error 'Could not download Google Cloud SDK.'
  end

  $stderr.puts 'Bootstrapping Google Cloud SDK ...'

  unless with_python_2_7("#{BOOTSTRAP} --usage-reporting=false --command-completion=false --path-update=false")
    error 'Could not bootstrap Google Cloud SDK.'
  end
end

#keyfileObject



52
53
54
# File 'lib/dpl/provider/gae.rb', line 52

def keyfile
  options[:keyfile] || context.env['GOOGLECLOUDKEYFILE'] || 'service-account.json'
end

#needs_key?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/dpl/provider/gae.rb', line 42

def needs_key?
  false
end

#no_promoteObject



68
69
70
# File 'lib/dpl/provider/gae.rb', line 68

def no_promote
  options[:no_promote]
end

#no_stop_previous_versionObject



76
77
78
# File 'lib/dpl/provider/gae.rb', line 76

def no_stop_previous_version
  options[:no_stop_previous_version]
end

#projectObject



56
57
58
# File 'lib/dpl/provider/gae.rb', line 56

def project
  options[:project] || context.env['GOOGLECLOUDPROJECT'] || context.env['CLOUDSDK_CORE_PROJECT'] || File.dirname(context.env['TRAVIS_REPO_SLUG'] || '')
end

#push_appObject



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/dpl/provider/gae.rb', line 80

def push_app
  command = GCLOUD
  command << ' --quiet'
  command << " --verbosity \"#{verbosity}\""
  command << " --project \"#{project}\""
  command << " app deploy \"#{config}\""
  command << " --version \"#{version}\"" unless version.to_s.empty?
  command << " --#{no_promote ? 'no-' : ''}promote"
  command << ' --no-stop-previous-version' unless no_stop_previous_version.to_s.empty?
  unless with_python_2_7(command)
    log 'Deployment failed.'
    context.shell('find $HOME/.config/gcloud/logs -type f -print -exec cat {} \;')
    error ''
  end
end

#verbosityObject



72
73
74
# File 'lib/dpl/provider/gae.rb', line 72

def verbosity
  options[:verbosity] || 'warning'
end

#versionObject



60
61
62
# File 'lib/dpl/provider/gae.rb', line 60

def version
  options[:version]
end

#with_python_2_7(cmd) ⇒ Object



13
14
15
16
# File 'lib/dpl/provider/gae.rb', line 13

def with_python_2_7(cmd)
  cmd.gsub!(/'/, "'\\\\''")
  context.shell("bash -c 'source #{context.env['HOME']}/virtualenv/python2.7/bin/activate; #{cmd}'")
end