Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Better bundler support, including support for Gemfiles with :git sour…

…ces,

 as long as :bundler_git_command is set to a Windows installation of git.

Simplified the code for running ruby commands
Setting ruby_exe_path is no longer needed; we find it in the system PATH instead.
  • Loading branch information...
commit c7fa9946ec97f1867e68a4784ce7099b2fe9aae5 1 parent 0dab573
Edward Anderson nilbus authored
Showing with 48 additions and 49 deletions.
  1. +6 −6 README.md
  2. +42 −43 lib/capistrano/ext/windows_server.rb
12 README.md
View
@@ -99,12 +99,12 @@ There are a few configuration values that need to be set in your deploy.rb, in a
set :rails_env, 'production'
set :user, 'git'
- set :deploy_to, "/cygdrive/c/rails_apps/#{application}" # Deploy to C:\rails_apps\#{application}
- set :mongrel_instances, (1..3) # Create 3 mongrel instances
- set :mongrel_instance_prefix, 'mongrel_' # named mongrel_{1..3}
- set :base_port, 8000 # on ports 8000, 8001, 8002
-
- set :ruby_exe_path, '/cygdrive/c/ruby/bin/ruby' # This should be set to the location where Ruby is installed.
+ set :deploy_to, "/cygdrive/c/rails_apps/#{application}" # Deploy to C:\rails_apps\#{application}
+ set :mongrel_instances, (1..3) # Create 3 mongrel instances
+ set :mongrel_instance_prefix, 'mongrel_' # named mongrel_{1..3}
+ set :base_port, 8000 # on ports 8000, 8001, 8002
+ set :bundler_git_command, '/cygdrive/c/RailsInstaller/Git/bin/git.exe' # Specify the remote location of a Windows installation of git
+ # Required only when your Gemfile pulls gems from a git repository
Your final config/deploy.rb might look something like this:
85 lib/capistrano/ext/windows_server.rb
View
@@ -10,6 +10,7 @@
set :repository_cache, "current"
set :scm_verbose, true
set :use_sudo, false
+ set :default_shell, false
def strip_cygdrive(path)
path.sub /\/cygdrive\/([c-z])\//, '\1:/'
@@ -18,28 +19,31 @@ def strip_cygdrive(path)
def latest_release
strip_cygdrive current_path
end
-
- # We can't run ruby commands directly, because the rake script searches for ruby based on windows paths that aren't valid in this environment
- def ruby_cmd(cmd, gem_name=cmd)
- %Q(PATH="#{File.dirname ruby_exe_path}:$PATH" #{ruby_exe_path} -e "require 'rubygems'; gem '#{gem_name}', '>= 0'; load Gem.bin_path('#{gem_name}', '#{cmd}', '>= 0')")
+
+ def system_path
+ return @system_path if @system_path
+ run 'echo "/bin:/usr/bin:$PATH"' do |channel, stream, data|
+ return @system_path = data.strip # Probably not compatible with multiple run targets with different PATHs
+ end
end
- def run_ruby_cmd(cmd, args='', gem_name=cmd)
- run "cd #{current_path} && #{ruby_cmd cmd, gem_name} #{args}"
+ task :path do
+ puts system_path.inspect
end
-
- def bundle_exec(cmd, args='', gem_name=cmd)
+
+ def run_ruby_cmd(cmd)
+ bundler_git_path = "#{File.dirname(bundler_git_command)}:" rescue nil
+ run "cd #{current_path} && PATH='#{bundler_git_path}#{system_path}' ruby -S #{cmd}"
+ end
+
+ def bundle_exec(cmd)
if gemfile_present?
- run_ruby_cmd 'bundle', "exec #{cmd} #{args}", 'bundler'
+ run_ruby_cmd "bundle exec #{cmd}"
else
- run_ruby_cmd cmd, args, gem_name
+ run_ruby_cmd cmd
end
end
- def rubygems_cmd
- "PATH=\"#{File.dirname ruby_exe_path}:$PATH\" #{ruby_exe_path} -e \"require 'rubygems';require 'rubygems/gem_runner';require 'rubygems/exceptions';Gem::GemRunner.new.run ARGV.clone\""
- end
-
def application_server
app_server rescue :mongrel
end
@@ -53,14 +57,14 @@ def gemfile_present?
task :update_code do
# update_repository_cache will attempt to clean out the repository; we must prevent that.
# /bin/git below is where www.windowsgit.com's windows git/ssh installation puts the git executable.
- # This creates a git proxy that goes in $PATH before /bin, which will filter out any `git clean` commands.
- run "mkdir -p '#{shared_path}/bin'"
+ # This creates a git wrapper that goes in $PATH before /bin, which will filter out any `git clean` commands.
+ run "/bin/mkdir -p '#{shared_path}/bin'"
run <<-RUN
echo 'if [ "$1" != "clean" ]; then /bin/git $*; fi' > "#{shared_path}/bin/git.exe"
RUN
alter_path_cmd = "export PATH=#{shared_path}/bin:$PATH # Required for capistrano-windows-server"
run <<-RUN
- if ! grep '#{alter_path_cmd}' ~/.bashrc > /dev/null; then echo '#{alter_path_cmd}' >> ~/.bashrc; fi
+ if ! /bin/grep '#{alter_path_cmd}' ~/.bashrc > /dev/null; then echo '#{alter_path_cmd}' >> ~/.bashrc; fi
RUN
strategy.send 'update_repository_cache'
@@ -81,10 +85,10 @@ def gemfile_present?
DESC
task :setup do
dirs = [deploy_to]
- run "mkdir -p #{dirs.join(' ')} && chmod g+w #{dirs.join(' ')}"
+ run "/bin/mkdir -p #{dirs.join(' ')} && /bin/chmod g+w #{dirs.join(' ')}"
if exists?(:repository_host_key)
- run "if ! grep '#{repository_host_key}' ~/.ssh/known_hosts > /dev/null; then echo '#{repository_host_key}' >> ~/.ssh/known_hosts; fi"
+ run "if ! /bin/grep '#{repository_host_key}' ~/.ssh/known_hosts > /dev/null; then echo '#{repository_host_key}' >> ~/.ssh/known_hosts; fi"
end
end
@@ -98,9 +102,9 @@ def gemfile_present?
end
end
- desc "Run pending migrations"
+ desc "Run pending migrations. Override the default rails environment with RAILS_ENV"
task :migrate do
- bundle_exec 'rake', "db:migrate RAILS_ENV=#{rails_env}"
+ bundle_exec "rake db:migrate RAILS_ENV=#{ENV['RAILS_ENV'] || rails_env}"
end
desc "Start mongrel"
@@ -133,8 +137,8 @@ def gemfile_present?
task :setup do
return unless application_server == :mongrel
mongrel_instances.each do |n|
- run "mkdir -p #{current_path}/{tmp,log}" # These are often not under version control, but their absence keeps mongrel from recognizing the rails app
- bundle_exec 'mongrel_rails', "service::install -e #{rails_env} -N #{mongrel_instance_prefix}#{n} -p #{base_port + n - mongrel_instances.first}; true", 'mongrel'
+ run "/bin/mkdir -p #{current_path}/{tmp,log}" # These are often not under version control, but their absence keeps mongrel from recognizing the rails app
+ bundle_exec "mongrel_rails service::install -e #{rails_env} -N #{mongrel_instance_prefix}#{n} -p #{base_port + n - mongrel_instances.first}; true"
run %Q(sc.exe config "#{mongrel_instance_prefix}#{n}" start= auto type= interact type= own; true)
end
end
@@ -142,47 +146,42 @@ def gemfile_present?
desc "Remove mongrel services"
task :remove do
mongrel_instances.each do |n|
- bundle_exec 'mongrel_rails', "service::remove -N #{mongrel_instance_prefix}#{n}; true", 'mongrel'
+ bundle_exec "mongrel_rails service::remove -N #{mongrel_instance_prefix}#{n}; true"
end
end
-
end
-
end
- desc "Run a rake command in COMMAND"
+ desc "Run a rake command in COMMAND. RAILS_ENV for the configured environment will be included; it can be overridden by setting RAILS_ENV"
task :rake do
raise "Specify the command with COMMAND='some:task with_arguments'" unless ENV['COMMAND']
- bundle_exec 'rake', "#{ENV['COMMAND']} RAILS_ENV=#{rails_env}"
+ bundle_exec "rake #{ENV['COMMAND']} RAILS_ENV=#{ENV['RAILS_ENV'] || rails_env}"
end
desc "Run a rubygems (gem) command in COMMAND"
task :rubygems do
raise "Specify the command with COMMAND='install rails'" unless ENV['COMMAND']
- run "cd #{current_path} && #{rubygems_cmd} #{ENV['COMMAND']}"
+ bundle_exec "gem #{ENV['COMMAND']}"
end
- namespace :git do
- desc "Run a git command in COMMAND"
- task :execute do
- raise "Specify the command with COMMAND. eg: COMMAND='diff HEAD^^'" unless ENV['COMMAND']
- run "cd #{current_path} && git #{ENV['COMMAND']}"
- end
+ desc "Run a git command in COMMAND"
+ task :git do
+ raise "Specify the command with COMMAND. eg: COMMAND='diff HEAD^^'" unless ENV['COMMAND']
+ run "cd #{current_path} && /bin/git #{ENV['COMMAND']}"
end
namespace :bundle do
- desc "Install gems with bundler"
- task :install do
+ desc "Execute a COMMAND with bundle exec"
+ task :default do
raise "No Gemfile detected" unless gemfile_present?
- run_ruby_cmd 'bundle', "install --without test development --path #{strip_cygdrive deploy_to}/bundle", 'bundler'
+ raise "Specify the command with COMMAND. eg: COMMAND='rake db:migrate'" unless ENV['COMMAND']
+ bundle_exec ENV['COMMAND']
end
- desc "Execute a COMMAND with bundle exec"
- task :execute do
+ desc "Install gems with bundler"
+ task :install do
raise "No Gemfile detected" unless gemfile_present?
- raise "Specify the command with COMMAND. eg: COMMAND='rake db:migrate'" unless ENV['COMMAND']
- args = ENV['COMMAND'].split
- bundle_exec args.shift, args.join(' ')
+ run_ruby_cmd "bundle install --without test development --path ../bundle"
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.