Skip to content

Commit

Permalink
Fix conflicts.
Browse files Browse the repository at this point in the history
  • Loading branch information
jtadeulopes committed Dec 14, 2010
2 parents 8941d1a + 21aa202 commit 9b28e04
Show file tree
Hide file tree
Showing 21 changed files with 152 additions and 50 deletions.
6 changes: 6 additions & 0 deletions Gemfile
@@ -0,0 +1,6 @@
source :rubygems

gem 'rake'
gem 'rspec', '>= 2.1.0'
gem 'rcov', '>= 0.9.7'
gem 'fakefs', '>= 0.2.1'
24 changes: 24 additions & 0 deletions Gemfile.lock
@@ -0,0 +1,24 @@
GEM
remote: http://rubygems.org/
specs:
diff-lcs (1.1.2)
fakefs (0.2.1)
rake (0.8.7)
rcov (0.9.9)
rspec (2.1.0)
rspec-core (~> 2.1.0)
rspec-expectations (~> 2.1.0)
rspec-mocks (~> 2.1.0)
rspec-core (2.1.0)
rspec-expectations (2.1.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.1.0)

PLATFORMS
ruby

DEPENDENCIES
fakefs (>= 0.2.1)
rake
rcov (>= 0.9.7)
rspec (>= 2.1.0)
9 changes: 9 additions & 0 deletions README.textile
Expand Up @@ -26,6 +26,14 @@ As a gem:

Please remember that when used as a gem, Inploy should be available in the deploy servers.

h3. Rails 2.3.x note

When using rails 2.3.x, you should include the follow line into you Rakefile:

<pre><code>##### Rakefile
load "tasks/inploy.rake"
</code></pre>

h2. USAGE

When using Inploy with Rake, there are five tasks:
Expand Down Expand Up @@ -117,6 +125,7 @@ sudo = true # default false
cache_dirs = ['public/cache', 'tmp/cache'] # default ['public/cache']
skip_steps = ['install_gems', 'clear_cache'] # default []
app_folder = 'project_folder' # default empty
login_shell = true # default false
</code></pre>

h2. SKIP STEPS
Expand Down
14 changes: 6 additions & 8 deletions Rakefile
Expand Up @@ -2,11 +2,11 @@ require 'rubygems'
require 'rubygems/specification'
require 'rake'
require 'rake/gempackagetask'
require 'spec/rake/spectask'
require 'rspec/core/rake_task'

GEM = "inploy"
GEM_VERSION = "1.6.8"
SUMMARY = "Rails deployment made easy"
GEM_VERSION = "1.8"
SUMMARY = "Rails and Sinatra deployment made easy"
AUTHOR = "Diego Carrion"
EMAIL = "dc.rec1@gmail.com"
HOMEPAGE = "http://www.diegocarrion.com"
Expand All @@ -26,9 +26,8 @@ spec = Gem::Specification.new do |s|
s.rubyforge_project = GEM # GitHub bug, gem isn't being build when this miss
end

Spec::Rake::SpecTask.new do |t|
t.spec_files = FileList['spec/**/*_spec.rb']
t.spec_opts = %w(-fp --color)
RSpec::Core::RakeTask.new :spec do |t|
t.rspec_opts = %w(-fp --color)
end

Rake::GemPackageTask.new(spec) do |pkg|
Expand All @@ -48,8 +47,7 @@ task :make_spec do
end

desc "Run all examples with RCov"
Spec::Rake::SpecTask.new('rcov') do |t|
t.spec_files = FileList['spec/**/*_spec.rb']
RSpec::Core::RakeTask.new :spec do |t|
t.rcov = true
t.rcov_opts = ['--no-html', '-T', '--exclude', 'spec']
end
Expand Down
8 changes: 4 additions & 4 deletions inploy.gemspec
Expand Up @@ -2,20 +2,20 @@

