Skip to content
This repository
  • 20 commits
  • 7 files changed
  • 1 comment
  • 3 contributors
Apr 09, 2012
Larry Karnowski and Lake Denman Reviewing trade off of using ruby vs bash eebe723
Apr 10, 2012
Relevance Pair WIP c248d94
Relevance Pair Merge branch 'master' into nightly-build
Conflicts:
	script/ci
ce3ab6f
Larry Karnowski and Lake Denman GH #22: adding better logging 4032b7a
Larry Karnowski and Lake Denman GH #22: implementing nightly build script 672a867
Larry Karnowski and Lake Denman GH #22: added ability to "force" a stop or destroy of EC2 instance via
Rake
8b7a2ed
Larry Karnowski and Lake Denman GH #22: bugfix, removed unused, broken code e295eda
Larry Karnowski and Lake Denman GH #22: added rake task to determine the EC2 instance's current DNS name fb21681
Larry Karnowski and Lake Denman GH #22: changed the acceptance tests to work in production environment
on an EC2 instance
b24bd94
Larry Karnowski and Lake Denman GH #22: getting the nightly build pieces all together 0661d8d
Larry Karnowski and Lake Denman Merge branch 'master' into nightly-build
Conflicts:
	lib/relevance_rails/provision.rb
6627b02
Apr 11, 2012
Larry Karnowski and Lake Denman GH #22: extra protection f5704f8
Larry Karnowski and Lake Denman Removed debug statement 65b1911
Larry Karnowski and Lake Denman GH #22: finer-grained timestamp on CI ec2 instance names b27357f
Larry Karnowski and Lake Denman GH #22: adding lots of RVM debug messages 6e51a7e
Larry Karnowski and Lake Denman GH #22: explicitly state which ruby to use (to make Jenkins happy) 3a52bde
Larry Karnowski and Lake Denman GH #22: always fail if command fails, even if we don't have an active
EC2 instance
8e96f09
Larry Karnowski and Lake Denman GH #22: fun with shell, spaces, and missing quotes 1c4865f
Larry Karnowski and Lake Denman GH #22: allow Selenium tests to run on Jenkins server 247775c
Apr 12, 2012
Lake Denman and Sam Umbach Merge branch 'nightly-build' 7b91ef9
4 lib/generators/fixtures/fixtures_generator.rb
@@ -11,7 +11,9 @@ def create_views
11 11 %h1 WELCOME HOME
12 12 STR
13 13 create_file "app/views/relevance_rails/db.html.haml", <<-STR
14   -%h1.database= ActiveRecord::Base.connection.current_database
  14 += conn = ActiveRecord::Base.connection
  15 += results = conn.execute("select 4200+42 as advanced_math")
  16 +%h1.advanced_math= results.first["advanced_math"]
15 17 STR
16 18 end
17 19
28 lib/relevance_rails/provision.rb
@@ -6,11 +6,13 @@ module RelevanceRails
6 6 module Provision
7 7 def self.create_ec2(name = nil)
8 8 abort "Please provide a $NAME" unless name
9   - provision_ec2_instances(name)
  9 + server = provision_ec2_instances(name)
  10 + wait_for_ssh server
  11 + run_commands server
10 12 end
11 13
12 14 def self.stop_ec2
13   - return unless Thor::Shell::Basic.new.yes?("Are you sure you want to shut down EC2 instance #{instance_id}?")
  15 + return unless ENV["FORCE"] == "true" || Thor::Shell::Basic.new.yes?("Are you sure you want to shut down EC2 instance #{instance_id}?")
14 16 puts "Shutting down EC2 instance #{instance_id}..."
15 17 server = fog_connection.servers.get(instance_id)
16 18 server.stop
@@ -19,7 +21,7 @@ def self.stop_ec2
19 21 end
20 22
21 23 def self.destroy_ec2
22   - return unless Thor::Shell::Basic.new.yes?("Are you sure you want to destroy EC2 instance #{instance_id}?")
  24 + return unless ENV["FORCE"] == "true" || Thor::Shell::Basic.new.yes?("Are you sure you want to destroy EC2 instance #{instance_id}?")
23 25 puts "Destroying EC2 instance #{instance_id}..."
24 26 server = fog_connection.servers.get(instance_id)
25 27 server.destroy
@@ -29,6 +31,11 @@ def self.destroy_ec2
29 31 puts "Done!"
30 32 end
31 33
  34 + def self.current_dns
  35 + server = fog_connection.servers.get(instance_id)
  36 + puts server.reload.dns_name
  37 + end
  38 +
32 39 private
33 40
34 41 def self.instance_id
@@ -44,19 +51,19 @@ def self.fog_connection
44 51 end
45 52
46 53 def self.provision_ec2_instances(name)
  54 + puts "Provisioning an instance..."
47 55 server = fog_connection.servers.create(config['server']['creation_config'])
48 56 fog_connection.tags.create(:key => 'Name',
49 57 :value => "#{Rails.application.class.parent_name} #{name}",
50 58 :resource_id => server.id)
51 59 server.private_key = config['server']['private_key']
52   - wait_for_ssh server
53   -
  60 +
