deb_deploy 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # deb_deploy
2
+
3
+ deb_deploy is a capistrano plugin to facilitate the deployment of debian packages (inspired by supply_drop). It works by simply copying (using rsync, or scp) your debian packages to your servers and installing them through the package manager
4
+
5
+ ### Installation
6
+
7
+ gem install deb_deploy
8
+
9
+ or with Bundler
10
+
11
+ gem 'deb_deploy'
12
+
13
+ ### Tasks
14
+
15
+ cap deb:deploy
16
+
17
+ This deploys the debian packages and does a simple apt-get install of on the target servers.
18
+
19
+ ### Configuration
20
+
21
+ At the top of your deploy.rb
22
+
23
+ require 'rubygems'
24
+ require 'deb_deploy'
25
+
26
+ then optionally set some variables
27
+
28
+ set :debian_source, '.'
29
+
30
+ the directory containing your debian packages that will be rsynced to the servers.
31
+
32
+ set :debian_target, '/tmp/deb_deploy'
33
+
34
+ the temp directory on the target machine to hold the packages before installing.
35
+
36
+ set :debian_stream_log, false
37
+
38
+ determines whether to stream the command output.
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ desc "clean"
2
+ task :clean do
3
+ rm_f Dir.glob("*.gem")
4
+ end
5
+
6
+ namespace :gem do
7
+ desc "build the gem"
8
+ task :build => :clean do
9
+ sh "gem build deb_deploy.gemspec"
10
+ end
11
+
12
+ desc "push the gem"
13
+ task :push => :build do
14
+ sh "gem push #{Dir.glob("*.gem").first}"
15
+ end
16
+ end
@@ -0,0 +1,22 @@
1
+ module DebDeploy
2
+ module Logger
3
+ class Batch
4
+ def initialize(logger)
5
+ @messages = {}
6
+ @logger = logger
7
+ end
8
+
9
+ def collect(host, data)
10
+ @messages[host] ||= ""
11
+ @messages[host] << data
12
+ end
13
+
14
+ def collected
15
+ @messages.keys.sort.each do |host|
16
+ @logger.info "Log for #{host}"
17
+ @logger.debug @messages[host], host
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,16 @@
1
+ module DebDeploy
2
+ module Logger
3
+ class Stream
4
+ def initialize(logger)
5
+ @logger = logger
6
+ end
7
+
8
+ def collect(host, data)
9
+ @logger.debug data, host
10
+ end
11
+
12
+ def collected
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,43 @@
1
+ module DebDeploy
2
+ class Rsync
3
+ class << self
4
+ def command(from, to, options={})
5
+ flags = ['-az']
6
+ flags << '--delete'
7
+ flags << includes(["*/","*.deb"])
8
+ flags << excludes(["*"])
9
+ flags << ssh_options(options[:ssh]) if options.has_key?(:ssh)
10
+
11
+ "rsync #{flags.compact.join(' ')} #{from} #{to}"
12
+ end
13
+
14
+ def remote_address(user, host, path)
15
+ user_with_host = [user, host].compact.join('@')
16
+ [user_with_host, path].join(':')
17
+ end
18
+
19
+ def excludes(patterns)
20
+ patterns.map { |p| "--exclude=#{p}" }
21
+ end
22
+
23
+
24
+ def includes(patterns)
25
+ patterns.map { |p| "--include=#{p}" }
26
+ end
27
+
28
+ def ssh_options(options)
29
+ mapped_options = options.map do |key, value|
30
+ next unless value
31
+
32
+ case key
33
+ when :keys then [value].flatten.select { |k| File.exist?(k) }.map { |k| "-i #{k}" }
34
+ when :config then "-F #{value}"
35
+ when :port then "-p #{value}"
36
+ end
37
+ end.compact
38
+
39
+ %[-e "ssh #{mapped_options.join(' ')}"] unless mapped_options.empty?
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,22 @@
1
+ module DebDeploy
2
+ class Scp
3
+ class << self
4
+ def command(from, to, options={})
5
+ flags = ['-q']
6
+ flags << '-r' if options[:recurse]
7
+ flags << ssh_options(options[:ssh]) if options.has_key?(:ssh)
8
+
9
+ "scp #{flags.compact.join(' ')} #{from} #{to}"
10
+ end
11
+
12
+ def remote_address(user, host, path)
13
+ user_with_host = [user, host].compact.join('@')
14
+ [user_with_host, path].join(':')
15
+ end
16
+
17
+ def ssh_options(options)
18
+ %[-o "#{options.join(' ')}"] unless options.empty?
19
+ end
20
+ end
21
+ end
22
+ end
data/lib/deb_deploy.rb ADDED
@@ -0,0 +1,56 @@
1
+ require 'deb_deploy/rsync'
2
+ require 'deb_deploy/logger/batch'
3
+ require 'deb_deploy/logger/stream'
4
+
5
+ Capistrano::Configuration.instance.load do
6
+ namespace :deb do
7
+ set :debian_source, '.'
8
+ set :debian_target, '/tmp/deb_deploy'
9
+ set :debian_package_manager, 'dpkg'
10
+ set :debian_stream_log, false
11
+
12
+ desc "copies debian packages to the server"
13
+ task :copy_packages do
14
+ targets = find_servers_for_task(current_task)
15
+ failed_targets = targets.map do |target|
16
+ copy_cmd = DebDeploy::Rsync.command(
17
+ debian_source,
18
+ DebDeploy::Rsync.remote_address(target.user || fetch(:user, ENV['USER']), target.host, debian_target),
19
+ :ssh => {
20
+ :keys => ssh_options[:keys],
21
+ :config => ssh_options[:config],
22
+ :port => fetch(:port, nil)
23
+ }
24
+ )
25
+ logger.debug copy_cmd
26
+ target.host unless system copy_cmd
27
+ end.compact
28
+
29
+ raise "rsync failed on #{failed_targets.join(',')}" if failed_targets.any?
30
+ end
31
+
32
+ task :install_packages do
33
+ log = if debian_stream_log
34
+ DebDeploy::Logger::Stream.new(logger)
35
+ else
36
+ DebDeploy::Logger::Batch.new(logger)
37
+ end
38
+
39
+ begin
40
+ run "#{sudo} #{debian_package_manager} -R -i #{debian_target}" do |channel, stream, data|
41
+ log.collect(channel[:host], data)
42
+ end
43
+ logger.debug "Package installation complete."
44
+ ensure
45
+ log.collected
46
+ end
47
+ end
48
+
49
+ desc "copies and installs debian packages to the server"
50
+ task :deploy do
51
+ run "mkdir -p #{debian_target}"
52
+ copy_packages
53
+ install_packages
54
+ end
55
+ end
56
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: deb_deploy
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 0
8
+ - 0
9
+ version: 1.0.0
10
+ platform: ruby
11
+ authors:
12
+ - Jeroen Rosenberg
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2012-04-18 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: See http://github.com/jeroenr/deb_deploy
22
+ email:
23
+ - jeroen.rosenberg@gmail.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - README.md
32
+ - Rakefile
33
+ - lib/deb_deploy.rb
34
+ - lib/deb_deploy/rsync.rb
35
+ - lib/deb_deploy/scp.rb
36
+ - lib/deb_deploy/logger/batch.rb
37
+ - lib/deb_deploy/logger/stream.rb
38
+ has_rdoc: true
39
+ homepage: http://github.com/jeroenr/deb_deploy
40
+ licenses: []
41
+
42
+ post_install_message:
43
+ rdoc_options: []
44
+
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ segments:
53
+ - 0
54
+ version: "0"
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ requirements: []
64
+
65
+ rubyforge_project:
66
+ rubygems_version: 1.3.7
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: Masterless puppet with capistrano
70
+ test_files: []
71
+