Permalink
Browse files

Merge branch 'nightly-build'

  • Loading branch information...
2 parents c6f80a7 + 247775c commit 7b91ef961af6a22da9f3a7490df01cdca9d737ad Lake Denman and Sam Umbach committed Apr 12, 2012
@@ -11,7 +11,9 @@ def create_views
%h1 WELCOME HOME
STR
create_file "app/views/relevance_rails/db.html.haml", <<-STR
-%h1.database= ActiveRecord::Base.connection.current_database
+= conn = ActiveRecord::Base.connection
+= results = conn.execute("select 4200+42 as advanced_math")
+%h1.advanced_math= results.first["advanced_math"]
STR
end
@@ -6,11 +6,13 @@ module RelevanceRails
module Provision
def self.create_ec2(name = nil)
abort "Please provide a $NAME" unless name
- provision_ec2_instances(name)
+ server = provision_ec2_instances(name)
+ wait_for_ssh server
+ run_commands server
end
def self.stop_ec2
- return unless Thor::Shell::Basic.new.yes?("Are you sure you want to shut down EC2 instance #{instance_id}?")
+ return unless ENV["FORCE"] == "true" || Thor::Shell::Basic.new.yes?("Are you sure you want to shut down EC2 instance #{instance_id}?")
puts "Shutting down EC2 instance #{instance_id}..."
server = fog_connection.servers.get(instance_id)
server.stop
@@ -19,7 +21,7 @@ def self.stop_ec2
end
def self.destroy_ec2
- return unless Thor::Shell::Basic.new.yes?("Are you sure you want to destroy EC2 instance #{instance_id}?")
+ return unless ENV["FORCE"] == "true" || Thor::Shell::Basic.new.yes?("Are you sure you want to destroy EC2 instance #{instance_id}?")
puts "Destroying EC2 instance #{instance_id}..."
server = fog_connection.servers.get(instance_id)
server.destroy
@@ -29,6 +31,11 @@ def self.destroy_ec2
puts "Done!"
end
+ def self.current_dns
+ server = fog_connection.servers.get(instance_id)
+ puts server.reload.dns_name
+ end
+
private
def self.instance_id
@@ -44,19 +51,19 @@ def self.fog_connection
end
def self.provision_ec2_instances(name)
+ puts "Provisioning an instance..."
server = fog_connection.servers.create(config['server']['creation_config'])
fog_connection.tags.create(:key => 'Name',
:value => "#{Rails.application.class.parent_name} #{name}",
:resource_id => server.id)
server.private_key = config['server']['private_key']
- wait_for_ssh server
-
+
File.open("config/ec2_instance.txt", "w") do |f|
f.puts(server.id)
end
- run_commands server
- return server
+ puts "Provisioned!"
+ server
end
def self.run_commands(server)
@@ -75,6 +82,7 @@ def self.run_commands(server)
puts "Server Instance: #{server.id}"
puts "Server IP: #{server.public_ip_address}"
+ server
end
def self.run_command(server, command)
@@ -83,7 +91,7 @@ def self.run_command(server, command)
end
def self.wait_for_ssh(server)
- puts "Provisioning an instance..."
+ puts "Waiting for ssh connectivity..."
server.wait_for { ready? }
succeeded = false
attempts = 0
@@ -101,7 +109,7 @@ def self.wait_for_ssh(server)
end
end
raise last_error unless succeeded
- puts "Server up and listening for SSH..."
+ puts "Server up and listening for SSH!"
end
def self.jobs_succeeded?(jobs)
@@ -113,7 +121,7 @@ def self.jobs_succeeded?(jobs)
puts "STDERR: #{job.stderr}"
puts "----------------------"
end
- return false
+ false
end
end
View
@@ -21,4 +21,9 @@ namespace :provision do
task :destroy do
RelevanceRails::Provision.destroy_ec2
end
+
+ desc 'Return the current public DNS name for your previously-provisioned EC2 instance'
+ task :current_dns do
+ RelevanceRails::Provision.current_dns
+ end
end
View
@@ -28,8 +28,7 @@ TARGET_HOST="placeholder.example.com"
# Setup RVM
source "$HOME/.rvm/scripts/rvm"
rvm use "ruby-1.9.2@relevance_rails"
-
-echo "DEBUG: using gemset: `rvm gemset name`"
+echo "RVM is now using:` rvm current`"
# exit if any statement fails;
# must be set AFTER loading RVM
@@ -51,6 +50,7 @@ set +e
rvm --force gemset delete $RAILS_APP
rvm gemset create $RAILS_APP
rvm gemset use $RAILS_APP
+echo "RVM is now using:` rvm current`"
set -e
if $(gem list relevance_rails --installed); then
@@ -68,6 +68,7 @@ relevance_rails new $RAILS_APP --database=postgresql
# NOTE: this does NOT change the RVM gemset; we set it manually above
builtin cd $RAILS_APP
+echo "RVM is now using:` rvm current`"
files_must_NOT_exist public/index.html
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."
files_must_exist app/assets/javascripts/relevance_rails.js.coffee app/assets/stylesheets/relevance_rails.css.scss
echo "Done."
-# rake provision:ec2 --> writes to config/ec2_instance.txt
-# TARGET_HOST=something
-#
-# echo "Generating relevance_rails deployment scripts..."
-# ./script/rails generate deployment staging $TARGET_HOST
-# git add .
-# git commit -m "Generated relevance_rails deployment scripts."
-# files_must_exist config/deploy/staging.rb
-# echo "Done."
-#
-# cap staging deploy:setup
-# cap staging deploy:cold
-#
-# cd ..
-#
-# HOST=$TARGET_HOST rake acceptance
-
-# IF failure, stop the instance
-#cd $RAILS_APP; bundle exec rake provision:stop
-#IF success, terminate the instance
-#cd $RAILS_APP; bundle exec rake provision:terminate
-
+echo "Generating relevance_rails deployment scripts..."
+./script/rails generate deployment staging $TARGET_HOST
+git add .
+git commit -m "Generated relevance_rails deployment scripts for $TARGET_HOST."
+files_must_exist config/deploy/staging.rb
+echo "Done."
View
@@ -0,0 +1,79 @@
+#!/bin/bash
+
+# Set the DISPLAY variable if not already set
+: ${DISPLAY:=":1"}
+# Allows firefox to use display
+export DISPLAY
+
+RAILS_APP="app_for_ci"
+EC2_MEMENTO_FILE="config/ec2_instance.txt"
+
+function stop_server_and_exit {
+ if [ -f $EC2_MEMENTO_FILE ]; then
+ echo "Stopping newly-created server..."
+ bundle exec rake provision:stop FORCE=true --trace
+ echo "Done."
+ fi
+
+ echo "BUILD FAILED"
+ exit 1
+}
+
+echo "RVM is now using:` rvm current`"
+
+set -e
+./script/ci
+set +e
+
+source "$HOME/.rvm/scripts/rvm"
+rvm use "ruby-1.9.2@$RAILS_APP"
+echo "RVM is now using:` rvm current`"
+
+builtin cd $RAILS_APP
+
+echo "Provisioning an EC2 instance..."
+rm -f $EC2_MEMENTO_FILE
+server_name="Nightly Build Testing - `date "+%Y-%m-%d %H:%M:%S"` "
+bundle exec rake --trace provision:ec2 NAME="$server_name"
+[ $? -ne 0 ] && stop_server_and_exit
+echo "Done!"
+
+echo "Determine the EC2 instance's DNS name..."
+TARGET_HOST=`bundle exec rake provision:current_dns`
+[ $? -ne 0 ] && stop_server_and_exit
+echo "Done."
+
+echo "Generating relevance_rails deployment scripts..."
+./script/rails generate deployment staging $TARGET_HOST --force
+[ $? -ne 0 ] && stop_server_and_exit
+git add .
+git commit -m "Generated relevance_rails deployment scripts for $TARGET_HOST."
+[ $? -ne 0 ] && stop_server_and_exit
+echo "Done."
+
+echo "Capistrano: setup..."
+bundle exec cap staging deploy:setup
+[ $? -ne 0 ] && stop_server_and_exit
+echo "Done."
+
+echo "Capistrano: deploying..."
+bundle exec cap staging deploy:cold
+[ $? -ne 0 ] && stop_server_and_exit
+echo "Done."
+
+builtin cd -
+rvm gemset use relevance_rails
+echo "RVM is now using:` rvm current`"
+
+echo "Running the acceptance tests against our newly-created server..."
+ACCEPTANCE_HOST=$TARGET_HOST rake acceptance --trace
+[ $? -ne 0 ] && stop_server_and_exit
+echo "Done."
+
+builtin cd $RAILS_APP
+rvm gemset use $RAILS_APP
+
+echo "Terminating our newly-created server..."
+bundle exec rake provision:destroy FORCE=true --trace
+echo "Done!"
+
View
@@ -1,25 +1,25 @@
require 'spec_helper'
describe 'App is alive', :js => true, :acceptance => true do
- it 'verifies coffeescript served up as js' do
- visit '/assets/relevance_rails.js'
- page.should have_content "console.log('Hello from Relevance, Inc!');"
- end
-
it "verifies haml is served up" do
visit '/relevance_rails'
page.should have_content 'WELCOME HOME'
end
+ it 'verifies coffeescript served up as js' do
+ visit '/assets/application.js'
+ page.should have_content 'console.log("Hello from Relevance, Inc!")'
+ end
+
it "verifies scss is served up as css" do
- visit '/assets/relevance_rails.css'
- page.should have_content "background-color: blue;"
+ visit '/assets/application.css'
+ page.should have_content "background-color:blue"
end
it "verifies a working database connection" do
visit '/relevance_rails/db'
- within ('h1.database') do
- page.should have_content '_development'
+ within ('h1.advanced_math') do
+ page.should have_content '4242'
end
end
end
View
@@ -55,5 +55,4 @@ def should_abort_with(msg)
Capybara.current_driver = :selenium
Capybara.run_server = false
-#Capybara.app_host = 'http://' + (ENV["ACCEPTANCE_HOST"] || 'localhost:3000')
-Capybara.app_host = ENV["ACCEPTANCE_HOST"] || 'http://localhost:3000'
+Capybara.app_host = 'http://' + (ENV["ACCEPTANCE_HOST"] || 'localhost:3000')

0 comments on commit 7b91ef9

Please sign in to comment.