From 025bfdb4b013ecf17c5329aafc92356878d01971 Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Mon, 19 Jan 2015 21:22:07 +0000 Subject: [PATCH 01/10] Test deployment with Travis. --- .travis.yml | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index af5732a70..94beaab9b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,18 @@ ---- language: ruby - env: GROWSTUFF_SITE_NAME="Growstuff (travis)" RAILS_SECRET_TOKEN='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' -bundler_args: --without development production staging +bundler_args: "--without development production staging" rvm: - - 2.1.5 +- 2.1.5 before_script: - - psql -c 'create database growstuff_test;' -U postgres +- psql -c 'create database growstuff_test;' -U postgres script: - - bundle exec rake db:migrate --trace - - bundle exec rspec spec/ +- bundle exec rake db:migrate --trace +- bundle exec rspec spec/ +deploy: + provider: heroku + api_key: + secure: WrQxf0fEKkCdXrjcejurobOnNNz3he4dDwjBbToXbQTQNDObPp7NetJrLsfM8FiUFEeOuvhIHHiDQtMvY720zGGAGxDptvgFS+0QHCUqoTRZA/yFfUmHlG2jROXTzk5uVK0AE4k6Ion5kX8+mM0EnMT/7u+MTFiukrJctSiEXfg= + app: tranquil-basin-3130 + on: + repo: Growstuff/growstuff + branch: travis_deploy From 1387f381d26e6013649a4b3928854ea2dbf1309f Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Mon, 19 Jan 2015 21:52:38 +0000 Subject: [PATCH 02/10] Run migrations and scripts on successful build. --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index 94beaab9b..7085ff719 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,3 +16,7 @@ deploy: on: repo: Growstuff/growstuff branch: travis_deploy + run: + - "rake db:migrate" + - "script/deploy-tasks.sh" + - restart From 3aadc5d68fad1f262dae1b01394e4720bdf68037 Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Mon, 19 Jan 2015 23:05:15 +0000 Subject: [PATCH 03/10] Deploy to different apps based on branch --- .travis.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 7085ff719..fbd82c179 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,7 +15,10 @@ deploy: app: tranquil-basin-3130 on: repo: Growstuff/growstuff - branch: travis_deploy + app: + master: growstuff-prod + dev: growstuff-staging + travis_deploy: tranquil-basin-3130 run: - "rake db:migrate" - "script/deploy-tasks.sh" From 72f86c4ad05b0f3dce128510f7612dca26b089f2 Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Mon, 19 Jan 2015 23:59:27 +0000 Subject: [PATCH 04/10] Don't auto-deploy to production. We need this to be stable and tested on staging (including environment variables and maintenance mode) before we turn it on for production. --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index fbd82c179..18bc8ac68 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,7 +16,6 @@ deploy: on: repo: Growstuff/growstuff app: - master: growstuff-prod dev: growstuff-staging travis_deploy: tranquil-basin-3130 run: From 2c006ec43031e253b94f3984b6a0bdd934cc3f84 Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Tue, 20 Jan 2015 08:17:41 +0000 Subject: [PATCH 05/10] Remove stray "app: tranquil-basin" --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 18bc8ac68..b92c9f520 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,7 +12,6 @@ deploy: provider: heroku api_key: secure: WrQxf0fEKkCdXrjcejurobOnNNz3he4dDwjBbToXbQTQNDObPp7NetJrLsfM8FiUFEeOuvhIHHiDQtMvY720zGGAGxDptvgFS+0QHCUqoTRZA/yFfUmHlG2jROXTzk5uVK0AE4k6Ion5kX8+mM0EnMT/7u+MTFiukrJctSiEXfg= - app: tranquil-basin-3130 on: repo: Growstuff/growstuff app: From 34ea6eb37fc3d0f6df47e858def218b866c06e68 Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Tue, 20 Jan 2015 08:20:44 +0000 Subject: [PATCH 06/10] Turning on maintenance mode for deploys, attempt 3 --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index b92c9f520..37ecd0a70 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,8 @@ before_script: script: - bundle exec rake db:migrate --trace - bundle exec rspec spec/ +before_deploy: + - heroku maintenance:on deploy: provider: heroku api_key: @@ -21,3 +23,5 @@ deploy: - "rake db:migrate" - "script/deploy-tasks.sh" - restart +after_deploy: + - heroku maintenance:on From 1b936100e711f9d55ff212da4f8313e7c222b232 Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Tue, 20 Jan 2015 08:47:06 +0000 Subject: [PATCH 07/10] Trying out container-based Travis. --- .travis.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 37ecd0a70..4496b77f6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,4 @@ +sudo: false language: ruby env: GROWSTUFF_SITE_NAME="Growstuff (travis)" RAILS_SECRET_TOKEN='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' bundler_args: "--without development production staging" @@ -8,8 +9,6 @@ before_script: script: - bundle exec rake db:migrate --trace - bundle exec rspec spec/ -before_deploy: - - heroku maintenance:on deploy: provider: heroku api_key: @@ -23,5 +22,3 @@ deploy: - "rake db:migrate" - "script/deploy-tasks.sh" - restart -after_deploy: - - heroku maintenance:on From 5a2d9eabf4cd342825c1037aa64ea0265d71d8fb Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Tue, 20 Jan 2015 09:16:00 +0000 Subject: [PATCH 08/10] Turn on Bundler caching on Travis --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 4496b77f6..aed5eb644 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,6 @@ sudo: false language: ruby +cache: bundler env: GROWSTUFF_SITE_NAME="Growstuff (travis)" RAILS_SECRET_TOKEN='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' bundler_args: "--without development production staging" rvm: From 531a0bd9eac2dcfab342ae8c8c01213b7bfc5fc9 Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Tue, 20 Jan 2015 23:16:05 +0000 Subject: [PATCH 09/10] Roll our own heroku maintenance:(on|off) script This allows us to use maintenance mode without installing the full Heroku toolbelt, which we can't do on the (much faster!) container-based infrastructure. We add a (temporary) deployment to my sandbox from the travis_containers branch: muckingabout with one branch for both container-based and VM-based approaches was starting to get confusing. --- .travis.yml | 11 ++++++++++- Gemfile | 4 ++++ Gemfile.lock | 5 +++++ script/heroku_maintenance.rb | 27 +++++++++++++++++++++++++++ 4 files changed, 46 insertions(+), 1 deletion(-) create mode 100755 script/heroku_maintenance.rb diff --git a/.travis.yml b/.travis.yml index aed5eb644..5b3795ac5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,11 @@ sudo: false language: ruby cache: bundler -env: GROWSTUFF_SITE_NAME="Growstuff (travis)" RAILS_SECRET_TOKEN='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' +env: + matrix: + - GROWSTUFF_SITE_NAME="Growstuff (travis)" RAILS_SECRET_TOKEN='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' + global: + secure: "Z5TpM2jEX4UCvNePnk/LwltQX48U2u9BRc+Iypr1x9QW2o228QJhPIOH39a8RMUrepGnkQIq9q3ZRUn98RfrJz1yThtlNFL3NmzdQ57gKgjGwfpa0e4Dwj/ZJqV2D84tDGjvdVYLP7zzaYZxQcwk/cgNpzKf/jq97HLNP7CYuf4=" bundler_args: "--without development production staging" rvm: - 2.1.5 @@ -10,6 +14,8 @@ before_script: script: - bundle exec rake db:migrate --trace - bundle exec rspec spec/ +before_deploy: + - bundle exec script/heroku_maintenance.rb on deploy: provider: heroku api_key: @@ -19,7 +25,10 @@ deploy: app: dev: growstuff-staging travis_deploy: tranquil-basin-3130 + travis_containers: tranquil-basin-3130 run: - "rake db:migrate" - "script/deploy-tasks.sh" - restart +after_deploy: + - bundle exec script/heroku_maintenance.rb off diff --git a/Gemfile b/Gemfile index 5d3f1dbc2..5fd97718e 100644 --- a/Gemfile +++ b/Gemfile @@ -109,3 +109,7 @@ group :development, :test do gem 'poltergeist', '~> 1.5.1' # for headless JS testing gem 'i18n-tasks' # adds tests for finding missing and unused translations end + +group :travis do + gem 'heroku-api' +end diff --git a/Gemfile.lock b/Gemfile.lock index ba229682d..aea28ac9b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -110,6 +110,7 @@ GEM thread thread_safe erubis (2.7.0) + excon (0.43.0) execjs (2.2.2) factory_girl (4.5.0) activesupport (>= 3.0.0) @@ -136,6 +137,9 @@ GEM html2haml (>= 1.0.1) railties (>= 4.0.1) hashie (3.3.2) + heroku-api (0.3.22) + excon (~> 0.38) + multi_json (~> 1.8) highline (1.6.21) hike (1.2.3) hpricot (0.8.6) @@ -356,6 +360,7 @@ DEPENDENCIES gravatar-ultimate haml haml-rails + heroku-api i18n-tasks jquery-rails jquery-ui-rails (~> 5.0.2) diff --git a/script/heroku_maintenance.rb b/script/heroku_maintenance.rb new file mode 100755 index 000000000..789c2c1b9 --- /dev/null +++ b/script/heroku_maintenance.rb @@ -0,0 +1,27 @@ +#!/usr/bin/env ruby + +require 'heroku-api' + +heroku = Heroku::API.new(:api_key => ENV['HEROKU_API_KEY']) +branch = ENV['TRAVIS_BRANCH'] +case branch +when 'master' + app = 'growstuff-prod' +when 'dev' + app = 'growstuff-staging' +when 'travis_deploy', 'travis_containers' + app = 'tranquil-basin-3130' +else + abort "No Heroku app found for branch #{branch}" +end + +case ARGV[0] +when "on" + maintenance_state = 1 +when "off" + maintenance_state = 0 +else + abort "usage: #{$0} (on|off)" +end + +heroku.post_app_maintenance(app, maintenance_state) From 57552455e3a310bb64b48a07a77e64831e5ac00a Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Wed, 21 Jan 2015 09:13:07 +0000 Subject: [PATCH 10/10] Get Heroku app from .travis.yml --- script/heroku_maintenance.rb | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/script/heroku_maintenance.rb b/script/heroku_maintenance.rb index 789c2c1b9..cf23b398f 100755 --- a/script/heroku_maintenance.rb +++ b/script/heroku_maintenance.rb @@ -1,16 +1,13 @@ #!/usr/bin/env ruby require 'heroku-api' +require 'yaml' heroku = Heroku::API.new(:api_key => ENV['HEROKU_API_KEY']) branch = ENV['TRAVIS_BRANCH'] -case branch -when 'master' - app = 'growstuff-prod' -when 'dev' - app = 'growstuff-staging' -when 'travis_deploy', 'travis_containers' - app = 'tranquil-basin-3130' +travis_config = YAML.load_file('.travis.yml') +if travis_config['deploy']['app'].has_key? branch + app = travis_config['deploy']['app'][branch] else abort "No Heroku app found for branch #{branch}" end @@ -24,4 +21,5 @@ else abort "usage: #{$0} (on|off)" end +puts "Turning #{maintenance_state} maintenance mode on app #{app}" heroku.post_app_maintenance(app, maintenance_state)