Skip to content

Commit

Permalink
Merge pull request #563 from travis-ci/gae-python-2.7
Browse files Browse the repository at this point in the history
Invoke GAE deployment commands with Python 2.7
  • Loading branch information
BanzaiMan committed Jan 11, 2017
2 parents 7e9b4e0 + 0238181 commit 77160b4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
17 changes: 14 additions & 3 deletions lib/dpl/provider/gae.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,22 @@ class GAE < Provider
BOOTSTRAP="#{INSTALL}/#{NAME}/bin/bootstrapping/install.py"
GCLOUD="#{INSTALL}/#{NAME}/bin/gcloud"

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

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}")
Expand All @@ -23,7 +34,7 @@ def install_deploy_dependencies

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

unless context.shell("#{BOOTSTRAP} --usage-reporting=false --command-completion=false --path-update=false")
unless with_python_2_7("#{BOOTSTRAP} --usage-reporting=false --command-completion=false --path-update=false")
error 'Could not bootstrap Google Cloud SDK.'
end
end
Expand All @@ -33,7 +44,7 @@ def needs_key?
end

def check_auth
unless context.shell("#{GCLOUD} -q --verbosity debug auth activate-service-account --key-file #{keyfile}")
unless with_python_2_7("#{GCLOUD} -q --verbosity debug auth activate-service-account --key-file #{keyfile}")
error 'Authentication failed.'
end
end
Expand Down Expand Up @@ -75,7 +86,7 @@ def push_app
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 context.shell(command)
unless with_python_2_7(command)
log 'Deployment failed.'
context.shell('find $HOME/.config/gcloud/logs -type f -print -exec cat {} \;')
error ''
Expand Down
13 changes: 12 additions & 1 deletion spec/provider/gae_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,21 @@
described_class.new(DummyContext.new, project: 'test')
end


describe '#push_app' do
example 'with defaults' do
allow(provider.context).to receive(:shell).with("#{DPL::Provider::GAE::GCLOUD} --quiet --verbosity \"warning\" --project \"test\" app deploy \"app.yaml\" --promote").and_return(true)
expect(provider.context.env).to receive(:[]).with('HOME').and_return('/home/travis')
allow(provider.context).to receive(:shell).with("bash -c 'source /home/travis/virtualenv/python2.7/bin/activate; #{DPL::Provider::GAE::GCLOUD} --quiet --verbosity \"warning\" --project \"test\" app deploy \"app.yaml\" --promote'").and_return(true)
provider.push_app
end
end


describe '#with_python_2_7' do
example 'with apostrophe' do
expect(provider.context.env).to receive(:[]).with('HOME').and_return('/home/travis')
allow(provider.context).to receive(:shell).with("bash -c 'source /home/travis/virtualenv/python2.7/bin/activate; python -c '\\''import sys; print(sys.version)'\\'''").and_return(true)
provider.with_python_2_7("python -c 'import sys; print(sys.version)'")
end
end
end

0 comments on commit 77160b4

Please sign in to comment.