54 61 File.open("config/ec2_instance.txt", "w") do |f|
55 62 f.puts(server.id)
56 63 end
57 64
58   - run_commands server
59   - return server
  65 + puts "Provisioned!"
  66 + server
60 67 end
61 68
62 69 def self.run_commands(server)
@@ -75,6 +82,7 @@ def self.run_commands(server)
75 82
76 83 puts "Server Instance: #{server.id}"
77 84 puts "Server IP: #{server.public_ip_address}"
  85 + server
78 86 end
79 87
80 88 def self.run_command(server, command)
@@ -83,7 +91,7 @@ def self.run_command(server, command)
83 91 end
84 92
85 93 def self.wait_for_ssh(server)
86   - puts "Provisioning an instance..."
  94 + puts "Waiting for ssh connectivity..."
87 95 server.wait_for { ready? }
88 96 succeeded = false
89 97 attempts = 0
@@ -101,7 +109,7 @@ def self.wait_for_ssh(server)
101 109 end
102 110 end
103 111 raise last_error unless succeeded
104   - puts "Server up and listening for SSH..."
  112 + puts "Server up and listening for SSH!"
105 113 end
106 114
107 115 def self.jobs_succeeded?(jobs)
@@ -113,7 +121,7 @@ def self.jobs_succeeded?(jobs)
113 121 puts "STDERR: #{job.stderr}"
114 122 puts "----------------------"
115 123 end
116   - return false
  124 + false
117 125 end
118 126
119 127 end
5 lib/tasks/provision.rake
@@ -21,4 +21,9 @@ namespace :provision do
21 21 task :destroy do
22 22 RelevanceRails::Provision.destroy_ec2
23 23 end
  24 +
  25 + desc 'Return the current public DNS name for your previously-provisioned EC2 instance'
  26 + task :current_dns do
  27 + RelevanceRails::Provision.current_dns
  28 + end
24 29 end
33 script/ci
@@ -28,8 +28,7 @@ TARGET_HOST="placeholder.example.com"
28 28 # Setup RVM
29 29 source "$HOME/.rvm/scripts/rvm"
30 30 rvm use "ruby-1.9.2@relevance_rails"
31   -
32   -echo "DEBUG: using gemset: `rvm gemset name`"
  31 +echo "RVM is now using:` rvm current`"
33 32
34 33 # exit if any statement fails;
35 34 # must be set AFTER loading RVM
@@ -51,6 +50,7 @@ set +e
51 50 rvm --force gemset delete $RAILS_APP
52 51 rvm gemset create $RAILS_APP
53 52 rvm gemset use $RAILS_APP
  53 +echo "RVM is now using:` rvm current`"
54 54 set -e
55 55
56 56 if $(gem list relevance_rails --installed); then
@@ -68,6 +68,7 @@ relevance_rails new $RAILS_APP --database=postgresql
68 68
69 69 # NOTE: this does NOT change the RVM gemset; we set it manually above
70 70 builtin cd $RAILS_APP
  71 +echo "RVM is now using:` rvm current`"
71 72
72 73 files_must_NOT_exist public/index.html
73 74 files_must_exist config/database.yml provision/dna.json config/deploy.rb config/deploy/recipes/deploy.rb
@@ -79,25 +80,9 @@ git commit -m "Generated relevance_rails fixtures."
79 80 files_must_exist app/assets/javascripts/relevance_rails.js.coffee app/assets/stylesheets/relevance_rails.css.scss
80 81 echo "Done."
81 82
82   -# rake provision:ec2 --> writes to config/ec2_instance.txt
83   -# TARGET_HOST=something
84   -#
85   -# echo "Generating relevance_rails deployment scripts..."
86   -# ./script/rails generate deployment staging $TARGET_HOST
87   -# git add .
88   -# git commit -m "Generated relevance_rails deployment scripts."
89   -# files_must_exist config/deploy/staging.rb
90   -# echo "Done."
91   -#
92   -# cap staging deploy:setup
93   -# cap staging deploy:cold
94   -#
95   -# cd ..
96   -#
97   -# HOST=$TARGET_HOST rake acceptance
98   -
99   -# IF failure, stop the instance
100   -#cd $RAILS_APP; bundle exec rake provision:stop
101   -#IF success, terminate the instance
102   -#cd $RAILS_APP; bundle exec rake provision:terminate
103   -
  83 +echo "Generating relevance_rails deployment scripts..."
  84 +./script/rails generate deployment staging $TARGET_HOST
  85 +git add .
  86 +git commit -m "Generated relevance_rails deployment scripts for $TARGET_HOST."
  87 +files_must_exist config/deploy/staging.rb
  88 +echo "Done."
