Skip to content

Commit f5ac1da

Browse files
committed
Ensure GAE deployment accessibility and cleanup
1 parent 4088fe6 commit f5ac1da

3 files changed

Lines changed: 23 additions & 7 deletions

File tree

‎Rakefile‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ namespace :integration do
690690
project_id = gcloud_project_id
691691
fail "Unabled to determine project_id from gcloud SDK. Please make " \
692692
"sure gcloud SDK is logged in and a valid project ID is configured." unless project_id
693-
# If project_uri not given, default to "http://[project_id].appspot.com"
693+
# If project_uri not given, default to "http://[project_id].appspot-preview.com"
694694
project_uri = args[:project_uri] ||
695695
"http://#{project_id}.appspot-preview.com"
696696

@@ -701,7 +701,7 @@ namespace :integration do
701701

702702
test_apps.each do |test_app|
703703
header "Deploying #{test_app} to GAE Flex"
704-
deploy_gae_flex test_app do
704+
deploy_gae_flex test_app, project_uri do
705705
valid_gems.each do |gem|
706706
Dir.chdir gem do
707707
header "Running integration:gae for gem #{gem}"

‎integration/deploy.rb‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
# Setup the app.yaml file and deploy this directory to GAE. When run from repo
2020
# root directory, this will deploy the integration/classic_sinatra_app.rb onto
2121
# GAE for testing use.
22-
def deploy_gae_flex app_dir
22+
def deploy_gae_flex app_dir, project_uri
2323
unless File.file? "app.yaml"
2424
FileUtils.cp "#{app_dir}/app.yaml.example", "app.yaml"
2525
temp_app_yaml = true
@@ -31,15 +31,21 @@ def deploy_gae_flex app_dir
3131
last_gae_version = get_gae_versions.last
3232
sh "gcloud beta app deploy -q" do |ok, res|
3333
if ok
34-
# Wait couple minutes for load balancer to stablize
35-
sleep 120
34+
# Make sure the deployment is fully accessible.
35+
keep_trying_till_true 300 do
36+
verify_uri_acessibility project_uri
37+
end
3638

3739
yield
3840

3941
# Delete the last version of Google App Engine if successfully deployed
4042
unless last_gae_version.empty?
4143
puts "gcloud app versions delete #{last_gae_version} -q"
42-
`gcloud app versions delete #{last_gae_version} -q`
44+
keep_trying_till_true 600 do
45+
`gcloud app versions delete #{last_gae_version} -q`
46+
47+
!get_gae_versions.include?(last_gae_version)
48+
end
4349
end
4450
else
4551
fail "'gcloud app deploy' failed with status = #{res.exitstatus}"

‎integration/helper.rb‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,33 @@
1515

1616
require "fileutils"
1717
require "open3"
18+
require "net/http"
1819

1920
##
2021
# Keep trying a block of code until the code of block yield a true statement or
2122
# raise error after timeout
2223
def keep_trying_till_true timeout = 30
2324
t_begin = Time.now
25+
delay = 2
2426
loop do
2527
if yield
2628
break
2729
elsif (Time.now - t_begin) > timeout
2830
fail "Timeout after trying for #{timeout} seconds"
2931
else
30-
sleep 1
32+
sleep delay
3133
end
34+
delay += 1
3235
end
3336
end
3437

38+
##
39+
# Verify the given uri can be accessed successfully.
40+
def verify_uri_acessibility uri
41+
res = Net::HTTP.get_response URI(uri)
42+
res.is_a? Net::HTTPSuccess
43+
end
44+
3545
##
3646
# Get GCP project id from Gcloud SDK
3747
def gcloud_project_id

0 commit comments

Comments
 (0)