niman 0.0.6 → 0.0.7
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.
- checksums.yaml +4 -4
- data/README.md +16 -2
- data/lib/niman/installer.rb +1 -0
- data/lib/niman/library/custom_package.rb +9 -3
- data/lib/niman/library/file.rb +0 -4
- data/lib/niman/library/package.rb +4 -0
- data/lib/niman/provisioner.rb +14 -8
- data/lib/niman/version.rb +1 -1
- data/spec/lib/application_spec.rb +63 -12
- data/spec/lib/library/custom_package_spec.rb +0 -4
- data/spec/lib/library/file_spec.rb +0 -20
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 849ea0f664574300027e1f5311e06375aa50c001
|
|
4
|
+
data.tar.gz: 168af32a5c49219b57cb82db211f460aca5de1aa
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4c5fb35e3062723dd50c80e99944f59bd35267d6266b66a24c7141fe678e639b60133a1a4825bafb4061982bc1e328847c1bcf10d021eceea3549b75b9d0981f
|
|
7
|
+
data.tar.gz: ec6b81a0f7bcd8c1be3e3d907ed237dc06c76a3064228bd3b3de93364d50698372fe56878a849fc77c4d99acd6dd7908f5f654c4e43a5b6e2e3772eb2168b6e4
|
data/README.md
CHANGED
|
@@ -73,12 +73,14 @@ Package description:
|
|
|
73
73
|
```ruby
|
|
74
74
|
#packages/ruby.rb
|
|
75
75
|
require 'niman'
|
|
76
|
-
class RubyPackage < Niman::
|
|
76
|
+
class RubyPackage < Niman::CustomPackage
|
|
77
77
|
package_name :ubuntu, "ruby1.9.1"
|
|
78
78
|
package_name :centos, "ruby1.9.1"
|
|
79
79
|
end
|
|
80
80
|
```
|
|
81
|
+
|
|
81
82
|
In your `Nimanfile`:
|
|
83
|
+
|
|
82
84
|
```ruby
|
|
83
85
|
Niman::Recipe.configure do |config|
|
|
84
86
|
config.package "packages/ruby"
|
|
@@ -89,7 +91,7 @@ A custom package can have one or more configuration files inside of it:
|
|
|
89
91
|
|
|
90
92
|
```ruby
|
|
91
93
|
#packages/nginx
|
|
92
|
-
class NginxPackage < Niman::
|
|
94
|
+
class NginxPackage < Niman::CustomPackage
|
|
93
95
|
package_name :ubuntu, 'nginx'
|
|
94
96
|
|
|
95
97
|
file '/etc/nginx/nginx.conf' do |config|
|
|
@@ -103,6 +105,18 @@ class NginxPackage < Niman::Package
|
|
|
103
105
|
end
|
|
104
106
|
```
|
|
105
107
|
|
|
108
|
+
A custom package can also be used as a container for a bunch of configuration files
|
|
109
|
+
and shell commands without the need to specify `package_names`:
|
|
110
|
+
|
|
111
|
+
```ruby
|
|
112
|
+
#packages/ruby
|
|
113
|
+
require 'niman'
|
|
114
|
+
class RubyPackage < Niman::Library::CustomPackage
|
|
115
|
+
exec '\\curl -sSL https://get.rvm.io | bash -s stable'
|
|
116
|
+
exec 'rvm install ruby --latest'
|
|
117
|
+
end
|
|
118
|
+
```
|
|
119
|
+
|
|
106
120
|
### Apply `Nimanfile`
|
|
107
121
|
|
|
108
122
|
To apply a `Nimanfile` run:
|
data/lib/niman/installer.rb
CHANGED
|
@@ -17,6 +17,7 @@ module Niman
|
|
|
17
17
|
|
|
18
18
|
def install_package(package)
|
|
19
19
|
package_manager = managers.fetch(shell.os.to_sym) { raise Niman::InstallError, shell.os }
|
|
20
|
+
return unless package.installable?
|
|
20
21
|
if package.respond_to?(:package_names)
|
|
21
22
|
package_name = package.package_names.fetch(shell.os.to_sym) { raise Niman::InstallError, "Package has no support for #{shell.os}" }
|
|
22
23
|
shell.exec("#{package_manager} install #{package_name}", true)
|
|
@@ -5,9 +5,15 @@ module Niman
|
|
|
5
5
|
attr_reader :package_names, :files, :commands
|
|
6
6
|
|
|
7
7
|
def valid?
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
if installable?
|
|
9
|
+
package_names.keys.all?{|k| !package_names[k].empty?}
|
|
10
|
+
else
|
|
11
|
+
true
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def installable?
|
|
16
|
+
!package_names.nil? && !package_names.empty?
|
|
11
17
|
end
|
|
12
18
|
|
|
13
19
|
def package_name(os, name)
|
data/lib/niman/library/file.rb
CHANGED
data/lib/niman/provisioner.rb
CHANGED
|
@@ -23,31 +23,37 @@ module Niman
|
|
|
23
23
|
raise Niman::ConfigError, self.errors unless self.valid?
|
|
24
24
|
@instructions.each do |instruction|
|
|
25
25
|
yield(instruction) if block_given?
|
|
26
|
-
if instruction
|
|
27
|
-
custom_package_files(instruction)
|
|
28
|
-
end
|
|
29
|
-
if instruction.respond_to?(:commands)
|
|
30
|
-
custom_package_exec(instruction)
|
|
31
|
-
end
|
|
32
|
-
if instruction.respond_to?(:run)
|
|
26
|
+
if is_file(instruction)
|
|
33
27
|
@filehandler.run(instruction)
|
|
34
28
|
elsif instruction.respond_to?(:command)
|
|
35
29
|
command(instruction)
|
|
36
30
|
else
|
|
37
31
|
@installer.install(instruction)
|
|
38
32
|
end
|
|
33
|
+
|
|
34
|
+
if instruction.respond_to?(:files)
|
|
35
|
+
custom_package_files(instruction)
|
|
36
|
+
end
|
|
37
|
+
if instruction.respond_to?(:commands)
|
|
38
|
+
custom_package_exec(instruction)
|
|
39
|
+
end
|
|
39
40
|
end
|
|
40
41
|
end
|
|
41
42
|
|
|
42
43
|
private
|
|
43
44
|
|
|
45
|
+
def is_file(instruction)
|
|
46
|
+
instruction.respond_to?(:path) &&
|
|
47
|
+
instruction.respond_to?(:content)
|
|
48
|
+
end
|
|
49
|
+
|
|
44
50
|
def custom_package_exec(instruction)
|
|
45
51
|
return if instruction.commands.nil?
|
|
46
52
|
instruction.commands.each { |cmd| command(cmd) }
|
|
47
53
|
end
|
|
48
54
|
|
|
49
55
|
def custom_package_files(instruction)
|
|
50
|
-
instruction.files.each do |file|
|
|
56
|
+
Array(instruction.files).each do |file|
|
|
51
57
|
@filehandler.run(file)
|
|
52
58
|
end
|
|
53
59
|
end
|
data/lib/niman/version.rb
CHANGED
|
@@ -109,6 +109,17 @@ describe Niman::CLI::Application do
|
|
|
109
109
|
end
|
|
110
110
|
|
|
111
111
|
describe "custom package" do
|
|
112
|
+
def create_package(name, content, filename)
|
|
113
|
+
nginx_package = <<-EOS
|
|
114
|
+
require 'niman'
|
|
115
|
+
|
|
116
|
+
class #{name} < Niman::Library::CustomPackage
|
|
117
|
+
#{content}
|
|
118
|
+
end
|
|
119
|
+
EOS
|
|
120
|
+
FileUtils.mkdir("packages")
|
|
121
|
+
File.open(filename, "w") {|h| h.write(nginx_package)}
|
|
122
|
+
end
|
|
112
123
|
context 'is nonexistant' do
|
|
113
124
|
before do
|
|
114
125
|
nimanfile = <<-EOS
|
|
@@ -131,9 +142,6 @@ describe Niman::CLI::Application do
|
|
|
131
142
|
context 'is existant' do
|
|
132
143
|
before do
|
|
133
144
|
nginx_package = <<-EOS
|
|
134
|
-
require 'niman'
|
|
135
|
-
|
|
136
|
-
class Nginx < Niman::Library::CustomPackage
|
|
137
145
|
package_name :debian, 'nginx'
|
|
138
146
|
|
|
139
147
|
file '/etc/nginx/nginx.conf' do |config|
|
|
@@ -142,19 +150,17 @@ describe Niman::CLI::Application do
|
|
|
142
150
|
|
|
143
151
|
exec :sudo, 'ln -s /etc/nginx/sites-available/example.org /etc/nginx/sites-enabled/example.org'
|
|
144
152
|
exec 'touch ~/install_notes.txt'
|
|
145
|
-
end
|
|
146
153
|
EOS
|
|
147
154
|
|
|
148
155
|
nimanfile = <<-EOS
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
156
|
+
#-*- mode: ruby -*-
|
|
157
|
+
# vi: set ft=ruby :
|
|
158
|
+
require 'niman'
|
|
159
|
+
Niman::Recipe.configure do |config|
|
|
160
|
+
config.package "packages/nginx"
|
|
161
|
+
end
|
|
155
162
|
EOS
|
|
156
|
-
|
|
157
|
-
File.open("packages/nginx.rb", "w") {|h| h.write(nginx_package)}
|
|
163
|
+
create_package('Nginx', nginx_package, "packages/nginx.rb")
|
|
158
164
|
File.open(Niman::Recipe::DEFAULT_FILENAME, "w") {|h| h.write(nimanfile)}
|
|
159
165
|
allow(shell).to receive(:create_file)
|
|
160
166
|
allow(shell).to receive(:exec)
|
|
@@ -179,6 +185,51 @@ describe Niman::CLI::Application do
|
|
|
179
185
|
it 'creates install_notes.txt in home directory' do
|
|
180
186
|
expect(shell).to have_received(:exec).with('touch ~/install_notes.txt', false)
|
|
181
187
|
end
|
|
188
|
+
|
|
189
|
+
it 'installs package before creating configuration' do
|
|
190
|
+
expect(shell).to have_received(:exec).with("apt-get -y install nginx", true).ordered
|
|
191
|
+
expect(shell).to have_received(:create_file).with('/etc/nginx/nginx.conf', 'foo bar').ordered
|
|
192
|
+
expect(shell).to have_received(:exec).with('ln -s /etc/nginx/sites-available/example.org /etc/nginx/sites-enabled/example.org', true).ordered
|
|
193
|
+
end
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
context 'without package_name' do
|
|
197
|
+
before do
|
|
198
|
+
custom_ruby_package = <<-EOS
|
|
199
|
+
exec '\\curl -sSL https://get.rvm.io | bash -s stable'
|
|
200
|
+
exec 'rvm install ruby --latest'
|
|
201
|
+
EOS
|
|
202
|
+
|
|
203
|
+
nimanfile = <<-EOS
|
|
204
|
+
#-*- mode: ruby -*-
|
|
205
|
+
# vi: set ft=ruby :
|
|
206
|
+
require 'niman'
|
|
207
|
+
Niman::Recipe.configure do |config|
|
|
208
|
+
config.package "packages/ruby"
|
|
209
|
+
end
|
|
210
|
+
EOS
|
|
211
|
+
|
|
212
|
+
create_package('Ruby', custom_ruby_package, 'packages/ruby.rb')
|
|
213
|
+
File.open(Niman::Recipe::DEFAULT_FILENAME, "w") {|h| h.write(nimanfile)}
|
|
214
|
+
allow(shell).to receive(:create_file)
|
|
215
|
+
allow(shell).to receive(:exec)
|
|
216
|
+
application.apply
|
|
217
|
+
end
|
|
218
|
+
after do
|
|
219
|
+
FileUtils.rm_r("packages")
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
it 'does not execute package manager commands' do
|
|
223
|
+
expect(shell).to_not have_received(:exec).with('apt get -y install')
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
it 'executes curl command' do
|
|
227
|
+
expect(shell).to have_received(:exec).with('\curl -sSL https://get.rvm.io | bash -s stable', false)
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
it 'installs latest ruby' do
|
|
231
|
+
expect(shell).to have_received(:exec).with('rvm install ruby --latest',false)
|
|
232
|
+
end
|
|
182
233
|
end
|
|
183
234
|
end
|
|
184
235
|
end
|
|
@@ -27,10 +27,6 @@ describe Niman::Library::CustomPackage do
|
|
|
27
27
|
package.instance_variable_set(:@package_names, {})
|
|
28
28
|
end
|
|
29
29
|
|
|
30
|
-
it 'is not valid when package_names not set' do
|
|
31
|
-
expect(package.valid?).to be false
|
|
32
|
-
end
|
|
33
|
-
|
|
34
30
|
it 'is not valid when package name is empty' do
|
|
35
31
|
package.package_name :ubuntu, ''
|
|
36
32
|
expect(package.valid?).to be false
|
|
@@ -50,26 +50,6 @@ describe Niman::Library::File do
|
|
|
50
50
|
end
|
|
51
51
|
end
|
|
52
52
|
|
|
53
|
-
describe "#run" do
|
|
54
|
-
let(:path) { 'hello.txt' }
|
|
55
|
-
let(:content) { 'FooBar' }
|
|
56
|
-
subject(:file) { Niman::Library::File.new(path: path, content: content) }
|
|
57
|
-
before do
|
|
58
|
-
file.run
|
|
59
|
-
end
|
|
60
|
-
after do
|
|
61
|
-
File.delete(path)
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
it 'creates a file at path' do
|
|
65
|
-
expect(File.exists?(path)).to be true
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
it 'file has expected content' do
|
|
69
|
-
expect(File.read(path)).to eq content
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
|
|
73
53
|
describe "#description" do
|
|
74
54
|
let(:path) { 'hello.txt' }
|
|
75
55
|
subject(:file) { Niman::Library::File.new(path: path) }
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: niman
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.7
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jan Schulte
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2015-02-
|
|
11
|
+
date: 2015-02-22 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: thor
|