class DPL::Provider::GAE

Constants

BASE
BOOTSTRAP
EXT
GCLOUD
INSTALL
NAME

Public Instance Methods

check_auth() click to toggle source
# 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
config() click to toggle source
# File lib/dpl/provider/gae.rb, line 64
def config
  options[:config] || 'app.yaml'
end
install_deploy_dependencies() click to toggle source
# 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
keyfile() click to toggle source
# File lib/dpl/provider/gae.rb, line 52
def keyfile
  options[:keyfile] || context.env['GOOGLECLOUDKEYFILE'] || 'service-account.json'
end
needs_key?() click to toggle source
# File lib/dpl/provider/gae.rb, line 42
def needs_key?
  false
end
no_promote() click to toggle source
# File lib/dpl/provider/gae.rb, line 68
def no_promote
  options[:no_promote]
end
no_stop_previous_version() click to toggle source
# File lib/dpl/provider/gae.rb, line 76
def no_stop_previous_version
  options[:no_stop_previous_version]
end
project() click to toggle source
# 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_app() click to toggle source
# 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
verbosity() click to toggle source
# File lib/dpl/provider/gae.rb, line 72
def verbosity
  options[:verbosity] || 'warning'
end
version() click to toggle source
# File lib/dpl/provider/gae.rb, line 60
def version
  options[:version]
end
with_python_2_7(cmd) click to toggle source
# 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