79 script/ci_nightly
... ... @@ -0,0 +1,79 @@
  1 +#!/bin/bash
  2 +
  3 +# Set the DISPLAY variable if not already set
  4 +: ${DISPLAY:=":1"}
  5 +# Allows firefox to use display
  6 +export DISPLAY
  7 +
  8 +RAILS_APP="app_for_ci"
  9 +EC2_MEMENTO_FILE="config/ec2_instance.txt"
  10 +
  11 +function stop_server_and_exit {
  12 + if [ -f $EC2_MEMENTO_FILE ]; then
  13 + echo "Stopping newly-created server..."
  14 + bundle exec rake provision:stop FORCE=true --trace
  15 + echo "Done."
  16 + fi
  17 +
  18 + echo "BUILD FAILED"
  19 + exit 1
  20 +}
  21 +
  22 +echo "RVM is now using:` rvm current`"
  23 +
  24 +set -e
  25 +./script/ci
  26 +set +e
  27 +
  28 +source "$HOME/.rvm/scripts/rvm"
  29 +rvm use "ruby-1.9.2@$RAILS_APP"
  30 +echo "RVM is now using:` rvm current`"
  31 +
  32 +builtin cd $RAILS_APP
  33 +
  34 +echo "Provisioning an EC2 instance..."
  35 +rm -f $EC2_MEMENTO_FILE
  36 +server_name="Nightly Build Testing - `date "+%Y-%m-%d %H:%M:%S"` "
  37 +bundle exec rake --trace provision:ec2 NAME="$server_name"
  38 +[ $? -ne 0 ] && stop_server_and_exit
  39 +echo "Done!"
  40 +
  41 +echo "Determine the EC2 instance's DNS name..."
  42 +TARGET_HOST=`bundle exec rake provision:current_dns`
  43 +[ $? -ne 0 ] && stop_server_and_exit
  44 +echo "Done."
  45 +
  46 +echo "Generating relevance_rails deployment scripts..."
  47 +./script/rails generate deployment staging $TARGET_HOST --force
  48 +[ $? -ne 0 ] && stop_server_and_exit
  49 +git add .
  50 +git commit -m "Generated relevance_rails deployment scripts for $TARGET_HOST."
  51 +[ $? -ne 0 ] && stop_server_and_exit
  52 +echo "Done."
  53 +
  54 +echo "Capistrano: setup..."
  55 +bundle exec cap staging deploy:setup
  56 +[ $? -ne 0 ] && stop_server_and_exit
  57 +echo "Done."
  58 +
  59 +echo "Capistrano: deploying..."
  60 +bundle exec cap staging deploy:cold
  61 +[ $? -ne 0 ] && stop_server_and_exit
  62 +echo "Done."
  63 +
  64 +builtin cd -
  65 +rvm gemset use relevance_rails
  66 +echo "RVM is now using:` rvm current`"
  67 +
  68 +echo "Running the acceptance tests against our newly-created server..."
  69 +ACCEPTANCE_HOST=$TARGET_HOST rake acceptance --trace
  70 +[ $? -ne 0 ] && stop_server_and_exit
  71 +echo "Done."
  72 +
  73 +builtin cd $RAILS_APP
  74 +rvm gemset use $RAILS_APP
  75 +
  76 +echo "Terminating our newly-created server..."
  77 +bundle exec rake provision:destroy FORCE=true --trace
  78 +echo "Done!"
  79 +
18 spec/acceptance_spec.rb
... ... @@ -1,25 +1,25 @@
1 1 require 'spec_helper'
2 2
3 3 describe 'App is alive', :js => true, :acceptance => true do
4   - it 'verifies coffeescript served up as js' do
5   - visit '/assets/relevance_rails.js'
6   - page.should have_content "console.log('Hello from Relevance, Inc!');"
7   - end
8   -
9 4 it "verifies haml is served up" do
10 5 visit '/relevance_rails'
11 6 page.should have_content 'WELCOME HOME'
12 7 end
13 8
  9 + it 'verifies coffeescript served up as js' do
  10 + visit '/assets/application.js'
  11 + page.should have_content 'console.log("Hello from Relevance, Inc!")'
  12 + end
  13 +
14 14 it "verifies scss is served up as css" do
15   - visit '/assets/relevance_rails.css'
16   - page.should have_content "background-color: blue;"
  15 + visit '/assets/application.css'
  16 + page.should have_content "background-color:blue"
17 17 end
18 18
19 19 it "verifies a working database connection" do
20 20 visit '/relevance_rails/db'
21   - within ('h1.database') do
22   - page.should have_content '_development'
  21 + within ('h1.advanced_math') do
  22 + page.should have_content '4242'
23 23 end
24 24 end
25 25 end
3  spec/spec_helper.rb
@@ -55,5 +55,4 @@ def should_abort_with(msg)
55 55
56 56 Capybara.current_driver = :selenium
57 57 Capybara.run_server = false
58   -#Capybara.app_host = 'http://' + (ENV["ACCEPTANCE_HOST"] || 'localhost:3000')
59   -Capybara.app_host = ENV["ACCEPTANCE_HOST"] || 'http://localhost:3000'
  58 +Capybara.app_host = 'http://' + (ENV["ACCEPTANCE_HOST"] || 'localhost:3000')

Showing you all comments on commits in this comparison.

Alex Redington
Owner

The changes to the fixtures_generator in this commit have caused failures when Muness took a test drive in MySQL. Instead of returning a result set, it returned a single result with no column names.

Something went wrong with that request. Please try again.