Module: Capistrano::Fanfare::Bundler

Defined in:
lib/capistrano/fanfare/bundler.rb

Class Method Summary (collapse)

Class Method Details

+ (Object) load_into(configuration)



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/capistrano/fanfare/bundler.rb', line 4

def self.load_into(configuration)
  configuration.load do
    set :bundle_cmd,      "bundle"
    set :bundle_shebang,  "ruby-local-exec"

    set(:default_environment) {
      { 'PATH' => "#{current_path}/bin:$PATH" }
    }

    set(:bundle_flags) do
      flags = "--deployment"
      flags << " --quiet" unless ENV['VERBOSE']
      flags << " --binstubs"
      flags << " --shebang #{bundle_shebang}"
      flags
    end

    set(:bundle_without) do
      without = [:development, :test]
      if exists?(:os_type) && exists?(:os_types)
        without += (fetch(:os_types) - Array(fetch(:os_type)))
      end
      without
    end

    set :bundle_binstub_template do
      <<-BINSTUB.gsub(/^ {10}/, '')
        #!/usr/bin/env #{bundle_shebang}
        #
        # This file was generated by capistrano.
        #

        require 'pathname'
        ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
          Pathname.new(__FILE__).realpath)

        require 'rubygems'

        load Gem.bin_path('bundler', 'bundle')
      BINSTUB
    end

    require 'bundler/capistrano'

    set(:rake) { "rake" }

    # =========================================================================
    # These are the tasks that are available to help with deploying web apps.
    # You can have cap give you a summary of them with `cap -T'.
    # =========================================================================

    namespace :bundle do
      desc <<-DESC
        [internal] Creates a binstub script for the bundle command.
      DESC
      task :create_binstub_script, :roles => :app, :except => { :no_release => true } do
        run "mkdir -p #{shared_path}/bin"
        put bundle_binstub_template, "#{shared_path}/bin/bundle", { :mode => "0755" }
      end

      desc <<-DESC
        [internal] Copies bin/bundle from shared_path into current_path.
      DESC
      task :cp_bundle_binstub, :roles => :app, :except => { :no_release => true } do
        run [
          "mkdir -p #{current_path}/bin",
          "cp #{shared_path}/bin/bundle #{current_path}/bin/bundle",
          "chmod 0755 #{current_path}/bin/bundle"
        ].join(" && ")
      end
    end

    after "deploy:setup", "bundle:create_binstub_script"
    before "deploy:finalize_update", "bundle:cp_bundle_binstub"
  end
end