Gem::Specification.new do |s|
s.name = %q{inploy}
s.version = "1.6.8"
s.version = "1.8"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Diego Carrion"]
s.date = %q{2010-08-18}
s.date = %q{2010-12-14}
s.default_executable = %q{inploy}
s.email = %q{dc.rec1@gmail.com}
s.executables = ["inploy"]
s.files = ["lib/inploy", "lib/inploy/cli.rb", "lib/inploy/deploy.rb", "lib/inploy/dsl.rb", "lib/inploy/helper.rb", "lib/inploy/servers", "lib/inploy/servers/mongrel.rb", "lib/inploy/servers/passenger.rb", "lib/inploy/servers/thin.rb", "lib/inploy/servers/unicorn.rb", "lib/inploy/templates", "lib/inploy/templates/locaweb.rb", "lib/inploy/templates/rails3.rb", "lib/inploy/templates/rails3_push.rb", "lib/inploy.rb", "lib/tasks", "lib/tasks/inploy.rake", "bin/inploy", "Rakefile", "README.textile"]
s.files = ["lib/inploy", "lib/inploy/cli.rb", "lib/inploy/deploy.rb", "lib/inploy/dsl.rb", "lib/inploy/helper.rb", "lib/inploy/servers", "lib/inploy/servers/mongrel.rb", "lib/inploy/servers/passenger.rb", "lib/inploy/servers/thin.rb", "lib/inploy/servers/unicorn.rb", "lib/inploy/templates", "lib/inploy/templates/locaweb.rb", "lib/inploy/templates/rails3.rb", "lib/inploy/templates/rails3_push.rb", "lib/inploy/templates/sinatra.rb", "lib/inploy.rb", "lib/tasks", "lib/tasks/inploy.rake", "bin/inploy", "Gemfile", "Gemfile.lock", "Rakefile", "README.textile"]
s.homepage = %q{http://www.diegocarrion.com}
s.require_paths = ["lib"]
s.rubyforge_project = %q{inploy}
s.rubygems_version = %q{1.3.7}
s.summary = %q{Rails deployment made easy}
s.summary = %q{Rails and Sinatra deployment made easy}

if s.respond_to? :specification_version then
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
Expand Down
3 changes: 2 additions & 1 deletion lib/inploy/cli.rb
Expand Up @@ -16,7 +16,8 @@ def self.execute(params)

def self.parse(param)
if param.include? '='
{ :from => param.sub("from=", "") }
keys = param.split "="
{ keys.first.to_sym => keys.last }
else
param
end
Expand Down
12 changes: 8 additions & 4 deletions lib/inploy/deploy.rb
Expand Up @@ -4,7 +4,7 @@ class Deploy
include DSL

attr_accessor :repository, :user, :application, :hosts, :path, :app_folder, :ssh_opts, :branch, :environment,
:port, :skip_steps, :cache_dirs, :sudo
:port, :skip_steps, :cache_dirs, :sudo, :login_shell

define_callbacks :after_setup, :before_restarting_server

Expand Down Expand Up @@ -41,11 +41,11 @@ def remote_install(opts)
end

def remote_setup
remote_run "cd #{path} && #{@sudo}git clone --depth 1 #{repository} #{application} && cd #{application_folder} #{checkout}#{bundle} && #{@sudo}rake inploy:local:setup environment=#{environment}#{skip_steps_cmd}"
remote_run "cd #{path} && #{@sudo}git clone --depth 1 #{repository} #{application} && cd #{application_folder} #{checkout}#{bundle} && #{@sudo}rake inploy:local:setup RAILS_ENV=#{environment} environment=#{environment}#{skip_steps_cmd}"
end

def local_setup
create_folders 'tmp/pids', 'db'
create_folders 'public', 'tmp/pids', 'db'
copy_sample_files
rake "db:create RAILS_ENV=#{environment}"
run "./init.sh" if file_exists?("init.sh")
Expand All @@ -54,13 +54,17 @@ def local_setup
end

def remote_update
remote_run "cd #{application_path} && #{@sudo}rake inploy:local:update environment=#{environment}#{skip_steps_cmd}"
remote_run "cd #{application_path} && #{@sudo}rake inploy:local:update RAILS_ENV=#{environment} environment=#{environment}#{skip_steps_cmd}"
end

def remote_rake(task)
remote_run "cd #{application_path} && rake #{task} RAILS_ENV=#{environment}"
end

def remote_reset(params)
remote_run "cd #{application_path} && git reset --hard #{params[:to]}"
end

def local_update
update_code
after_update_code
Expand Down
6 changes: 5 additions & 1 deletion lib/inploy/dsl.rb
Expand Up @@ -69,10 +69,14 @@ def run(command, disable_sudo = false)
def remote_run(command)
port_opts = port ? "-p #{port} " : ''
hosts.each do |host|
run "ssh #{ssh_opts} #{port_opts}#{user}@#{host} '#{command}'", true
run "ssh #{ssh_opts} #{port_opts}#{user}@#{host} #{login_shell_wrap(command)}", true
end
end

def login_shell_wrap(cmd)
login_shell ? "\"bash -l -c '#{cmd}'\"" : "'#{cmd}'"
end

def secure_copy(src, dest)
unless file_exists?(dest)
log "mv #{src} #{dest}"
Expand Down
4 changes: 2 additions & 2 deletions lib/inploy/helper.rb
Expand Up @@ -57,11 +57,11 @@ def tasks
end

def bundle_cmd
"bundle install ~/.bundle --without development test"
"bundle install --path ~/.bundle --without development test cucumber"
end

def bundle_install
run bundle_cmd
run bundle_cmd unless skip_step?('bundle_install')
end

def install_gems
Expand Down
4 changes: 2 additions & 2 deletions lib/inploy/templates/locaweb.rb
Expand Up @@ -6,12 +6,12 @@ def self.extended(base)
end

def remote_setup
run "rm -Rf #{tmp_path} && git clone . #{tmp_path} && tar czf - #{tmp_path} | ssh #{user}@#{host} 'tar xzfv - -C ~/ && mv ~#{tmp_path} #{path}/ && cd #{application_path} && rake inploy:local:setup'"
run "rm -Rf #{tmp_path} && git clone . #{tmp_path} && tar czf - #{tmp_path} | ssh #{user}@#{host} 'tar xzfv - -C ~/ && mv ~#{tmp_path} #{path}/ && cd #{application_path} && rake inploy:local:setup RAILS_ENV=#{environment} environment=#{environment}'"
end

def remote_update
run "git push ssh://[#{user}@#{host}#{port ? ":#{port}" : ''}]#{application_path} #{branch}"
remote_run "cd #{application_path} && git checkout -f && rake inploy:local:update environment=#{environment}"
remote_run "cd #{application_path} && git checkout -f && rake inploy:local:update RAILS_ENV=#{environment} environment=#{environment}"
end

def local_setup
Expand Down
8 changes: 4 additions & 4 deletions lib/inploy/templates/rails3_push.rb
Expand Up @@ -16,7 +16,7 @@ def remote_setup

command = []
command << "cd #{application_path}"
command << "rake inploy:local:setup environment=#{environment}#{skip_steps_cmd}"
command << "rake inploy:local:setup RAILS_ENV=#{environment} environment=#{environment}#{skip_steps_cmd}"
remote_run command.join(' && ')
end

Expand All @@ -25,7 +25,7 @@ def remote_update

command = []
command << "cd #{application_path}"
command << "rake inploy:local:update environment=#{environment}#{skip_steps_cmd}"
command << "rake inploy:local:update RAILS_ENV=#{environment} environment=#{environment}#{skip_steps_cmd}"
remote_run command.join(' && ')
end

Expand All @@ -45,9 +45,9 @@ def push_code
command = []
command << "cd #{application_path}"
command << "git reset --hard"
command << "git clean -f -d"
command << "git clean -f -d -e public/system" # Keeps paperclip uploaded files
command << "git submodule update --init"
command << "bundle install"
command << "bundle install --deployment" unless skip_step?('bundle_install')
remote_run command.join(' && ')
end

Expand Down
6 changes: 6 additions & 0 deletions lib/inploy/templates/sinatra.rb
@@ -0,0 +1,6 @@
module Inploy
module Templates
module Sinatra
end
end
end
6 changes: 6 additions & 0 deletions lib/tasks/inploy.rake
Expand Up @@ -6,6 +6,7 @@ deploy = Inploy::Deploy.new
deploy.environment = ENV['environment'] || deploy.environment
deploy.skip_steps = ENV['skip_steps'].split(',') unless ENV['skip_steps'].nil?


namespace :inploy do
namespace :local do
desc "Local Setup"
Expand Down Expand Up @@ -39,3 +40,8 @@ namespace :inploy do
desc "Alias to Remote Update"
task :up => "remote:update"
end

namespace :in do
desc "Alias to Remote Update"
task :up => "inploy:remote:update"
end
5 changes: 5 additions & 0 deletions spec/cli_spec.rb
Expand Up @@ -33,5 +33,10 @@
@deploy.should_receive(:remote_rake).with('db:migrate')
subject.class.execute %w(rake db:migrate)
end

it "should execute deploy.remote_reset :to => commit when params = ['reset', 'to=commit']" do
@deploy.should_receive(:remote_reset).with(:to => '12345')
subject.class.execute %w(reset to=12345)
end
end
end
20 changes: 14 additions & 6 deletions spec/deploy_spec.rb
Expand Up @@ -11,9 +11,9 @@ def expect_setup_with(branch, environment = 'production', skip_steps = nil, bund
checkout = "&& $(git branch | grep -vq #{branch}) && git checkout -f -b #{branch} origin/#{branch}"
end
skip_steps_cmd = " skip_steps=#{skip_steps.join(',')}" unless skip_steps.nil?
bundler_cmd = " && bundle install ~/.bundle --without development test" if bundler
bundler_cmd = " && bundle install --path ~/.bundle --without development test cucumber" if bundler
directory = app_folder.nil? ? @application : "#{@application}/#{app_folder}"
expect_command "ssh #{@ssh_opts} #{@user}@#{@host} 'cd #{@path} && git clone --depth 1 #{@repository} #{@application} && cd #{directory} #{checkout}#{bundler_cmd} && rake inploy:local:setup environment=#{environment}#{skip_steps_cmd}'"
expect_command "ssh #{@ssh_opts} #{@user}@#{@host} 'cd #{@path} && git clone --depth 1 #{@repository} #{@application} && cd #{directory} #{checkout}#{bundler_cmd} && rake inploy:local:setup RAILS_ENV=#{environment} environment=#{environment}#{skip_steps_cmd}'"
end

def setup(subject)
Expand Down Expand Up @@ -87,6 +87,7 @@ def setup(subject)
subject.ssh_opts = @ssh_opts = "-A"
subject.branch = @branch = "onions"
subject.environment = @environment = "staging"
subject.login_shell = @login_shell = false
end

context "on remote setup" do
Expand All @@ -101,7 +102,7 @@ def setup(subject)
end

it "should pass skip_steps params to local setup" do
subject.skip_steps = %w(migrate_database gems_install)
subject.skip_steps = %w(migrate_database gems_install bundle_install)
expect_setup_with @branch, @environment, subject.skip_steps
subject.remote_setup
end
Expand All @@ -121,7 +122,6 @@ def setup(subject)
end

context "on local setup" do

it "should use staging for the environment" do
expect_command "rake db:migrate RAILS_ENV=staging"
subject.local_setup
Expand All @@ -136,14 +136,14 @@ def setup(subject)
it "should exec the commands in all hosts" do
subject.hosts = ['host0', 'host1', 'host2']
3.times.each do |i|
expect_command "ssh #{@ssh_opts} #{@user}@host#{i} 'cd #{@path}/#{@application} && rake inploy:local:update environment=#{@environment}'"
expect_command "ssh #{@ssh_opts} #{@user}@host#{i} 'cd #{@path}/#{@application} && rake inploy:local:update RAILS_ENV=#{@environment} environment=#{@environment}'"
end
subject.remote_update
end

it "should exec the commands in the app_folder" do
subject.app_folder = 'project'
expect_command "ssh #{@ssh_opts} #{@user}@#{@host} 'cd #{@path}/#{@application}/#{subject.app_folder} && rake inploy:local:update environment=#{@environment}'"
expect_command "ssh #{@ssh_opts} #{@user}@#{@host} 'cd #{@path}/#{@application}/#{subject.app_folder} && rake inploy:local:update RAILS_ENV=#{@environment} environment=#{@environment}'"
subject.remote_update
end

Expand Down Expand Up @@ -183,6 +183,14 @@ def setup(subject)
subject.remote_rake task
end
end

context "on remote reset" do
it "should execute 'git reset --hard {:to}' in the servers" do
commit = "fa3ed118970d8ddb0655be94b4c85d996c695476"
expect_command "ssh #{@ssh_opts} #{@user}@#{@host} 'cd #{@path}/#{@application} && git reset --hard #{commit}'"
subject.remote_reset :to => commit
end
end
end

context "on configure" do
Expand Down
4 changes: 2 additions & 2 deletions spec/locaweb_spec.rb
Expand Up @@ -5,7 +5,7 @@
subject { Inploy::Deploy.new }

def expect_setup_in(path)
expect_command "rm -Rf /tmp/#{@application} && git clone . /tmp/#{@application} && tar czf - /tmp/#{@application} | ssh #{@user}@#{@host} 'tar xzfv - -C ~/ && mv ~/tmp/#{@application} #{path}/ && cd #{path}/#{@application} && rake inploy:local:setup'"
expect_command "rm -Rf /tmp/#{@application} && git clone . /tmp/#{@application} && tar czf - /tmp/#{@application} | ssh #{@user}@#{@host} 'tar xzfv - -C ~/ && mv ~/tmp/#{@application} #{path}/ && cd #{path}/#{@application} && rake inploy:local:setup RAILS_ENV=#{subject.environment} environment=#{subject.environment}'"
end

context "with template locaweb" do
Expand Down Expand Up @@ -46,7 +46,7 @@ def expect_setup_in(path)

it "should run git checkout -f and inploy:local:update task in the server" do
subject.environment = "env10"
expect_command "ssh #{@ssh_opts} #{@user}@#{@host} 'cd /home/#{@user}/rails_app/#{@application} && git checkout -f && rake inploy:local:update environment=#{subject.environment}'"
expect_command "ssh #{@ssh_opts} #{@user}@#{@host} 'cd /home/#{@user}/rails_app/#{@application} && git checkout -f && rake inploy:local:update RAILS_ENV=#{subject.environment} environment=#{subject.environment}'"
subject.remote_update
end
end
Expand Down
8 changes: 4 additions & 4 deletions spec/rails3_push_spec.rb
Expand Up @@ -21,8 +21,8 @@
it "should init and configure an empty repository, push to it and run the local setup" do
expect_command "ssh #{@ssh_opts} batman@gothic 'mkdir -p /fakie/path/robin && cd /fakie/path/robin && git init && sed -i'' -e 's/master/live/' .git/HEAD && git config --bool receive.denyNonFastForwards false && git config receive.denyCurrentBranch ignore'"
expect_command "git push -f batman@gothic:/fakie/path/robin live"
expect_command "ssh #{@ssh_opts} batman@gothic 'cd /fakie/path/robin && git reset --hard && git clean -f -d && git submodule update --init && bundle install'"
expect_command "ssh #{@ssh_opts} batman@gothic 'cd /fakie/path/robin && rake inploy:local:setup environment=production'"
expect_command "ssh #{@ssh_opts} batman@gothic 'cd /fakie/path/robin && git reset --hard && git clean -f -d -e public/system && git submodule update --init && bundle install --deployment'"
expect_command "ssh #{@ssh_opts} batman@gothic 'cd /fakie/path/robin && rake inploy:local:setup RAILS_ENV=production environment=production'"
subject.remote_setup
end
end
Expand All @@ -34,8 +34,8 @@
subject.hosts = ['host0', 'host1', 'host2']
3.times.each do |i|
expect_command "git push -f batman@host#{i}:/fakie/path/robin live"
expect_command "ssh #{@ssh_opts} batman@host#{i} 'cd /fakie/path/robin && git reset --hard && git clean -f -d && git submodule update --init && bundle install'"
expect_command "ssh #{@ssh_opts} batman@host#{i} 'cd /fakie/path/robin && rake inploy:local:update environment=production'"
expect_command "ssh #{@ssh_opts} batman@host#{i} 'cd /fakie/path/robin && git reset --hard && git clean -f -d -e public/system && git submodule update --init && bundle install --deployment'"
expect_command "ssh #{@ssh_opts} batman@host#{i} 'cd /fakie/path/robin && rake inploy:local:update RAILS_ENV=production environment=production'"
end
subject.remote_update
end
Expand Down

0 comments on commit 9b28e04

Please sign in to comment.