Navigation Menu

Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Commit

Permalink
Refactored deployment recipes
Browse files Browse the repository at this point in the history
  • Loading branch information
dbloete committed Sep 14, 2010
1 parent fc4733e commit 236dc92
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 28 deletions.
18 changes: 4 additions & 14 deletions lib/bundler/capistrano.rb
Expand Up @@ -2,6 +2,7 @@
#
# Just add "require 'bundler/capistrano'" in your Capistrano deploy.rb, and
# Bundler will be activated after each new deployment.
require 'bundler/deployment'

Capistrano::Configuration.instance(:must_exist).load do
after "deploy:update_code", "bundle:install"
Expand All @@ -16,25 +17,14 @@
can not find the 'bundle' cmd then you can override the bundle_cmd \
variable to specifiy which one it should use.
set :bundle_gemfile, fetch(:latest_release)+"/Gemfile"
set :bundle_dir, fetch(:shared_path)+"/bundle"
set :bundle_gemfile, "Gemfile"
set :bundle_dir, File.join(fetch(:shared_path), 'bundle')
set :bundle_flags, "--deployment --quiet"
set :bundle_without, [:development, :test]
set :bundle_cmd, "bundle" # e.g. change to "/opt/ruby/bin/bundle"
DESC
task :install, :except => { :no_release => true } do
bundle_cmd = fetch(:bundle_cmd, "bundle")
bundle_flags = fetch(:bundle_flags, "--deployment --quiet")
bundle_without = [*fetch(:bundle_without, [:development, :test])].compact
bundle_dir = (fetch(:bundle_dir, nil) || fetch(:shared_path)+"/bundle")
bundle_gemfile = (fetch(:bundle_gemfile, nil) || fetch(:latest_release)+"/Gemfile")

args = ["--gemfile #{bundle_gemfile}"]
args << "--path #{bundle_dir}" unless bundle_dir.to_s.empty?
args << bundle_flags.to_s
args << "--without #{bundle_without.join(" ")}" unless bundle_without.empty?

run "#{bundle_cmd} install #{args.join(' ')}"
Bundler::Deployment.install_bundle(self)
end
end
end
18 changes: 18 additions & 0 deletions lib/bundler/deployment.rb
@@ -0,0 +1,18 @@
module Bundler
class Deployment
def self.install_bundle(context)
bundle_cmd = context.fetch(:bundle_cmd, "bundle")
bundle_flags = context.fetch(:bundle_flags, "--deployment --quiet")
bundle_dir = context.fetch(:bundle_dir, File.join(context.fetch(:shared_path), 'bundle'))
bundle_gemfile = context.fetch(:bundle_gemfile, "Gemfile")
bundle_without = [*context.fetch(:bundle_without, [:development, :test])].compact

args = ["--gemfile #{File.join(context.fetch(:current_release), bundle_gemfile)}"]
args << "--path #{bundle_dir}" unless bundle_dir.to_s.empty?
args << bundle_flags.to_s
args << "--without #{bundle_without.join(" ")}" unless bundle_without.empty?

context.run "#{bundle_cmd} install #{args.join(' ')}"
end
end
end
18 changes: 4 additions & 14 deletions lib/bundler/vlad.rb
Expand Up @@ -2,6 +2,7 @@
#
# Just add "require 'bundler/vlad'" in your Vlad deploy.rb, and
# Bundler will be activated after each new deployment.
require 'bundler/deployment'

namespace :vlad do
namespace :bundle do
Expand All @@ -15,24 +16,13 @@
variable to specifiy which one it should use.
set :bundle_gemfile, "Gemfile"
set :bundle_dir, File.join(shared_path, 'bundle')
set :bundle_dir, File.join(fetch(:shared_path), 'bundle')
set :bundle_flags, "--deployment --quiet"
set :bundle_without, [:development, :test]
set :bundle_cmd, "bundle" # e.g. change to "/opt/ruby/bin/bundle"
DESC
remote_task :install, :roles => :app do
bundle_dir = Rake::RemoteTask.fetch(:bundle_dir, File.join(shared_path, 'bundle'))
bundle_without = [*Rake::RemoteTask.fetch(:bundle_without, [:development, :test])].compact
bundle_flags = Rake::RemoteTask.fetch(:bundle_flags, "--deployment --quiet")
bundle_gemfile = Rake::RemoteTask.fetch(:bundle_gemfile, "Gemfile")
bundle_cmd = Rake::RemoteTask.fetch(:bundle_cmd, "bundle")

args = ["--gemfile #{File.join(current_release, bundle_gemfile)}"]
args << "--path #{bundle_dir}" unless bundle_dir.to_s.empty?
args << bundle_flags.to_s
args << "--without #{bundle_without.join(" ")}" unless bundle_without.empty?

run "#{bundle_cmd} install #{args.join(' ')}"
Bundler::Deployment.install_bundle(Rake::RemoteTask)
end
end
end
end

0 comments on commit 236dc92

Please sign in to comment.