Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Template rails3_push

  • Loading branch information...
commit 6896e63b1902057d07ca904e652384ff4b07c948 1 parent bbf0601
@thomasritz thomasritz authored committed
View
11 README.textile
@@ -1,12 +1,12 @@
h2. ABOUT:
-Inploy was born as an option to setup and deploy Rails applications in an easier and smarter way.
+Inploy was born as an option to setup and deploy Rails applications in an easier and smarter way.
It executes automatically common tasks like migrate the database, install gems, package the assets, clean the cache, notify Hoptoad, restart the server, etc. This means you will not have a big deploy script calld 'recipe' like with other tools, only a simple deploy script with a few lines.
-It uses Git to version the deploys and to pull only the modifications in each one. This means you will not have a lot of folders in the server (only one) with duplicated code and that ech deploy will be very fast.
+It uses Git to version the deploys and to pull or push only the modifications in each one. This means you will not have a lot of folders in the server (only one) with duplicated code and that ech deploy will be very fast.
-It is very flexible, meaning you can create templates specifing how specific tasks must behave. As today, there are templates for Locaweb and for Rails 3.
+It is very flexible, meaning you can create templates specifing how specific tasks must behave. As today, there are templates for Locaweb, for Rails 3 using git pull and Rails 3 using git push.
It works by default with Passenger, but you can specify another servers like Mongrel, Thin and Unicorn.
@@ -61,7 +61,7 @@ When using Inploy with Rake, there are five tasks:
- migrates the database
- updates the crontab from Whenever if being used
- cleans the cache, default tmp/cache
-- cleans cached assets in public/assets if Jammit is installed
+- cleans cached assets in public/assets if Jammit is installed
- parses less files if more:parse tasks exists
- package the assets if asset:packager:build_all task exists
- notifies Hoptoad about the deploy, specifing the revision, repository and environment
@@ -77,7 +77,7 @@ When using Inploy with Rake, there are five tasks:
- migrates the database
- updates the crontab from Whenever if being used
- cleans the cache, default tmp/cache
-- cleans cached assets in public/assets if Jammit is installed
+- cleans cached assets in public/assets if Jammit is installed
- parses less files if more:parse tasks exists
- package the assets if asset:packager:build_all task exists
- notifies Hoptoad about the deploy, specifing the revision, repository and environment
@@ -152,6 +152,7 @@ Inploy is brought to you by:
* alekenji
* Erik Dahlstrand
* Carlos Brando
+ * Thomas Ritz
h2. LICENSE:
View
0  bin/inploy 100644 → 100755
File mode changed
View
2  inploy.gemspec
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
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.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.rb", "lib/tasks", "lib/tasks/inploy.rake", "bin/inploy", "Rakefile", "README.textile"]
s.homepage = %q{http://www.diegocarrion.com}
s.require_paths = ["lib"]
s.rubyforge_project = %q{inploy}
View
6 lib/inploy/deploy.rb
@@ -60,7 +60,7 @@ def remote_update
end
def local_update
- run "git pull origin #{branch}"
+ update_code
after_update_code
end
@@ -68,6 +68,10 @@ def before_restarting_server(&block)
@before_restarting_server = block
end
+ def update_code
+ run "git pull origin #{branch}"
+ end
+
private
def after_update_code
View
56 lib/inploy/templates/rails3_push.rb
@@ -0,0 +1,56 @@
+module Inploy
+ module Templates
+ module Rails3Push
+
+ def remote_setup
+ command = []
+ command << "mkdir -p #{application_path}"
+ command << "cd #{application_path}"
+ command << "git init"
+ command << "sed -i'' -e 's/master/#{branch}/' .git/HEAD" unless branch == 'master'
+ command << "git config --bool receive.denyNonFastForwards false"
+ command << "git config receive.denyCurrentBranch ignore"
+ remote_run command.join(' && ')
+
+ push_code
+
+ command = []
+ command << "cd #{application_path}"
+ command << "rake inploy:local:setup environment=#{environment}#{skip_steps_cmd}"
+ remote_run command.join(' && ')
+ end
+
+ def remote_update
+ push_code
+
+ command = []
+ command << "cd #{application_path}"
+ command << "rake inploy:local:update environment=#{environment}#{skip_steps_cmd}"
+ remote_run command.join(' && ')
+ end
+
+ def install_gems
+ end
+
+ def update_code
+ end
+
+ private
+
+ def push_code
+ hosts.each do |host|
+ run "git push #{user}@#{host}:#{application_path} #{branch}"
+ end
+
+ command = []
+ command << "cd #{application_path}"
+ command << "git reset --hard"
+ command << "git clean -f -d"
+ command << "git submodule update --init"
+ command << "bundle install"
+ remote_run command.join(' && ')
+ end
+
+ end
+ end
+end
View
57 spec/rails3_push_spec.rb
@@ -0,0 +1,57 @@
+require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
+
+describe Inploy::Deploy do
+
+ context "with template rails3_push" do
+ before :each do
+ subject.template = :rails3_push
+ subject.path = @path = "/fakie/path"
+ subject.user = @user = 'batman'
+ subject.hosts = [@host = 'gothic']
+ subject.application = @application = "robin"
+ subject.branch = @branch = 'live'
+ subject.environment = @environment = "production"
+ stub_commands
+ mute subject
+ end
+
+ context "on remote setup" do
+ 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 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'"
+ subject.remote_setup
+ end
+ end
+
+ context "on remote update" do
+ it_should_behave_like "remote update"
+
+ it "should push git repository and runs the local update on all hosts" do
+ subject.hosts = ['host0', 'host1', 'host2']
+ 3.times.each do |i|
+ expect_command "git push 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'"
+ end
+ subject.remote_update
+ end
+ end
+
+ context "on install gems" do
+ it "should not install gems (install_gems is called from rake, but rake already requires bundles)" do
+ dont_accept_command "bundle install"
+ dont_accept_command "rake gems:install RAILS_ENV=production"
+ subject.install_gems
+ end
+ end
+
+ context "on update code" do
+ it "should not git pull" do
+ dont_accept_command "git pull origin live"
+ subject.update_code
+ end
+ end
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.