dpkg-tools 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +11 -0
- data/README +26 -0
- data/lib/dpkg-tools/command_line.rb +6 -3
- data/lib/dpkg-tools/package/builder.rb +13 -0
- data/lib/dpkg-tools/package/data.rb +8 -5
- data/lib/dpkg-tools/package/etc/builder.rb +16 -1
- data/lib/dpkg-tools/package/gem/setup.rb +6 -1
- data/lib/dpkg-tools/package/rails/builder.rb +2 -3
- data/lib/dpkg-tools/package/rails/data.rb +1 -1
- data/lib/dpkg-tools/package/rake.rb +18 -12
- data/lib/dpkg-tools/version.rb +2 -2
- data/resources/etc/changelog.yml +22 -0
- data/resources/etc/deb.yml +23 -0
- data/resources/etc/postinst.erb +3 -0
- data/resources/etc/prerm.erb +3 -0
- data/resources/gem/gems_to_deps.yml +45 -0
- data/resources/rails/apache.conf.erb +19 -0
- data/resources/rails/deb.yml +37 -0
- data/resources/rails/deploy.rb +51 -0
- data/resources/rails/logrotate.conf.erb +15 -0
- data/resources/rails/mongrel_cluster.yml +7 -0
- data/resources/rails/mongrel_cluster_init.erb +53 -0
- data/resources/rails/postinst.erb +63 -0
- data/resources/rails/postrm.erb +38 -0
- data/resources/rails/preinst.erb +36 -0
- data/spec/dpkg-tools/package/builder_spec.rb +136 -119
- data/spec/dpkg-tools/package/data_spec.rb +9 -0
- data/spec/dpkg-tools/package/etc/builder_spec.rb +39 -19
- data/spec/dpkg-tools/package/rails/builder_spec.rb +82 -83
- data/spec/dpkg-tools/package/rails/data_spec.rb +1 -1
- data/spec/dpkg-tools/package/rake_spec.rb +8 -2
- data/tasks/dist.rake +3 -1
- metadata +20 -3
@@ -0,0 +1,36 @@
|
|
1
|
+
#!/bin/bash -e
|
2
|
+
|
3
|
+
DATADIR="<%= app_install_path %>"
|
4
|
+
|
5
|
+
# Create a group for the app if it isn't already there
|
6
|
+
if ! getent group "<%= name %>" >/dev/null; then
|
7
|
+
# Adding system group for the app: <%= name %>.
|
8
|
+
addgroup --system "<%= name %>" >/dev/null
|
9
|
+
fi
|
10
|
+
|
11
|
+
# Create a user for the app if it isn't already there
|
12
|
+
if ! getent passwd <%= name %> >/dev/null; then
|
13
|
+
# Adding system user: <%= name %>.
|
14
|
+
adduser \
|
15
|
+
--system \
|
16
|
+
--disabled-login \
|
17
|
+
--ingroup <%= name %> \
|
18
|
+
--home $DATADIR \
|
19
|
+
--gecos "<%= name %> Rails app" \
|
20
|
+
--shell /bin/bash \
|
21
|
+
<%= name %> >/dev/null
|
22
|
+
fi
|
23
|
+
|
24
|
+
# Create the app's home dir, if it isn't there already...
|
25
|
+
if [ ! -d $DATADIR -a ! -L $DATADIR ]; then
|
26
|
+
mkdir -p $DATADIR
|
27
|
+
fi
|
28
|
+
|
29
|
+
# Fix ownership of the app's home dir...
|
30
|
+
# The "set +e" is necessary as e.g. a ".journal" of a ext3 partition is
|
31
|
+
# not chgrp'able (#318435). [nicked from mysql-server 5's preinst]
|
32
|
+
set +e
|
33
|
+
chown <%= name %>:<%= name %> $DATADIR
|
34
|
+
find $DATADIR -follow -not -group "<%= name %>" -print0 2>/dev/null \
|
35
|
+
| xargs -0 --no-run-if-empty chgrp "<%= name %>"
|
36
|
+
set -e
|
@@ -1,159 +1,176 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
2
|
|
3
|
-
describe DpkgTools::Package::Builder
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
@stub_data = stub("stub DpkgTools::Package::Rails::Data", :name => 'rails-app', :version => '1.0.8',
|
10
|
-
:full_name => 'rails-app-1.0.8', :debian_revision => "1", :debian_arch => "all",
|
11
|
-
:mongrel_ports => ['8000', '8001', '8002'])
|
12
|
-
stub_data_binding = @stub_data.send(:binding)
|
13
|
-
@stub_data.stubs(:binding).returns(stub_data_binding)
|
14
|
-
|
15
|
-
@builder = DpkgTools::Package::Builder.new(@stub_data)
|
3
|
+
describe DpkgTools::Package::Builder do
|
4
|
+
describe ".from_path support methods" do
|
5
|
+
it "should provide a for-overriding method to return the Package::Data subclass to use" do
|
6
|
+
DpkgTools::Package::Builder.data_class.should == DpkgTools::Package::Data
|
7
|
+
end
|
16
8
|
end
|
17
9
|
|
18
|
-
|
19
|
-
|
10
|
+
describe ".from_path" do
|
11
|
+
it "should be able to grab all needed config stuff and create a Data and a Builder instance" do
|
12
|
+
DpkgTools::Package::Data.expects(:new).with('/path/to/app').returns(:data)
|
13
|
+
DpkgTools::Package::Builder.expects(:new).with(:data).returns(:instance)
|
14
|
+
|
15
|
+
DpkgTools::Package::Builder.from_path('/path/to/app').should == :instance
|
16
|
+
end
|
20
17
|
end
|
21
18
|
|
22
|
-
|
23
|
-
|
24
|
-
|
19
|
+
describe "instances" do
|
20
|
+
before(:each) do
|
21
|
+
DpkgTools::Package::Config.stubs(:root_path).returns('/a/path/to/')
|
22
|
+
@config = DpkgTools::Package::Config.new('rails-app', '1.0.8', {})
|
23
|
+
DpkgTools::Package::Config.expects(:new).with('rails-app', '1.0.8', {}).returns(@config)
|
24
|
+
|
25
|
+
@stub_data = stub("stub DpkgTools::Package::Rails::Data", :name => 'rails-app', :version => '1.0.8',
|
26
|
+
:full_name => 'rails-app-1.0.8', :debian_revision => "1", :debian_arch => "all",
|
27
|
+
:mongrel_ports => ['8000', '8001', '8002'])
|
28
|
+
stub_data_binding = @stub_data.send(:binding)
|
29
|
+
@stub_data.stubs(:binding).returns(stub_data_binding)
|
30
|
+
|
31
|
+
@builder = DpkgTools::Package::Builder.new(@stub_data)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should provide access to @data" do
|
35
|
+
@builder.data.should == @stub_data
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should be able to provide access to its DpkgTools::Package::Config entry" do
|
39
|
+
@builder.config.should == @config
|
40
|
+
end
|
25
41
|
|
26
|
-
|
27
|
-
|
42
|
+
it "should be able to create an intermediate tmp build directory" do
|
43
|
+
@builder.expects(:create_dir_if_needed).with('/a/path/to/rails-app-1.0.8/dpkg-tools-tmp')
|
28
44
|
|
29
|
-
|
30
|
-
|
45
|
+
@builder.create_intermediate_buildroot
|
46
|
+
end
|
31
47
|
|
32
|
-
|
33
|
-
|
48
|
+
it "should be able to create the debian/tmp buildroot dir" do
|
49
|
+
@builder.expects(:create_dir_if_needed).with('/a/path/to/rails-app-1.0.8/debian/tmp')
|
34
50
|
|
35
|
-
|
36
|
-
|
51
|
+
@builder.create_buildroot
|
52
|
+
end
|
37
53
|
|
38
|
-
|
39
|
-
|
40
|
-
|
54
|
+
it "should be able to create the buildroot/DEBIAN dir" do
|
55
|
+
Dir.expects(:mkdir).with('/a/path/to/rails-app-1.0.8/debian/tmp/DEBIAN')
|
56
|
+
File.expects(:directory?).with('/a/path/to/rails-app-1.0.8/debian/tmp/DEBIAN').returns(false)
|
41
57
|
|
42
|
-
|
43
|
-
|
58
|
+
@builder.create_DEBIAN_dir
|
59
|
+
end
|
44
60
|
|
45
|
-
|
46
|
-
|
61
|
+
it "should be able to create the DEBIAN/* package metadata files" do
|
62
|
+
@builder.expects(:sh).with('dpkg-gencontrol')
|
47
63
|
|
48
|
-
|
49
|
-
|
64
|
+
@builder.create_control_files
|
65
|
+
end
|
50
66
|
|
51
|
-
|
52
|
-
|
53
|
-
|
67
|
+
it "should be able to generate the path to the built .deb package" do
|
68
|
+
@builder.built_deb_path.should == "/a/path/to/rails-app_1.0.8-1_all.deb"
|
69
|
+
end
|
54
70
|
|
55
|
-
|
56
|
-
|
71
|
+
it "should be able to create the .deb package" do
|
72
|
+
@builder.stubs(:built_deb_path).returns('/a/path/to/rails-app_1.0.8-1_all.deb')
|
57
73
|
|
58
|
-
|
59
|
-
|
60
|
-
|
74
|
+
@builder.expects(:sh).with('dpkg-deb --build "/a/path/to/rails-app-1.0.8/debian/tmp" "/a/path/to/rails-app_1.0.8-1_all.deb"')
|
75
|
+
@builder.create_deb
|
76
|
+
end
|
61
77
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
78
|
+
it "should be able to report which maintainer scripts need to be generated" do
|
79
|
+
Dir.expects(:entries).with('/a/path/to/rails-app-1.0.8/debian').returns(['.', '..', 'postinst.erb', 'preinst.erb', 'postinst'])
|
80
|
+
@builder.maintainer_script_targets.should == ['postinst', 'preinst']
|
81
|
+
end
|
66
82
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
83
|
+
it "should be able to render an erb template using data as the binding" do
|
84
|
+
@builder.render_template("<%= mongrel_ports.inspect %>").
|
85
|
+
should == '["8000", "8001", "8002"]'
|
86
|
+
end
|
71
87
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
88
|
+
it "should be able to generate a maintainer script" do
|
89
|
+
File.expects(:read).with('/a/path/to/rails-app-1.0.8/debian/postinst.erb').returns('template')
|
90
|
+
mock_file = mock('File')
|
91
|
+
mock_file.expects(:write).with('rendered template')
|
92
|
+
File.expects(:open).with('/a/path/to/rails-app-1.0.8/debian/tmp/DEBIAN/postinst', 'w').yields(mock_file)
|
93
|
+
File.expects(:chmod).with(0755, '/a/path/to/rails-app-1.0.8/debian/tmp/DEBIAN/postinst')
|
78
94
|
|
79
|
-
|
95
|
+
@builder.expects(:render_template).with('template').returns('rendered template')
|
80
96
|
|
81
|
-
|
82
|
-
|
97
|
+
@builder.generate_maintainer_script('postinst')
|
98
|
+
end
|
83
99
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
100
|
+
it "should be able to generate all the maintainer scripts" do
|
101
|
+
@builder.expects(:maintainer_script_targets).returns(['postinst', 'preinst'])
|
102
|
+
@builder.expects(:generate_maintainer_script).with('postinst')
|
103
|
+
@builder.expects(:generate_maintainer_script).with('preinst')
|
88
104
|
|
89
|
-
|
90
|
-
|
105
|
+
@builder.generate_maintainer_scripts
|
106
|
+
end
|
91
107
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
108
|
+
it "should be able to report that it's an architecture independent package when it is" do
|
109
|
+
@stub_data.stubs(:architecture_independent?).returns(true)
|
110
|
+
@builder.architecture_independent?.should be_true
|
111
|
+
end
|
96
112
|
|
97
|
-
|
98
|
-
|
99
|
-
|
113
|
+
it "should be able to report that it's an architecture dependent package when it is" do
|
114
|
+
@stub_data.stubs(:architecture_independent?).returns(false)
|
115
|
+
@builder.architecture_independent?.should be_false
|
116
|
+
end
|
100
117
|
end
|
101
|
-
end
|
102
118
|
|
103
|
-
describe DpkgTools::Package::Builder, "#build_package" do
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
119
|
+
describe DpkgTools::Package::Builder, "#build_package" do
|
120
|
+
it "should perform the equivalent steps to configure/make" do
|
121
|
+
stub_data = stub("stub DpkgTools::Package::Gem::Data", :name => 'rails-app', :version => '1.0.8',
|
122
|
+
:full_name => 'rails-app-1.0.8')
|
123
|
+
builder = DpkgTools::Package::Builder.new(stub_data)
|
124
|
+
builder.expects(:create_buildroot)
|
125
|
+
builder.expects(:create_install_dirs)
|
126
|
+
builder.expects(:build_package_files)
|
127
|
+
|
128
|
+
builder.build_package
|
129
|
+
end
|
113
130
|
end
|
114
|
-
end
|
115
131
|
|
116
|
-
describe DpkgTools::Package::Builder, "#binary_package" do
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
132
|
+
describe DpkgTools::Package::Builder, "#binary_package" do
|
133
|
+
it "should perform the steps needed to make a .deb and .dsc" do
|
134
|
+
stub_data = stub("stub DpkgTools::Package::Gem::Data", :name => 'rails-app', :version => '1.0.8',
|
135
|
+
:full_name => 'rails-app-1.0.8')
|
136
|
+
builder = DpkgTools::Package::Builder.new(stub_data)
|
137
|
+
builder.expects(:create_buildroot)
|
138
|
+
builder.expects(:create_install_dirs)
|
139
|
+
builder.expects(:install_package_files)
|
140
|
+
builder.expects(:generate_maintainer_scripts)
|
141
|
+
builder.expects(:create_DEBIAN_dir)
|
142
|
+
builder.expects(:create_control_files)
|
143
|
+
builder.expects(:create_deb)
|
144
|
+
|
145
|
+
builder.binary_package
|
146
|
+
end
|
130
147
|
end
|
131
|
-
end
|
132
148
|
|
133
|
-
describe DpkgTools::Package::Builder, "#remove_build_products" do
|
134
|
-
|
135
|
-
|
149
|
+
describe DpkgTools::Package::Builder, "#remove_build_products" do
|
150
|
+
before(:each) do
|
151
|
+
DpkgTools::Package::Config.stubs(:root_path).returns("a/path/to")
|
136
152
|
|
137
|
-
|
138
|
-
|
153
|
+
@stub_data = stub("stub DpkgTools::Package::Gem::Data", :name => 'rails-app', :version => '1.0.8',
|
154
|
+
:full_name => 'rails-app-1.0.8')
|
139
155
|
|
140
|
-
|
141
|
-
|
156
|
+
@builder = DpkgTools::Package::Builder.new(@stub_data)
|
157
|
+
end
|
142
158
|
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
159
|
+
it "should only try to remove build products when debian/tmp exists" do
|
160
|
+
File.expects(:exists?).with('a/path/to/rails-app-1.0.8/debian/tmp').returns(false)
|
161
|
+
File.expects(:exists?).with('a/path/to/rails-app-1.0.8/dpkg-tools-tmp').returns(false)
|
162
|
+
FileUtils.expects(:remove_dir).never
|
147
163
|
|
148
|
-
|
149
|
-
|
164
|
+
@builder.remove_build_products
|
165
|
+
end
|
150
166
|
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
167
|
+
it "should remove all the build products" do
|
168
|
+
File.expects(:exists?).with('a/path/to/rails-app-1.0.8/debian/tmp').returns(true)
|
169
|
+
FileUtils.expects(:remove_dir).with('a/path/to/rails-app-1.0.8/debian/tmp')
|
170
|
+
File.expects(:exists?).with('a/path/to/rails-app-1.0.8/dpkg-tools-tmp').returns(true)
|
171
|
+
FileUtils.expects(:remove_dir).with('a/path/to/rails-app-1.0.8/dpkg-tools-tmp')
|
156
172
|
|
157
|
-
|
173
|
+
@builder.remove_build_products
|
174
|
+
end
|
158
175
|
end
|
159
176
|
end
|
@@ -89,12 +89,21 @@ describe DpkgTools::Package::Data::YamlConfigHelpers do
|
|
89
89
|
should include({:name => 'rspec-rubygem', :requirements => ['>= 1.0.8-1']})
|
90
90
|
end
|
91
91
|
|
92
|
+
it "should be able to cope with deps without version requirements" do
|
93
|
+
fixture_data = {'dependencies' => {'gem' => ['rspec']}}
|
94
|
+
|
95
|
+
@module.process_dependencies(fixture_data).
|
96
|
+
should include({:name => 'rspec-rubygem'})
|
97
|
+
end
|
98
|
+
|
92
99
|
it "should raise an appropriate error if the dependencies collection is not a Hash (YAML collection)" do
|
93
100
|
fixture_data = {'dependencies' => 'string'}
|
94
101
|
|
95
102
|
lambda { @module.process_dependencies(fixture_data) }.
|
96
103
|
should raise_error(DpkgTools::Package::DebYAMLParseError)
|
97
104
|
end
|
105
|
+
|
106
|
+
|
98
107
|
end
|
99
108
|
|
100
109
|
describe @module, ".process_dependencies_by_type" do
|
@@ -1,28 +1,48 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../../../spec_helper'
|
2
2
|
|
3
|
-
describe DpkgTools::Package::Etc::Builder
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
@data = DpkgTools::Package::Etc::Data.new('/a/path/to/conf-package')
|
9
|
-
|
10
|
-
@builder = DpkgTools::Package::Etc::Builder.new(@data)
|
11
|
-
end
|
12
|
-
|
13
|
-
it "should provide the correct options for DpkgTools::Package::Config " do
|
14
|
-
@builder.config_options.should == {:base_path => "/a/path/to/conf-package"}
|
3
|
+
describe DpkgTools::Package::Etc::Builder do
|
4
|
+
describe ".from_path support" do
|
5
|
+
it "should return DpkgTools::Package::Etc::Data when asked for the data subclass to use" do
|
6
|
+
DpkgTools::Package::Etc::Builder.data_class.should == DpkgTools::Package::Etc::Data
|
7
|
+
end
|
15
8
|
end
|
16
9
|
|
17
|
-
|
18
|
-
|
10
|
+
describe "instances" do
|
11
|
+
before(:each) do
|
12
|
+
@config = DpkgTools::Package::Config.new('rails-app', '1.0.8')
|
13
|
+
DpkgTools::Package::Etc::Data.expects(:load_package_data).with('/a/path/to/conf-package', 'deb.yml').
|
14
|
+
returns({'name' => 'conf-package', 'version' => '1.0.8'})
|
15
|
+
@data = DpkgTools::Package::Etc::Data.new('/a/path/to/conf-package')
|
19
16
|
|
20
|
-
|
21
|
-
|
17
|
+
@builder = DpkgTools::Package::Etc::Builder.new(@data)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should provide the correct options for DpkgTools::Package::Config " do
|
21
|
+
@builder.config_options.should == {:base_path => "/a/path/to/conf-package"}
|
22
|
+
end
|
22
23
|
|
23
|
-
|
24
|
-
|
24
|
+
it "should be able to create the needed install dirs" do
|
25
|
+
@builder.expects(:create_dir_if_needed).with('/a/path/to/conf-package/debian/tmp/etc')
|
25
26
|
|
26
|
-
|
27
|
+
@builder.create_install_dirs
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should copy the contents of package/etc to package/debian/tmp/etc/" do
|
31
|
+
Dir.expects(:[]).with('/a/path/to/conf-package/etc/**/*').returns(['/a/path/to/conf-package/etc/thing',
|
32
|
+
'/a/path/to/conf-package/etc/thing/conf_file',
|
33
|
+
'/a/path/to/conf-package/etc/thing/wotsit.yml'])
|
34
|
+
File.expects(:file?).with('/a/path/to/conf-package/etc/thing').returns(false)
|
35
|
+
File.expects(:file?).with('/a/path/to/conf-package/etc/thing/conf_file').returns(true)
|
36
|
+
FileUtils.expects(:mkdir_p).with('/a/path/to/conf-package/debian/tmp/etc/thing')
|
37
|
+
FileUtils.expects(:install).with('/a/path/to/conf-package/etc/thing/conf_file',
|
38
|
+
'/a/path/to/conf-package/debian/tmp/etc/thing/conf_file',
|
39
|
+
{:mode => 0644, :verbose => true})
|
40
|
+
File.expects(:file?).with('/a/path/to/conf-package/etc/thing/wotsit.yml').returns(true)
|
41
|
+
FileUtils.expects(:mkdir_p).with('/a/path/to/conf-package/debian/tmp/etc/thing')
|
42
|
+
FileUtils.expects(:install).with('/a/path/to/conf-package/etc/thing/wotsit.yml',
|
43
|
+
'/a/path/to/conf-package/debian/tmp/etc/thing/wotsit.yml',
|
44
|
+
{:mode => 0644, :verbose => true})
|
45
|
+
@builder.install_package_files
|
46
|
+
end
|
27
47
|
end
|
28
48
|
end
|
@@ -1,113 +1,112 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../../../spec_helper'
|
2
2
|
|
3
3
|
describe DpkgTools::Package::Rails::Builder do
|
4
|
-
|
5
|
-
DpkgTools::Package::Rails::Data
|
6
|
-
|
7
|
-
|
8
|
-
DpkgTools::Package::Rails::Builder.from_path('/path/to/app').should == :instance
|
4
|
+
describe ".from_path support" do
|
5
|
+
it "should return DpkgTools::Package::Rails::Data when asked for the data subclass to use" do
|
6
|
+
DpkgTools::Package::Rails::Builder.data_class.should == DpkgTools::Package::Rails::Data
|
7
|
+
end
|
9
8
|
end
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
@data = DpkgTools::Package::Rails::Data.new('/a/path/to/rails-app/working/dir')
|
9
|
+
|
10
|
+
describe "instances" do
|
11
|
+
before(:each) do
|
12
|
+
@config = DpkgTools::Package::Config.new('rails-app', '1.0.8')
|
13
|
+
DpkgTools::Package::Rails::Data.expects(:load_package_data).with('/a/path/to/rails-app/working/dir', 'deb.yml').
|
14
|
+
returns({'name' => 'rails-app', 'version' => '1.0.8', 'server_name' => 'rails-app.org'}, 'mongrel_cluster' => {'port' => '8000', 'servers' => 3})
|
15
|
+
DpkgTools::Package::Rails::Data.expects(:load_package_data).with('/a/path/to/rails-app/working/dir', 'database.yml').
|
16
|
+
returns({'development' => {'database' => 'db_name'}})
|
17
|
+
@data = DpkgTools::Package::Rails::Data.new('/a/path/to/rails-app/working/dir')
|
20
18
|
|
21
|
-
|
22
|
-
|
19
|
+
@builder = DpkgTools::Package::Rails::Builder.new(@data)
|
20
|
+
end
|
23
21
|
|
24
|
-
|
25
|
-
|
26
|
-
|
22
|
+
it "should provide the correct options for DpkgTools::Package::Config " do
|
23
|
+
@builder.config_options.should == {:base_path => "/a/path/to/rails-app/working/dir"}
|
24
|
+
end
|
27
25
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
26
|
+
it "should be able to create the needed install dirs" do
|
27
|
+
@builder.expects(:create_dir_if_needed).with('/a/path/to/rails-app/working/dir/debian/tmp/etc/init.d')
|
28
|
+
@builder.expects(:create_dir_if_needed).with('/a/path/to/rails-app/working/dir/debian/tmp/etc/apache2/sites-available')
|
29
|
+
@builder.expects(:create_dir_if_needed).with('/a/path/to/rails-app/working/dir/debian/tmp/etc/logrotate.d')
|
30
|
+
@builder.expects(:create_dir_if_needed).with('/a/path/to/rails-app/working/dir/debian/tmp/var/lib/rails-app')
|
31
|
+
@builder.expects(:create_dir_if_needed).with('/a/path/to/rails-app/working/dir/debian/tmp/var/log/rails-app/apache2')
|
34
32
|
|
35
|
-
|
36
|
-
|
33
|
+
@builder.create_install_dirs
|
34
|
+
end
|
37
35
|
|
38
|
-
|
39
|
-
|
36
|
+
it "should be able to generate a config file from @data, an erb template and a destination path" do
|
37
|
+
File.expects(:read).with('template_path').returns('template')
|
40
38
|
|
41
|
-
|
39
|
+
@builder.expects(:render_template).with('template').returns('conf file')
|
42
40
|
|
43
|
-
|
44
|
-
|
45
|
-
|
41
|
+
mock_file = mock('File')
|
42
|
+
mock_file.expects(:write).with('conf file')
|
43
|
+
File.expects(:open).with('target_path', 'w').yields(mock_file)
|
46
44
|
|
47
|
-
|
48
|
-
|
45
|
+
@builder.generate_conf_file('template_path', 'target_path')
|
46
|
+
end
|
49
47
|
|
50
|
-
|
51
|
-
|
52
|
-
|
48
|
+
it "should generate all the needed config files" do
|
49
|
+
@builder.expects(:generate_conf_file).with('/a/path/to/rails-app/working/dir/config/apache.conf.erb',
|
50
|
+
'/a/path/to/rails-app/working/dir/debian/tmp/etc/apache2/sites-available/rails-app')
|
53
51
|
|
54
|
-
|
55
|
-
|
52
|
+
@builder.expects(:generate_conf_file).with('/a/path/to/rails-app/working/dir/config/logrotate.conf.erb',
|
53
|
+
'/a/path/to/rails-app/working/dir/debian/tmp/etc/logrotate.d/rails-app')
|
56
54
|
|
57
|
-
|
58
|
-
|
55
|
+
@builder.expects(:generate_conf_file).with('/a/path/to/rails-app/working/dir/config/mongrel_cluster_init.erb',
|
56
|
+
'/a/path/to/rails-app/working/dir/debian/tmp/etc/init.d/rails-app')
|
59
57
|
|
60
|
-
|
61
|
-
|
58
|
+
@builder.generate_conf_files
|
59
|
+
end
|
62
60
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
61
|
+
it "should be able to read the public ssh keys in deployers_ssh_keys" do
|
62
|
+
@data.stubs(:deployers_ssh_keys_dir).returns('/path/to/keys')
|
63
|
+
Dir.stubs(:entries).with('/path/to/keys').returns(['key1', 'key2'])
|
64
|
+
File.stubs(:file?).returns(true)
|
65
|
+
File.expects(:read).with('/path/to/keys/key1').returns('key1')
|
66
|
+
File.expects(:read).with('/path/to/keys/key2').returns('key2')
|
69
67
|
|
70
|
-
|
71
|
-
|
68
|
+
@builder.read_deployers_ssh_keys.should == ['key1', 'key2']
|
69
|
+
end
|
72
70
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
71
|
+
it "should be able to read the public ssh keys in deployers_ssh_keys, ignoring any directories there" do
|
72
|
+
@data.stubs(:deployers_ssh_keys_dir).returns('/path/to/keys')
|
73
|
+
Dir.stubs(:entries).with('/path/to/keys').returns(['is_a_dir', 'key1', 'key2'])
|
74
|
+
File.stubs(:file?).returns(true)
|
75
|
+
File.expects(:file?).with('/path/to/keys/is_a_dir').returns(false)
|
76
|
+
File.expects(:read).with('/path/to/keys/key1').returns('key1')
|
77
|
+
File.expects(:read).with('/path/to/keys/key2').returns('key2')
|
80
78
|
|
81
|
-
|
82
|
-
|
79
|
+
@builder.read_deployers_ssh_keys.should == ['key1', 'key2']
|
80
|
+
end
|
83
81
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
82
|
+
it "should be able to write out an authorized_keys file from a list of keys" do
|
83
|
+
mock_file = mock('File')
|
84
|
+
mock_file.expects(:write).with("key1\nkey2")
|
85
|
+
File.expects(:open).with('/a/path/to/rails-app/working/dir/debian/tmp/var/lib/rails-app/.ssh/authorized_keys', 'w').
|
86
|
+
yields(mock_file)
|
87
|
+
@builder.expects(:sh).with('chmod 600 "/a/path/to/rails-app/working/dir/debian/tmp/var/lib/rails-app/.ssh/authorized_keys"')
|
90
88
|
|
91
|
-
|
92
|
-
|
89
|
+
@builder.write_authorized_keys(['key1', 'key2'])
|
90
|
+
end
|
93
91
|
|
94
|
-
|
95
|
-
|
96
|
-
|
92
|
+
it "should be able to generate the authorized_keys file from the public keys in deployers_ssh_keys" do
|
93
|
+
@builder.expects(:create_dir_if_needed).with('/a/path/to/rails-app/working/dir/debian/tmp/var/lib/rails-app/.ssh')
|
94
|
+
@builder.expects(:sh).with('chmod 700 "/a/path/to/rails-app/working/dir/debian/tmp/var/lib/rails-app/.ssh"')
|
97
95
|
|
98
|
-
|
99
|
-
|
96
|
+
@builder.expects(:read_deployers_ssh_keys).returns(['key1', 'key2'])
|
97
|
+
@builder.expects(:write_authorized_keys).with(['key1', 'key2'])
|
100
98
|
|
101
|
-
|
102
|
-
|
99
|
+
@builder.generate_authorized_keys
|
100
|
+
end
|
103
101
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
102
|
+
it "should be able to perform all the needed steps to put install the package's files " do
|
103
|
+
@builder.expects(:generate_conf_files)
|
104
|
+
@builder.expects(:sh).with('chown -R root:root "/a/path/to/rails-app/working/dir/debian/tmp"')
|
105
|
+
@builder.expects(:sh).with('chmod 755 "/a/path/to/rails-app/working/dir/debian/tmp/etc/init.d/rails-app"')
|
108
106
|
|
109
|
-
|
107
|
+
@builder.expects(:generate_authorized_keys)
|
110
108
|
|
111
|
-
|
109
|
+
@builder.install_package_files
|
110
|
+
end
|
112
111
|
end
|
113
112
|
end
|