deb_deploy 1.2.1 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +8 -2
- data/lib/deb_deploy/apt_ftp_archive.rb +27 -0
- data/lib/deb_deploy/apt_get.rb +17 -0
- data/lib/deb_deploy/rsync.rb +1 -0
- data/lib/deb_deploy.rb +37 -51
- metadata +4 -2
data/README.md
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
[![endorse](http://api.coderwall.com/jeroenr/endorsecount.png)](http://coderwall.com/jeroenr)
|
2
|
+
|
1
3
|
# deb_deploy
|
2
4
|
|
3
5
|
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
|
@@ -20,6 +22,10 @@ This sets up the environment for dpkg or apt deployment, depending on your confi
|
|
20
22
|
|
21
23
|
This deploys the debian packages on the target servers.
|
22
24
|
|
25
|
+
cap deb:teardown
|
26
|
+
|
27
|
+
Cleans up the environment.
|
28
|
+
|
23
29
|
### Configuration
|
24
30
|
|
25
31
|
At the top of your deploy.rb
|
@@ -33,7 +39,7 @@ then optionally set some variables
|
|
33
39
|
|
34
40
|
the directory containing your debian packages that will be rsynced to the servers.
|
35
41
|
|
36
|
-
set :debian_target, '/tmp
|
42
|
+
set :debian_target, '/tmp'
|
37
43
|
|
38
44
|
the temp directory on the target machine to hold the packages before installing.
|
39
45
|
|
@@ -45,6 +51,6 @@ the debian package manager to use (one of [dpkg, apt]).
|
|
45
51
|
|
46
52
|
determines whether to stream the command output.
|
47
53
|
|
48
|
-
set :debian_filter,
|
54
|
+
set :debian_filter, '*'
|
49
55
|
|
50
56
|
a glob syntax filter to determine which packages to deploy. By default all will be deployed.
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module DebDeploy
|
2
|
+
class AptFtpArchive
|
3
|
+
class << self
|
4
|
+
def command(arguments, options={})
|
5
|
+
"apt-ftparchive " << options.map{|k,v| "-o #{k}='#{v}'"}.join(' ') << " #{arguments}"
|
6
|
+
end
|
7
|
+
|
8
|
+
def create_packages_file(from, options={})
|
9
|
+
command("packages #{from} | gzip -9c > Packages.gz", options)
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_release_file(from, options={})
|
13
|
+
release_file_options = {
|
14
|
+
"Codename" => "deb_deploy",
|
15
|
+
"Components" => "deb_deploy",
|
16
|
+
"Origin" => "deb_deploy",
|
17
|
+
"Label" => "Deployed with deb_deploy",
|
18
|
+
"Architectures" => "all",
|
19
|
+
"Suite" => "stable"
|
20
|
+
}
|
21
|
+
command("release #{from} > Release", options.merge(Hash[release_file_options.map {|k,v| ["APT::FTPArchive::Release::#{k}",v]}]))
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module DebDeploy
|
2
|
+
class AptGet
|
3
|
+
class << self
|
4
|
+
def command(arguments, options={})
|
5
|
+
"apt-get -y --allow-unauthenticated " << options.map{|k,v| "-o #{k}='#{v}'"}.join(' ') << " #{arguments}"
|
6
|
+
end
|
7
|
+
|
8
|
+
def update_cache(options={})
|
9
|
+
command("update", options)
|
10
|
+
end
|
11
|
+
|
12
|
+
def install_packages(packages, options={})
|
13
|
+
command("install #{packages.join(' ')}", options)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/deb_deploy/rsync.rb
CHANGED
data/lib/deb_deploy.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
require 'deb_deploy/rsync'
|
2
|
+
require 'deb_deploy/apt_get'
|
3
|
+
require 'deb_deploy/apt_ftp_archive'
|
2
4
|
require 'deb_deploy/logger/batch'
|
3
5
|
require 'deb_deploy/logger/stream'
|
4
6
|
require 'deb_deploy/util/parallel_enumerable'
|
@@ -6,11 +8,20 @@ require 'deb_deploy/util/parallel_enumerable'
|
|
6
8
|
Capistrano::Configuration.instance.load do
|
7
9
|
namespace :deb do
|
8
10
|
set :debian_source, '.'
|
9
|
-
set :debian_target, '/tmp
|
11
|
+
set :debian_target, '/tmp'
|
10
12
|
set :debian_package_manager, 'dpkg'
|
11
13
|
set :debian_stream_log, false
|
12
14
|
set :debian_filter, '*'
|
13
15
|
|
16
|
+
RELEASE_FILE_OPTIONS = {
|
17
|
+
"Codename" => "deb_deploy",
|
18
|
+
"Components" => "deb_deploy",
|
19
|
+
"Origin" => "deb_deploy",
|
20
|
+
"Label" => "Deployed with deb_deploy",
|
21
|
+
"Architectures" => "all",
|
22
|
+
"Suite" => "stable"
|
23
|
+
}
|
24
|
+
|
14
25
|
namespace :bootstrap do
|
15
26
|
desc "prepares remote hosts for debian deployment based on selected package manager (dpkg or apt)"
|
16
27
|
task :default do
|
@@ -26,28 +37,26 @@ Capistrano::Configuration.instance.load do
|
|
26
37
|
|
27
38
|
desc "creates directories and installs dependencies"
|
28
39
|
task :dpkg do
|
29
|
-
run "mkdir -p #{debian_target}"
|
30
|
-
sudo
|
31
|
-
sudo
|
40
|
+
run "mkdir -p #{debian_target}/deb_deploy"
|
41
|
+
sudo DebDeploy::AptGet.update_cache
|
42
|
+
sudo DebDeploy::AptGet.install_packages(%w(rsync))
|
32
43
|
logger.debug "Dependencies installed"
|
33
44
|
end
|
34
45
|
|
35
46
|
desc "creates local debian repository for apt-get"
|
36
47
|
task :apt do
|
37
|
-
run "mkdir -p #{debian_target}"
|
48
|
+
run "mkdir -p #{debian_target}/deb_deploy"
|
38
49
|
|
39
|
-
sudo
|
40
|
-
sudo
|
50
|
+
sudo DebDeploy::AptGet.update_cache
|
51
|
+
sudo DebDeploy::AptGet.install_packages(%w(rsync dpkg-dev gzip))
|
41
52
|
|
42
53
|
logger.debug "Dependencies installed"
|
43
54
|
|
44
|
-
put "deb file:#{debian_target} ./", "#{debian_target}/deb_deploy.list"
|
45
|
-
sudo "mv #{debian_target}/deb_deploy.list /etc/apt/sources.list.d/deb_deploy.list"
|
55
|
+
put "deb file:#{debian_target}/deb_deploy ./", "#{debian_target}/deb_deploy.list"
|
46
56
|
|
47
57
|
put "Package: *\nPin: origin\nPin-Priority: 900\n", "#{debian_target}/00debdeploy"
|
48
|
-
sudo "mv #{debian_target}/00debdeploy /etc/apt/preferences.d/00debdeploy"
|
49
58
|
|
50
|
-
run "cd #{debian_target} &&
|
59
|
+
run "cd #{debian_target}/deb_deploy && " << DebDeploy::AptFtpArchive.create_packages_file('.')
|
51
60
|
|
52
61
|
logger.debug "Set up local debian repository"
|
53
62
|
end
|
@@ -55,34 +64,16 @@ Capistrano::Configuration.instance.load do
|
|
55
64
|
end
|
56
65
|
|
57
66
|
namespace :teardown do
|
58
|
-
desc "cleans up deb_deploy files
|
67
|
+
desc "cleans up deb_deploy files"
|
59
68
|
task :default do
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
else
|
66
|
-
raise "#{debian_package_manager} is an unsupported package manager. Only dpkg and apt are supported"
|
69
|
+
sudo "rm -rf #{debian_target}/deb_deploy"
|
70
|
+
|
71
|
+
deb_deploy_files = %w(/etc/apt/sources.list.d/deb_deploy.list /etc/apt/preferences.d/00debdeploy) << "#{debian_target}/deb_deploy.list" << "#{debian_target}/00debdeploy"
|
72
|
+
deb_deploy_files.each do |file_name|
|
73
|
+
sudo "rm -f #{file_name}"
|
67
74
|
end
|
68
|
-
end
|
69
|
-
|
70
|
-
desc "cleans up deb_deploy directory (#{debian_target})"
|
71
|
-
task :dpkg do
|
72
|
-
run "rm -rf #{debian_target}"
|
73
75
|
logger.debug "Removed deployment directory"
|
74
76
|
end
|
75
|
-
|
76
|
-
desc "cleans up deb_deploy directory (#{debian_target}) and local debian repository from remote hosts"
|
77
|
-
task :apt do
|
78
|
-
run "rm -rf #{debian_target}"
|
79
|
-
|
80
|
-
sudo "rm /etc/apt/sources.list.d/deb_deploy.list"
|
81
|
-
|
82
|
-
sudo "rm /etc/apt/preferences.d/00debdeploy"
|
83
|
-
|
84
|
-
logger.debug "Removed local debian repository and deployment directory"
|
85
|
-
end
|
86
77
|
end
|
87
78
|
|
88
79
|
desc "copies debian packages to the server"
|
@@ -91,7 +82,7 @@ Capistrano::Configuration.instance.load do
|
|
91
82
|
failed_targets = targets.async.map do |target|
|
92
83
|
copy_cmd = DebDeploy::Rsync.command(
|
93
84
|
debian_source,
|
94
|
-
DebDeploy::Rsync.remote_address(target.user || fetch(:user, ENV['USER']), target.host, debian_target),
|
85
|
+
DebDeploy::Rsync.remote_address(target.user || fetch(:user, ENV['USER']), target.host, "#{debian_target}/deb_deploy"),
|
95
86
|
:filter => ['*/'] + debian_filter.split(',').map {|x| "#{x}.deb"},
|
96
87
|
:ssh => {
|
97
88
|
:keys => ssh_options[:keys],
|
@@ -116,28 +107,23 @@ Capistrano::Configuration.instance.load do
|
|
116
107
|
begin
|
117
108
|
case debian_package_manager
|
118
109
|
when "dpkg"
|
119
|
-
sudo "dpkg -R -i #{debian_target}" do |channel, stream, data|
|
110
|
+
sudo "dpkg -R -i #{debian_target}/deb_deploy" do |channel, stream, data|
|
120
111
|
log.collect(channel[:host], data)
|
121
112
|
end
|
122
113
|
when "apt"
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
"Codename" => "deb_deploy",
|
127
|
-
"Components" => "deb_deploy",
|
128
|
-
"Origin" => "deb_deploy",
|
129
|
-
"Label" => "Deployed with deb_deploy",
|
130
|
-
"Architectures" => "all",
|
131
|
-
"Suite" => "stable"
|
114
|
+
apt_get_options = {
|
115
|
+
"Dir::Etc::SourceList" => "#{debian_target}/deb_deploy.list",
|
116
|
+
"Dir::Etc::Preferences" => "#{debian_target}/00debdeploy"
|
132
117
|
}
|
133
118
|
|
134
|
-
|
119
|
+
list_packages_cmd = "zcat #{debian_target}/deb_deploy/Packages.gz | grep Package | cut -d ' ' -f2 | sed ':a;N;$!ba;s/\n/ /g'"
|
120
|
+
|
121
|
+
run "cd #{debian_target}/deb_deploy && " << DebDeploy::AptFtpArchive.create_packages_file('.')
|
122
|
+
run "cd #{debian_target}/deb_deploy && " << DebDeploy::AptFtpArchive.create_release_file('.', Hash[RELEASE_FILE_OPTIONS.map {|k,v| ["APT::FTPArchive::Release::#{k}",v]}])
|
135
123
|
|
136
|
-
sudo
|
124
|
+
sudo DebDeploy::AptGet.update_cache(apt_get_options)
|
137
125
|
|
138
|
-
|
139
|
-
|
140
|
-
run "#{list_packages_cmd} | xargs #{sudo} apt-get -y --allow-unauthenticated install" do |channel, stream, data|
|
126
|
+
run "#{list_packages_cmd} | xargs #{sudo} #{DebDeploy::AptGet.install_packages([],apt_get_options)}" do |channel, stream, data|
|
141
127
|
log.collect(channel[:host], data)
|
142
128
|
end
|
143
129
|
else
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deb_deploy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-06-01 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: See http://github.com/jeroenr/deb_deploy
|
15
15
|
email:
|
@@ -21,7 +21,9 @@ files:
|
|
21
21
|
- README.md
|
22
22
|
- Rakefile
|
23
23
|
- lib/deb_deploy.rb
|
24
|
+
- lib/deb_deploy/apt_get.rb
|
24
25
|
- lib/deb_deploy/rsync.rb
|
26
|
+
- lib/deb_deploy/apt_ftp_archive.rb
|
25
27
|
- lib/deb_deploy/util/parallel_enumerable.rb
|
26
28
|
- lib/deb_deploy/util/collection_utils.rb
|
27
29
|
- lib/deb_deploy/scp.rb
|