capistrano-strategy-vagrant-copy-bundled 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ .rvmrc
2
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in capistrano-strategy-copy-bundled.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011-2012 Krzysztof Zalewski
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Capistrano Strategy: Vagrant Copy Bundled
2
+
3
+ This recipe for capistrano utilizes the regular copy strategy. However,
4
+ instead of bundling the gems on the remote servers, they are already
5
+ pre-bundled on the Vagrant virtual machine and sent as one package.
6
+
7
+ Based on [capistrano-strategy-copy-bundled by Rudolf Schmidt](https://github.com/rudionrails/capistrano-strategy-copy-bundled)
8
+
9
+ ## Installation
10
+
11
+ System wide usage
12
+
13
+ ```console
14
+ gem install 'capistrano-strategy-vagrant-copy-bundled'
15
+ ```
16
+
17
+ In your Gemfile
18
+
19
+ ```ruby
20
+ gem 'capistrano-strategy-vagrant-copy-bundled'
21
+ ```
22
+
23
+
24
+ ## Usage
25
+
26
+ As this recipe does it's own bundling, there is not need to: `require 'bundler/capistrano'`.
27
+
28
+ All you have to do in your `config/deploy.rb`:
29
+
30
+ ```ruby
31
+ require 'capistrano-strategy-vagrant-copy-bundled'
32
+ set :deploy_via, :vagrant_copy_bundled # bundle gems locally and send them packed to all servers
33
+ ```
34
+
35
+ Additionally to that, you can set the usual options when using the regular :copy strategy for capistrano, like:
36
+
37
+ ```ruby
38
+ set :copy_dir, "/tmp/#{application}" # path where files are temporarily put before sending them to the servers
39
+ set :copy_exclude, ".git*" # we exclude the .git repo so that nobody is able to temper with the release
40
+ ```
41
+
42
+ Copyright © 2012 Krzysztof Zalewski. Released under the MIT license.
43
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require 'capistrano-strategy-vagrant-copy-bundled'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "capistrano-strategy-vagrant-copy-bundled"
7
+ s.version = CapistranoStrategyVagrantCopyBundled::VERSION
8
+ s.authors = ["Krzysztof Zalewski"]
9
+ s.email = ['zlw.zalewski@gmail.com']
10
+
11
+ s.homepage = "http://github.com/zlw/capistrano-strategy-vagrant-copy-bundled"
12
+ s.summary = %q{Capistrano copy recipe to transfer files already pre-bundled via Vagrant}
13
+ s.description = %q{Bundle all gems in the copy directory via Vagrant and then send it to all servers}
14
+
15
+ s.rubyforge_project = "capistrano-strategy-vagrant-copy-bundled"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ # specify any dependencies here; for example:
23
+ # s.add_development_dependency "rspec"
24
+ s.add_runtime_dependency "capistrano", "~> 2"
25
+
26
+ s.add_development_dependency 'rake'
27
+ end
@@ -0,0 +1,3 @@
1
+ module CapistranoStrategyVagrantCopyBundled
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,133 @@
1
+ require 'capistrano/recipes/deploy/strategy/copy'
2
+
3
+ module Capistrano
4
+ module Deploy
5
+ module Strategy
6
+
7
+ class VagrantCopyBundled < Copy
8
+
9
+ def deploy!
10
+ if copy_cache
11
+ if File.exists?(copy_cache)
12
+ logger.debug "refreshing local cache to revision #{revision} at #{copy_cache}"
13
+ system(source.sync(revision, copy_cache))
14
+ else
15
+ logger.debug "preparing local cache at #{copy_cache}"
16
+ system(source.checkout(revision, copy_cache))
17
+ end
18
+
19
+ # Check the return code of last system command and rollback if not 0
20
+ unless $? == 0
21
+ raise Capistrano::Error, "shell command failed with return code #{$?}"
22
+ end
23
+
24
+ FileUtils.mkdir_p(destination)
25
+
26
+ logger.debug "copying cache to deployment staging area #{destination}"
27
+ Dir.chdir(copy_cache) do
28
+ queue = Dir.glob("*", File::FNM_DOTMATCH)
29
+ while queue.any?
30
+ item = queue.shift
31
+ name = File.basename(item)
32
+
33
+ next if name == "." || name == ".."
34
+ next if copy_exclude.any? { |pattern| File.fnmatch(pattern, item) }
35
+
36
+ if File.symlink?(item)
37
+ FileUtils.ln_s(File.readlink(item), File.join(destination, item))
38
+ elsif File.directory?(item)
39
+ queue += Dir.glob("#{item}/*", File::FNM_DOTMATCH)
40
+ FileUtils.mkdir(File.join(destination, item))
41
+ else
42
+ FileUtils.ln(item, File.join(destination, item))
43
+ end
44
+ end
45
+ end
46
+ else
47
+ logger.debug "getting (via #{copy_strategy}) revision #{revision} to #{destination}"
48
+ system(command)
49
+
50
+ if copy_exclude.any?
51
+ logger.debug "processing exclusions..."
52
+
53
+ copy_exclude.each do |pattern|
54
+ delete_list = Dir.glob(File.join(destination, pattern), File::FNM_DOTMATCH)
55
+ # avoid the /.. trap that deletes the parent directories
56
+ delete_list.delete_if { |dir| dir =~ /\/\.\.$/ }
57
+ FileUtils.rm_rf(delete_list.compact)
58
+ end
59
+ end
60
+ end
61
+
62
+ File.open(File.join(destination, "REVISION"), "w") { |f| f.puts(revision) }
63
+
64
+ # execute bundler
65
+ bundle!
66
+
67
+ logger.trace "compressing #{destination} to #{filename}"
68
+ Dir.chdir(copy_dir) { system(compress(File.basename(destination), File.basename(filename)).join(" ")) }
69
+
70
+ distribute!
71
+ ensure
72
+ FileUtils.rm filename rescue nil
73
+ FileUtils.rm_rf destination rescue nil
74
+ end
75
+
76
+
77
+ private
78
+
79
+ def bundle!
80
+ logger.trace "Vagrant VM up"
81
+ system 'vagrant up; vagrant ssh; cd /vagrant'
82
+
83
+ logger.trace "running bundler in #{destination}..."
84
+
85
+ bundle_cmd = configuration[:bundle_cmd] || "bundle"
86
+ bundle_flags = configuration[:bundle_flags] || "--deployment"
87
+ bundle_dir = configuration[:bundle_dir] || File.join('vendor', 'bundle')
88
+ bundle_gemfile = configuration[:bundle_gemfile] || File.join("Gemfile")
89
+ bundle_without = [*(configuration[:bundle_without] || [:development, :test])].compact
90
+
91
+ args = ["--gemfile #{bundle_gemfile}"]
92
+ args << "--path #{bundle_dir}" unless bundle_dir.to_s.empty?
93
+ args << bundle_flags.to_s
94
+ args << "--without #{bundle_without.join(" ")}" unless bundle_without.empty?
95
+
96
+ cmd = "#{bundle_cmd} install #{args.join(' ')}"
97
+ Dir.chdir(destination) do
98
+ defined?(Bundler) ? with_original_env { system(cmd) } : system(cmd)
99
+
100
+ # Check the return code of last system command and rollback if not 0
101
+ raise Capistrano::Error, "shell command failed with return code #{$?}" unless $? == 0
102
+ end
103
+
104
+ logger.trace "Exit Vagrant VM"
105
+ system 'exit'
106
+ end
107
+
108
+ # This method should be built-in to Bundler 1.1+
109
+ def with_original_env
110
+ original_env = ENV.to_hash
111
+
112
+ begin
113
+ # clean the ENV from Bundler settings
114
+ ENV.delete( 'RUBYOPT' )
115
+ ENV.keys.each { |k| ENV.delete(k) if k =~ /^bundle_/i } #remove any BUNDLE_* keys
116
+
117
+ yield
118
+ ensure
119
+ ENV.replace( original_env )
120
+ end
121
+ end
122
+
123
+ # Distributes the file to the remote servers
124
+ def distribute!
125
+ upload( filename, remote_filename, :via => configuration[:copy_via] || :sftp )
126
+ run "cd #{configuration[:releases_path]} && #{decompress(remote_filename).join(" ")} && rm #{remote_filename}"
127
+ end
128
+
129
+ end
130
+
131
+ end
132
+ end
133
+ end
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-strategy-vagrant-copy-bundled
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Krzysztof Zalewski
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: capistrano
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '2'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '2'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Bundle all gems in the copy directory via Vagrant and then send it to
47
+ all servers
48
+ email:
49
+ - zlw.zalewski@gmail.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - LICENSE.txt
57
+ - README.md
58
+ - Rakefile
59
+ - capistrano-strategy-vagrant-copy-bundled.gemspec
60
+ - lib/capistrano-strategy-vagrant-copy-bundled.rb
61
+ - lib/capistrano/recipes/deploy/strategy/vagrant_copy_bundled.rb
62
+ homepage: http://github.com/zlw/capistrano-strategy-vagrant-copy-bundled
63
+ licenses: []
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ segments:
75
+ - 0
76
+ hash: 2058326402076963258
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ segments:
84
+ - 0
85
+ hash: 2058326402076963258
86
+ requirements: []
87
+ rubyforge_project: capistrano-strategy-vagrant-copy-bundled
88
+ rubygems_version: 1.8.24
89
+ signing_key:
90
+ specification_version: 3
91
+ summary: Capistrano copy recipe to transfer files already pre-bundled via Vagrant
92
+ test_files: []