jisota 0.0.2 → 0.0.3

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: d30b81b24cc0fc7e8bb04cc88f243fc83983dd25
4
- data.tar.gz: 5b94aabed9dcb6f17c89e03bd2092d73d79067ae
3
+ metadata.gz: 6a9b6fbe8f6f04bd26ea84192e789ec977a30b28
4
+ data.tar.gz: 5ea5c9239da6eb97a9da00f1cf4123e86fe05f2a
5
5
  SHA512:
6
- metadata.gz: 0d75af1889780c695a60813c9fd8613f60ca0149151e24d39f5ebbdb27ae172eb797c5c570fd92fee1f5de4d877a466ca3079b9affc477ee241ca16168710269
7
- data.tar.gz: 6ad96e33cbd4c23b673d075b1b6efd8944218ba7cb2c28756a692d5151c45265f67018b3ebc661bfbc0285a7169544c0c92cef1197a0ece52c51475f05363e4f
6
+ metadata.gz: 1bb3c31c918cf9ab2a17196a6a64ec2ce60dc58c1c69d28148beef395a969253bf80ee0ce795c0fc228b47d10071cf2dfe4069cfed8d4e0344211a88d6451c4a
7
+ data.tar.gz: e6d0b2c5023dc125dbb1413b07802f3d9e1dd5ccdaf8c3404e4c7ef3c11d7f1c0067b0668f33819a4ad354181f72caa00a458101a3bdd529c28344798727ccaf
@@ -1,6 +1,20 @@
1
1
  # Jisota changelog
2
2
 
3
- ## 0.0.2 (current)
3
+ ## 0.0.3 (current)
4
+
5
+ ### Features
6
+ * Packages can have multiple sections of run and verify blocks
7
+
8
+ ### Improvements
9
+ * Rake tasks for vagrant
10
+ * Better acceptance test runner
11
+ * Ruby package also installs bundler gem
12
+
13
+ ### New packages
14
+ * nginx
15
+
16
+
17
+ ## 0.0.2
4
18
 
5
19
  ### Features
6
20
  * Create and Update actions on file upload
@@ -17,5 +31,6 @@
17
31
  * gem_install
18
32
  * nginx_passenger
19
33
 
34
+
20
35
  ## 0.0.1
21
36
  Initial version with basic functionality
data/README.md CHANGED
@@ -83,6 +83,36 @@ the params section below.
83
83
  Inside a run-block, packages can be called by their name, somewhat like a Ruby
84
84
  method. See the `apt` example above.
85
85
 
86
+ ### Having multiple run and verify blocks
87
+
88
+ Sometimes you need to verify only parts of the package. Just specify multiple
89
+ run and verify blocks:
90
+
91
+ package :install_awesome_service do
92
+ description "Installs a service and starts it"
93
+
94
+ run { cmd "sudo apt-get install awesome-service" }
95
+ verify { cmd "command-to-tell-if-service-is-installed" }
96
+
97
+ run { cmd "sudo service awesome start" }
98
+ verify { cmd "command-to-tell-if-service-is-started" }
99
+ end
100
+
101
+ You can optionally name each of these sections to give a more precise output:
102
+
103
+ package :install_awesome_service do
104
+ description "Installs a service and starts it"
105
+
106
+ section "Install the service from apt-get"
107
+ run { cmd "sudo apt-get install awesome-service" }
108
+ verify { cmd "command-to-tell-if-service-is-installed" }
109
+
110
+ section "Start the service"
111
+ run { cmd "sudo service awesome start" }
112
+ verify { cmd "command-to-tell-if-service-is-started" }
113
+ end
114
+
115
+
86
116
  ### Defining packages to be used in more than one project
87
117
 
88
118
  Defining packages with `Jisota.config` as above will only add the package to
@@ -233,6 +263,11 @@ You can also use package params and call packages inside these blocks:
233
263
  description "Install nginx with passenger module"
234
264
  param :config_file, required: true
235
265
 
266
+ ### nginx
267
+
268
+ description "Install nginx from apt"
269
+ param :config_file
270
+
236
271
  ### More packages?
237
272
 
238
273
  Jisota is a young gem. Please contribute with any packages that you think
@@ -333,7 +368,7 @@ a near-real environment that is easy to destroy and rebuild.
333
368
 
334
369
  Start the vagrant:
335
370
 
336
- $ (cd spec/vagrant && vagrant up)
371
+ $ rake vagrant:up
337
372
 
338
373
  Then run acceptance specs
339
374
 
@@ -341,11 +376,11 @@ Then run acceptance specs
341
376
 
342
377
  Or run individual specs. Some of them might take a while:
343
378
 
344
- $ rspec --tag type:acceptance spec/acceptance/some_spec.rb
379
+ $ ACCEPTANCE=1 rspec spec/acceptance/some_spec.rb
345
380
 
346
381
  To kill vagrant and start with a fresh machine:
347
382
 
348
- $ (cd spec/vagrant && vagrant destroy --force && vagrant up)
383
+ $ rake vagrant:rebuild
349
384
 
350
385
  ## Contributing
351
386
 
data/Rakefile CHANGED
@@ -4,7 +4,24 @@ require 'rspec/core/rake_task'
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
  namespace :spec do
6
6
  RSpec::Core::RakeTask.new(:acceptance) do |config|
7
- config.rspec_opts = "--tag type:acceptance"
7
+ ENV["ACCEPTANCE"] = "Oh_yeah"
8
+ end
9
+ end
10
+
11
+ namespace :vagrant do
12
+ desc "Starts the vagrant VM"
13
+ task :up do
14
+ system "(cd spec/vagrant && vagrant up)"
15
+ end
16
+
17
+ desc "Destroys and starts the vagrant VM"
18
+ task :rebuild do
19
+ system '(cd spec/vagrant && vagrant destroy --force && vagrant up)'
20
+ end
21
+
22
+ desc "Shuts dows the vagrant VM"
23
+ task :halt do
24
+ system "(cd spec/vagrant && vagrant halt)"
8
25
  end
9
26
  end
10
27
 
@@ -18,8 +18,8 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "net-ssh", "~> 2.8.0"
22
- spec.add_dependency "net-scp", "~> 1.1.2"
21
+ spec.add_dependency "net-ssh", "~> 2.8"
22
+ spec.add_dependency "net-scp", "~> 1.2"
23
23
 
24
24
  spec.add_development_dependency "bundler", "~> 1.5"
25
25
  spec.add_development_dependency "rake"
@@ -1,15 +1,22 @@
1
1
  module Jisota
2
2
  class Package
3
- attr_accessor :name, :description, :params, :run_block, :verify_block
3
+ attr_accessor :name, :description, :params, :sections
4
4
 
5
5
  def initialize(name = nil, &block)
6
6
  @params = []
7
+ @sections = []
7
8
  @name = name
8
9
  DSL.new(self).evaluate(&block) if block_given?
9
10
  end
10
11
 
11
12
  alias_method :key, :name
12
13
 
14
+ class InvalidBlockOrder < StandardError; end
15
+
16
+ class Section
17
+ attr_accessor :description, :run_block, :verify_block
18
+ end
19
+
13
20
  class DSL < DSLBase
14
21
  def initialize(target)
15
22
  @target = target
@@ -23,12 +30,30 @@ module Jisota
23
30
  @target.params << Param.new(name, options)
24
31
  end
25
32
 
33
+ def section(description)
34
+ @target.sections << Section.new.tap do |section|
35
+ section.description = description
36
+ end
37
+ end
38
+
26
39
  def run(&block)
27
- @target.run_block = ScriptBlock.new(&block)
40
+ run_block = ScriptBlock.new(&block)
41
+ section = @target.sections.last
42
+ if section && section.run_block.nil?
43
+ section.run_block = run_block
44
+ else
45
+ @target.sections << Section.new.tap do |new_section|
46
+ new_section.run_block = run_block
47
+ end
48
+ end
28
49
  end
29
50
 
30
51
  def verify(&block)
31
- @target.verify_block = ScriptBlock.new(&block)
52
+ section = @target.sections.last
53
+ if section.nil? || section.verify_block
54
+ raise InvalidBlockOrder, "A verify block must come after a run block"
55
+ end
56
+ section.verify_block = ScriptBlock.new(&block)
32
57
  end
33
58
  end
34
59
  end
@@ -18,7 +18,7 @@ module Jisota
18
18
  def execute(context)
19
19
  context.param_scope(parse_params) do
20
20
  context.logger.system_message("Package #{self}") do
21
- execute_verify_and_run(context)
21
+ execute_package(context)
22
22
  end
23
23
  end
24
24
  end
@@ -39,23 +39,33 @@ module Jisota
39
39
  ParamParser.new(package.params, args).parse
40
40
  end
41
41
 
42
- def execute_verify_and_run(context)
43
- if package.verify_block
44
- verify_script = package.verify_block.evaluate(context)
42
+ def execute_package(context)
43
+ package.sections.each do |section|
44
+ context.logger.system_message("Section #{section.description}") do
45
+ result = execute_section(section, context)
46
+ return false unless result
47
+ end
48
+ end
49
+ true
50
+ end
51
+
52
+ def execute_section(section, context)
53
+ if section.verify_block
54
+ verify_script = section.verify_block.evaluate(context)
45
55
  result = verify_script.execute(context)
46
56
  if result
47
- context.logger.system_message("Package #{self} already installed")
57
+ context.logger.system_message("Section #{section.description} already installed")
48
58
  true
49
59
  else
50
- execute_run(context)
60
+ execute_run(section, context)
51
61
  end
52
62
  else
53
- execute_run(context)
63
+ execute_run(section, context)
54
64
  end
55
65
  end
56
66
 
57
- def execute_run(context)
58
- run_script = package.run_block.evaluate(context)
67
+ def execute_run(section, context)
68
+ run_script = section.run_block.evaluate(context)
59
69
  run_script.execute(context)
60
70
  end
61
71
  end
@@ -0,0 +1,25 @@
1
+ require 'jisota'
2
+
3
+ Jisota.global_config do
4
+ package :nginx do
5
+ description "Install nginx from apt"
6
+ param :config_file
7
+
8
+ section "Install nginx aåt package"
9
+ run { apt :nginx }
10
+
11
+ section "Files"
12
+ run do
13
+ if config_file
14
+ upload from: config_file, to: '/etc/nginx/nginx.conf' do
15
+ update { cmd "sudo service nginx restart || true" }
16
+ end
17
+ end
18
+ end
19
+
20
+ section "Start nginx"
21
+ run { cmd "sudo service nginx start" }
22
+ verify { cmd "ps -C nginx" }
23
+ end
24
+ end
25
+
@@ -5,11 +5,18 @@ Jisota.global_config do
5
5
  description "Install nginx with passenger module"
6
6
  param :config_file, required: true
7
7
 
8
+ section "Prerequisites"
8
9
  run do
9
10
  gem_install :passenger
10
11
  apt "libcurl4-openssl-dev"
11
- nginx_passenger_install
12
+ end
13
+
14
+ section "Install nginx with passenger"
15
+ run { cmd 'sudo passenger-install-nginx-module --auto --auto-download --prefix=/opt/nginx' }
16
+ verify { cmd 'which /opt/nginx/sbin/nginx' }
12
17
 
18
+ section "Files"
19
+ run do
13
20
  upload from: config_file, to: '/opt/nginx/conf/nginx.conf' do
14
21
  update { cmd "sudo service nginx restart" }
15
22
  end
@@ -17,17 +24,9 @@ Jisota.global_config do
17
24
  upload from: "package_files/nginx_passenger/nginx_service", to: "/etc/init.d/nginx" do
18
25
  create { cmd 'sudo update-rc.d nginx defaults 99' }
19
26
  end
20
-
21
- nginx_passenger_start
22
27
  end
23
- end
24
-
25
- package :nginx_passenger_install do
26
- run { cmd 'sudo passenger-install-nginx-module --auto --auto-download --prefix=/opt/nginx' }
27
- verify { cmd 'which /opt/nginx/sbin/nginx' }
28
- end
29
28
 
30
- package :nginx_passenger_start do
29
+ section "Start nginx"
31
30
  run { cmd "sudo service nginx start" }
32
31
  verify { cmd "ps -C nginx" }
33
32
  end
@@ -21,9 +21,11 @@ Jisota.global_config do
21
21
  sudo make install
22
22
  }
23
23
  end
24
-
25
24
  verify do
26
25
  cmd "ruby -v | grep #{version}"
27
26
  end
27
+
28
+ section "Install bundler"
29
+ run { gem_install :bundler }
28
30
  end
29
31
  end
@@ -1,3 +1,3 @@
1
1
  module Jisota
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -31,28 +31,13 @@ module Jisota
31
31
  end
32
32
  end
33
33
 
34
- describe "#run_block" do
35
- it "has one" do
36
- package = Package.new
37
- package.run_block = :foo
38
- expect(package.run_block).to eq(:foo)
39
- end
40
- end
41
-
42
- describe "#verify_block" do
43
- it "has one" do
44
- package = Package.new
45
- package.verify_block = :foo
46
- expect(package.verify_block).to eq(:foo)
47
- end
48
- end
49
-
50
34
  describe Package::DSL do
51
35
  it "initializes using DSL" do
52
36
  package = Package.new(:my_awesome_package) do
53
37
  description "Does cool stuff"
54
38
  param :foo
55
39
  param :bar, default: 42
40
+
56
41
  run { cmd "touch #{foo}" }
57
42
  verify { cmd "[ -f foo ]" }
58
43
  end
@@ -62,8 +47,47 @@ module Jisota
62
47
  expect(package.params.size).to eq(2)
63
48
  expect(package.params.last.name).to eq(:bar)
64
49
  expect(package.params.last.options).to eq({ default: 42 })
65
- expect(package.run_block).to be_a(ScriptBlock)
66
- expect(package.verify_block).to be_a(ScriptBlock)
50
+ expect(package.sections.size).to eq(1)
51
+ expect(package.sections.first.run_block).to be_a(ScriptBlock)
52
+ expect(package.sections.first.verify_block).to be_a(ScriptBlock)
53
+ end
54
+
55
+ it "has many run and verify blocks" do
56
+ package = Package.new(:something) do
57
+ run { cmd "touch foo" }
58
+ verify { cmd "[ -f foo ]" }
59
+
60
+ run { cmd "touch bar" }
61
+
62
+ run { cmd "touch baz" }
63
+ verify { cmd "[ -f baz ]" }
64
+ end
65
+
66
+ expect(package.sections.size).to eq(3)
67
+ end
68
+
69
+ it "must have a run block per verify block" do
70
+ expect {
71
+ package = Package.new { verify { } }
72
+ }.to raise_exception(Package::InvalidBlockOrder)
73
+
74
+ expect {
75
+ package = Package.new do
76
+ run { }
77
+ verify { }
78
+ verify { }
79
+ end
80
+ }.to raise_exception(Package::InvalidBlockOrder)
81
+ end
82
+
83
+ it "accepts section names" do
84
+ package = Package.new(:foo) do
85
+ section "do amazing stuff"
86
+ run {}
87
+ end
88
+
89
+ expect(package.sections.size).to eq(1)
90
+ expect(package.sections.first.description).to eq("do amazing stuff")
67
91
  end
68
92
  end
69
93
  end
@@ -13,7 +13,11 @@ require './spec/support/acceptance_helpers'
13
13
 
14
14
  RSpec.configure do |config|
15
15
  config.filter_run :focus
16
- config.filter_run_excluding type: :acceptance unless config.filter_run[:type] == "acceptance"
16
+ if ENV["ACCEPTANCE"]
17
+ config.filter_run type: :acceptance
18
+ else
19
+ config.filter_run_excluding type: :acceptance
20
+ end
17
21
  config.run_all_when_everything_filtered = true
18
22
 
19
23
  config.order = :random
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jisota
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lasse Skindstad Ebert
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-08 00:00:00.000000000 Z
11
+ date: 2014-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-ssh
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 2.8.0
19
+ version: '2.8'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 2.8.0
26
+ version: '2.8'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: net-scp
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 1.1.2
33
+ version: '1.2'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 1.1.2
40
+ version: '1.2'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -168,6 +168,7 @@ files:
168
168
  - lib/jisota/package_script.rb
169
169
  - lib/jisota/packages/apt.rb
170
170
  - lib/jisota/packages/gem_install.rb
171
+ - lib/jisota/packages/nginx.rb
171
172
  - lib/jisota/packages/nginx_passenger.rb
172
173
  - lib/jisota/packages/ruby.rb
173
174
  - lib/jisota/param.rb
@@ -266,4 +267,3 @@ test_files:
266
267
  - spec/test_files/nginx_default.conf
267
268
  - spec/vagrant/Vagrantfile
268
269
  - spec/vagrant/ssh_key
269
- has_rdoc: