niman 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cec92b45c738e4089f9d9dd278f4c6f84b86e161
4
- data.tar.gz: bbbfe3217ab77454b7339aefc5826bf4b5443c91
3
+ metadata.gz: 849ea0f664574300027e1f5311e06375aa50c001
4
+ data.tar.gz: 168af32a5c49219b57cb82db211f460aca5de1aa
5
5
  SHA512:
6
- metadata.gz: 7233e582d4389918020a9ffb1a6ba067841c1d0101bc6fc562f8d1d55fb473786b0bf88617b1294cb124401591d6b0c78575e31e0e6fd4b2b9e41d574de962db
7
- data.tar.gz: 9c5a3030863723f7df305f0c26dc390af35c6f59f53af716b906585d8f0eebcc0db1f11fb58e9e3faa5ecf7036e36f64dca26eeb742c255373922ad5febfb829
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::Package
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::Package
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:
@@ -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
- !package_names.nil? &&
9
- !package_names.empty? &&
10
- package_names.keys.all?{|k| !package_names[k].empty?}
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)
@@ -16,10 +16,6 @@ module Niman
16
16
  ['file path must not be nil and empty']
17
17
  end
18
18
 
19
- def run
20
- ::File.open(::File.expand_path(path), "w") { |handle| handle.write(content) }
21
- end
22
-
23
19
  def description
24
20
  "File #{path}"
25
21
  end
@@ -18,6 +18,10 @@ module Niman
18
18
  def errors
19
19
  'package name must not be empty'
20
20
  end
21
+
22
+ def installable?
23
+ true
24
+ end
21
25
  end
22
26
  end
23
27
  end
@@ -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.respond_to?(:files)
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
@@ -1,3 +1,3 @@
1
1
  module Niman
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -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
- #-*- mode: ruby -*-
150
- # vi: set ft=ruby :
151
- require 'niman'
152
- Niman::Recipe.configure do |config|
153
- config.package "packages/nginx"
154
- end
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
- FileUtils.mkdir("packages")
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.6
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-21 00:00:00.000000000 Z
11
+ date: 2015-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor