borg-rb 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NjdkOGNhMjJlZGQwOTc2NTVhZjMzYTkwODdlMDVjZWM1M2ExYjRlZA==
4
+ OWZmNWNmZDM1M2Y1YzdlNGIwNzQ4ZmJlNGI0NTVlMTMyODAyMTNiYw==
5
5
  data.tar.gz: !binary |-
6
- OWEzNzg2OGIxNDE2YjdlNTM5NjE3Zjc5ZmFiMjZmNGFhZDlmOGZlOQ==
6
+ OTU4ZDg4MTQ3NjlkYjkyZTFhMWJmNTdhOTI2MWYyNWRmZDRmMzZlNA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- Nzg3Y2QyMzhjYWZjZDQ1Zjc2ZWYyYzg1OGUxZmE2YmIwYzRiY2I5NWE4ZjJl
10
- YjVkNTdkZTBiMWRkNDc2YmIxZTMzZTJlNTdjOTY4M2U2MWNhNzU1ZjQ5Yzgz
11
- MTA4YmZmNDUwNTdjZWJjNjllYzMzMzUxMzVhMDk3MDQ4MDVjNGQ=
9
+ MTJjNmY1MjVhMTEzY2RlNWE5ZmI0ZTVlYWQ1OGE1OWFkMWM0ZjU5ZDZkOTRj
10
+ ZmFhNzY5ODE4MjBhNTQ3MTkwOWMzNjk0OGY1YjM4MDE5NWIzYjJmNTY1ZWEz
11
+ ZDRmMjkyM2IwZDcyZGYzYzA5MWYzNDEyZmU3MGE0NzhiNDcxNjQ=
12
12
  data.tar.gz: !binary |-
13
- NmRlNWFlMGI5MGUwYjQ5MTJhM2I1YjQ3MGU3MDdlMDVmMDU5ZjAxODM5NjBk
14
- NzRhNWViNzQ5NWRlNWIyNmMxYmU5NTA4NDE4MzExOWRlODhmNGJjMDYyODUy
15
- ZjMxMDVkZjFjMjZjMjRlODQ5NzNlYTYzZDdjN2I1ZmE2NjU3NmI=
13
+ NjA5ZDBhMGU2ZmI0ODkwNTI0ZjI0OGU4YzlmNmQyMDc3ZjFhMTUxODBlMGUy
14
+ MmFmOTc5ZjE1ZjljZjA0MTIwOWIwOGE2ZTJiMTY4ZTVlYzg4YWM0ZDYwYTc5
15
+ Mzk2OWQ1ZmU2YWIzYWEzZWNmMjZlN2I0YzY0NTgyZjA4NDhjNzI=
data/CHANGELOG.md CHANGED
@@ -1,9 +1,10 @@
1
- ## Current (Unreleased)
1
+ ## HEAD
2
2
 
3
- ## 0.0.3 / 3-22-2013
3
+ ## 0.0.4 / 3-22-2013
4
4
 
5
5
  * Fix load problem in Capfile in generated skeleton (0.0.2)
6
- * Change load borg-rb to a require
6
+ * Change load borg-rb to a require (0.0.3)
7
+ * Allow access to `application` and `stage` in an application configuration by creating a capistrano variable for them
7
8
 
8
9
 
9
10
  ## 0.0.1 / 3-21-2013
data/README.md CHANGED
@@ -67,11 +67,11 @@ Borg provides a application and stage config setup.
67
67
  One can define applications with the format.
68
68
  ``` ruby
69
69
  application :app_name do
70
- do things needed to setup the application environment.
70
+ # do things needed to setup the application environment.
71
71
  end
72
72
 
73
73
  stage :app_name, :stage_name do
74
- do things for specific stage for the applications.
74
+ # do things for specific stage for the applications.
75
75
  end
76
76
  ```
77
77
 
@@ -90,3 +90,5 @@ to be load and the deploy task be run against all of them.
90
90
  3. Commit your changes (`git commit -am 'Add some feature'`)
91
91
  4. Push to the branch (`git push origin my-new-feature`)
92
92
  5. Create new Pull Request
93
+
94
+ Ruby Style Guidelines: We like this one https://github.com/styleguide/ruby
data/bin/borg CHANGED
@@ -13,6 +13,6 @@ require 'borg/server/base'
13
13
  require 'borg/servers/base'
14
14
 
15
15
  # Ensure ruby 1.9.X
16
- raise "Ruby 1.9.X required" unless RUBY_VERSION =~ /^1\.9\.\d$/
16
+ raise "Ruby 1.9.X required" unless RUBY_VERSION =~ /^1\.9\.\d$/ || RUBY_VERSION =~ /^2\.0\.\d$/
17
17
 
18
18
  Capistrano::CLI.execute
@@ -6,12 +6,10 @@ module Borg
6
6
  base.send :alias_method, :execute_requested_actions, :execute_requested_actions_with_applications
7
7
  end
8
8
 
9
+ # TODO: documentation for `options`, where does it come from?
9
10
  def execute_requested_actions_with_applications(config)
10
-
11
- load_applications config
12
-
13
- separate_actions_and_applications config
14
-
11
+ load_applications(config)
12
+ separate_actions_and_applications(config)
15
13
  if options[:applications].empty? or Thread.current[:borg_application]
16
14
  Thread.current[:borg_application].load_into config if Thread.current[:borg_application]
17
15
  execute_requested_actions_without_applications(config)
@@ -26,17 +24,14 @@ module Borg
26
24
 
27
25
  private
28
26
 
29
- def load_applications config
30
- # load applications
27
+ def load_applications(config)
31
28
  unless @apps_loaded
32
- Dir["./cap/applications/**/*.rb"].each do |file|
33
- config.load file
34
- end
29
+ Dir["./cap/applications/**/*.rb"].each { |file| config.load(file) }
35
30
  @apps_loaded = true
36
31
  end
37
32
  end
38
33
 
39
- def separate_actions_and_applications config
34
+ def separate_actions_and_applications(config)
40
35
  options[:applications] = []
41
36
  found_non_application = false
42
37
  options[:actions] = Array(options[:actions]).keep_if do |action|
@@ -63,4 +58,4 @@ module Borg
63
58
  end
64
59
  end
65
60
 
66
- Capistrano::CLI.send :include, Borg::CLI::Applications
61
+ Capistrano::CLI.send(:include, Borg::CLI::Applications)
@@ -39,6 +39,14 @@ module Borg
39
39
  end
40
40
 
41
41
  def load_into config
42
+ if config.respond_to?(:application)
43
+ # Undefine the stage method now that the app:stage config is created
44
+ config_metaclass = class << config; self; end
45
+ config_metaclass.send(:undef_method, 'application')
46
+
47
+ # Create a capistrano variable for stage
48
+ config.instance_exec(@name, &(lambda { |name| set :application, name }))
49
+ end
42
50
  @execution_blocks.each {|blk| config.load &blk}
43
51
  end
44
52
  end
@@ -1,8 +1,7 @@
1
1
  module Borg
2
2
  module Configuration
3
3
  module Stages
4
-
5
- def stage (app, name, &block)
4
+ def stage(app, name, &block)
6
5
  app = app.to_sym
7
6
  name = name.to_sym
8
7
  application app unless @applications[app]
@@ -20,23 +19,34 @@ module Borg
20
19
  class Stage
21
20
  attr_accessor :execution_blocks
22
21
  attr_accessor :parent
22
+
23
+ # TODO: We might want to name this differently
23
24
  def name
24
25
  "#{parent.name}:#{@name}"
25
26
  end
26
27
 
27
- def initialize name, parent
28
+ def initialize(name, parent)
28
29
  @execution_blocks = []
29
30
  @name = name
30
31
  @parent = parent
31
32
  end
32
33
 
33
- def load_into config
34
- parent.load_into config
35
- @execution_blocks.each {|blk| config.load &blk}
34
+ def load_into(config)
35
+ if config.respond_to?(:stage)
36
+ # Undefine the stage method now that the app:stage config is created
37
+ config_metaclass = class << config; self; end
38
+ config_metaclass.send(:undef_method, 'stage')
39
+
40
+ # Create a capistrano variable for stage
41
+ config.instance_exec(@name, &(lambda { |name| set :stage, name }))
42
+ end
43
+
44
+ parent.load_into(config)
45
+ @execution_blocks.each { |blk| config.load(&blk) }
36
46
  end
37
47
  end
38
48
  end
39
49
  end
40
50
  end
41
51
 
42
- Capistrano::Configuration.send :include, Borg::Configuration::Stages
52
+ Capistrano::Configuration.send(:include, Borg::Configuration::Stages)
data/lib/borg/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Borg
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -0,0 +1,116 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'borg app:stage task' do
4
+ include_context 'acceptance'
5
+
6
+ # TODO: probably want to have some factory that generates what we want in an app config to DRY this out
7
+ let(:basic_app_config) {
8
+ <<-RUBY
9
+ application :app do
10
+ task :some_task do
11
+ end
12
+ end
13
+ RUBY
14
+ }
15
+
16
+ let(:app_config_with_stages) {
17
+ <<-RUBY
18
+ application :app do
19
+ task :common_task do
20
+ end
21
+ end
22
+ stage :app, :prd do
23
+ task :prd_task do
24
+ end
25
+ end
26
+ stage :app, :stg do
27
+ task :stg_task do
28
+ end
29
+ end
30
+ RUBY
31
+ }
32
+
33
+ let(:app_config_with_display_app_task) {
34
+ <<-RUBY
35
+ application :app do
36
+ task :display_app do
37
+ puts "The application is set to: \#{application}"
38
+ end
39
+ end
40
+ RUBY
41
+ }
42
+
43
+ let(:app_config_with_stage_with_display_app_task) {
44
+ <<-RUBY
45
+ stage :app, :prd do
46
+ task :display_app do
47
+ puts "The application is set to: \#{application}"
48
+ end
49
+ end
50
+ RUBY
51
+ }
52
+
53
+ before do
54
+ assert_execute('borgify')
55
+ end
56
+
57
+ context "app with no stages" do
58
+ before do
59
+ environment.create_file('cap/applications/app.rb', basic_app_config)
60
+ end
61
+
62
+ it "allows us to run tasks for that app" do
63
+ # a task defined for the app
64
+ assert_execute('borg', 'app', 'some_task')
65
+
66
+ # an undefined task
67
+ expect(execute('borg', 'app', 'undefined_task')).to_not succeed
68
+
69
+ # an undefined app
70
+ expect(execute('borg', 'undefined_app', 'some_task')).to_not succeed
71
+ end
72
+ end
73
+
74
+ context "app with stages: prd, stg" do
75
+ before do
76
+ environment.create_file('cap/applications/app.rb', app_config_with_stages)
77
+ end
78
+
79
+ it "allows us to set common/stage-specific tasks" do
80
+ # commonly defined tasks
81
+ assert_execute('borg', 'app:prd', 'common_task')
82
+ assert_execute('borg', 'app:stg', 'common_task')
83
+
84
+ # stage specific tasks in their respective stages
85
+ assert_execute('borg', 'app:prd', 'prd_task')
86
+ assert_execute('borg', 'app:stg', 'stg_task')
87
+
88
+ # stage specific tasks in other stages
89
+ expect(execute('borg', 'app:stg', 'prd_task')).to_not succeed
90
+ expect(execute('borg', 'app:prd', 'stg_task')).to_not succeed
91
+ end
92
+ end
93
+
94
+ context 'app with a task `display_app` which prints `application`' do
95
+ before do
96
+ environment.create_file('cap/applications/app.rb', app_config_with_display_app_task)
97
+ end
98
+
99
+ it 'the task prints `app`' do
100
+ result = execute('borg', 'app', 'display_app')
101
+ expect(result.stdout).to match(/The application is set to: app/)
102
+ end
103
+ end
104
+
105
+ context 'app with stages: prd, and a task `display_app` which prints `application`' do
106
+ before do
107
+ environment.create_file('cap/applications/app.rb', app_config_with_stage_with_display_app_task)
108
+ end
109
+
110
+ it 'the task prints `app`' do
111
+ result = execute('borg', 'app:prd', 'display_app')
112
+ expect(result.stdout).to match(/The application is set to: app/)
113
+ end
114
+ end
115
+
116
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'borg app:stage task' do
4
+ include_context 'acceptance'
5
+
6
+ let(:stage_test_config) {
7
+ <<-RUBY
8
+ stage :app, :prd do
9
+ task :display_stage do
10
+ puts "The stage is set to: \#{stage}"
11
+ end
12
+ end
13
+ RUBY
14
+ }
15
+
16
+ before do
17
+ assert_execute('borgify')
18
+ end
19
+
20
+ context 'app with stages: prd, and a task `display_stage` which prints `stage`' do
21
+ before do
22
+ environment.create_file('cap/applications/app.rb', stage_test_config)
23
+ end
24
+
25
+ it 'the task prints `prd`' do
26
+ result = execute('borg', 'app:prd', 'display_stage')
27
+ expect(result.stdout).to match(/The stage is set to: prd/)
28
+ end
29
+ end
30
+
31
+ end
@@ -3,8 +3,7 @@ require "pathname"
3
3
  require "childprocess"
4
4
 
5
5
  module Support
6
- # This class creates a temporary directory to act as the working directory
7
- #
6
+ # This class creates a temporary directory to act as the working directory for our tests
8
7
  # Modified from: https://github.com/mitchellh/vagrant/blob/master/spec/support/isolated_environment.rb
9
8
  class IsolatedEnvironment
10
9
  ROOT_DIR = Pathname.new(File.expand_path("../../", __FILE__))
@@ -12,24 +11,12 @@ module Support
12
11
  attr_reader :workdir, :workdir_path
13
12
 
14
13
  def initialize
15
- # Create a temporary directory for our work
16
14
  @workdir = TempDir.new("borg")
17
- @workdir_path = Pathname.new(TempDir.new("borg").path)
18
- # puts "Initialize isolated environment: #{@workdir_path.to_s}"
19
- end
20
-
21
- # Copies a skeleton into this isolated environment. This is useful
22
- # for testing environments that require a complex setup.
23
- #
24
- # @param [String] name Name of the skeleton in the root directory.
25
- def skeleton!(name)
26
- # Copy all the files into the home directory
27
- source = Dir.glob(ROOT_DIR.join(name).join("*").to_s)
28
- FileUtils.cp_r(source, @workdir.to_s)
15
+ @workdir_path = Pathname.new(@workdir.path)
29
16
  end
30
17
 
31
18
  # Executes a command in the context of this isolated environment.
32
- # Any command executed will therefore see our temporary directory
19
+ # Any command executed will therefore see our working directory
33
20
  # as the home directory.
34
21
  def execute(command, *argN)
35
22
  # Determine the options
@@ -42,17 +29,47 @@ module Support
42
29
  # Add the options to be passed on
43
30
  argN << options
44
31
 
45
- # Execute, logging out the stdout/stderr as we get it
46
- # puts("Executing: #{[command].concat(argN).inspect}")
32
+ # Execute
47
33
  Support::Subprocess.execute(command, *argN) do |type, data|
48
34
  yield type, data if block_given?
49
35
  end
50
36
  end
51
37
 
52
- # Closes the environment and cleans it up
38
+ # Remove everything created in the environment
53
39
  def close
54
- # puts "Removing isolated environment: #{@workdir.path}"
55
- FileUtils.rm_rf(@workdir.path)
40
+ FileUtils.rm_rf(@workdir_path)
41
+ end
42
+
43
+ # Creates a new file in the isolated environment
44
+ #
45
+ # @param [String] filename Name of destination file's path relative to the isolated environment's root
46
+ # @param [String] content The stuff
47
+ def create_file(filename, content)
48
+ Dir.chdir(@workdir_path) do
49
+ FileUtils.mkdir_p(File.dirname(filename)) unless File.directory?(File.dirname(filename))
50
+ File.open(filename, "w") { |file| file.write(content) }
51
+ end
52
+ end
53
+
54
+ # Copies a directory into this isolated environment.
55
+ #
56
+ # @param [String] src_dir Name of the source directory's path relative to the root directory.
57
+ # @param [String] dest_dir Name of path relative to the isolated environment's root
58
+ def copy_dir(src_dir, dest_dir = "/")
59
+ # Copy all the files into the home directory
60
+ source = Dir.glob(ROOT_DIR.join(name).join("*").to_s)
61
+ FileUtils.cp_r(source, @workdir_path.to_s)
62
+ end
63
+
64
+ # Copies a file into this isolated environment.
65
+ #
66
+ # @param [String] src_file Name of the source file's path relative to the root directory.
67
+ # @param [String] dest_file Name of destination file's path relative to the isolated environment's root
68
+ def copy_file(src_file, dest_file)
69
+ Dir.chdir(@workdir_path) do
70
+ FileUtils.mkdir_p(File.dirname(dest_file)) unless File.directory?(File.dirname(dest_file))
71
+ FileUtils.cp(ROOT_DIR.join(src_file), dest_file)
72
+ end
56
73
  end
57
74
  end
58
75
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: borg-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Identified
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-26 00:00:00.000000000 Z
11
+ date: 2013-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capistrano
@@ -135,8 +135,10 @@ files:
135
135
  - skeleton/cap/recipes/.gitkeep
136
136
  - skeleton/lib/.gitkeep
137
137
  - skeleton/mygem.gemspec.skeleton
138
+ - spec/acceptance/application_spec.rb
138
139
  - spec/acceptance/borgify_plugin_spec.rb
139
140
  - spec/acceptance/borgify_spec.rb
141
+ - spec/acceptance/stage_spec.rb
140
142
  - spec/lib/borg/cli/applications_spec.rb
141
143
  - spec/lib/borg/configuration/applications_spec.rb
142
144
  - spec/lib/borg/configuration/assimilator_spec.rb
@@ -173,8 +175,10 @@ signing_key:
173
175
  specification_version: 4
174
176
  summary: Ruby-based software provisioning and deployment framework
175
177
  test_files:
178
+ - spec/acceptance/application_spec.rb
176
179
  - spec/acceptance/borgify_plugin_spec.rb
177
180
  - spec/acceptance/borgify_spec.rb
181
+ - spec/acceptance/stage_spec.rb
178
182
  - spec/lib/borg/cli/applications_spec.rb
179
183
  - spec/lib/borg/configuration/applications_spec.rb
180
184
  - spec/lib/borg/configuration/assimilator_spec.rb