org-converge 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -24,6 +24,8 @@ that one ought to be able to reproduce.
24
24
 
25
25
  # Example usage
26
26
 
27
+ Inspecting the files that would be tangled:
28
+
27
29
  $ org-converge spec/converge_examples/basic_tangle/setup.org --showfiles
28
30
 
29
31
  ---------- conf.yml --------------
@@ -35,6 +37,8 @@ that one ought to be able to reproduce.
35
37
  host: somewhere-example.local
36
38
  password: 111111111
37
39
 
40
+ Executing the tangle:
41
+
38
42
  $ org-converge spec/converge_examples/basic_tangle/setup.org --tangle
39
43
 
40
44
  I, [2014-03-24T00:21:08.073506 #660] INFO -- : Tangling 1 files...
@@ -42,6 +46,51 @@ that one ought to be able to reproduce.
42
46
  I, [2014-03-24T00:21:08.075562 #660] INFO -- : END(conf.yml): done.
43
47
  I, [2014-03-24T00:21:08.075638 #660] INFO -- : Tangling succeeded!
44
48
 
49
+ Run the code blocks in sequence:
50
+
51
+ $ org-converge spec/converge_examples/runlist_example/setup.org --runmode=sequential
52
+ I, [2014-04-02T01:18:17.336255 #65462] INFO -- : Tangling 0 files...
53
+ I, [2014-04-02T01:18:17.336376 #65462] INFO -- : Tangling succeeded!
54
+ I, [2014-04-02T01:18:17.336698 #65462] INFO -- : Tangling 2 scripts within directory: /Users/mariko/repos/org-converge/run...
55
+ I, [2014-04-02T01:18:17.340638 #65462] INFO -- : sh(65466) -- started with pid 65466
56
+ I, [2014-04-02T01:18:22.365128 #65462] INFO -- : sh(65466) -- exited with code 0
57
+ I, [2014-04-02T01:18:22.398983 #65462] INFO -- : ruby(65469) -- started with pid 65469
58
+ I, [2014-04-02T01:18:23.013195 #65462] INFO -- : ruby(65469) -- exited with code 0
59
+ I, [2014-04-02T01:18:23.013354 #65462] INFO -- : Run has completed successfully.
60
+
61
+ Running the code blocks in parallel mode is also possible:
62
+
63
+ $ org-converge spec/converge_examples/basic_run_example/setup.org --runmode=parallel
64
+
65
+ I, [2014-04-02T01:16:27.660259 #65126] INFO -- : Tangling 0 files...
66
+ I, [2014-04-02T01:16:27.660390 #65126] INFO -- : Tangling succeeded!
67
+ I, [2014-04-02T01:16:27.661640 #65126] INFO -- : Running code blocks now! (3 runnable blocks found in total)
68
+ I, [2014-04-02T01:16:27.732659 #65126] INFO -- : sh(65157) -- started with pid 65157
69
+ I, [2014-04-02T01:16:27.732819 #65126] INFO -- : ruby(65158) -- started with pid 65158
70
+ I, [2014-04-02T01:16:27.732915 #65126] INFO -- : python(65160) -- started with pid 65160
71
+ I, [2014-04-02T01:16:27.733565 #65126] INFO -- : sh(65157) -- Writing! 1
72
+ I, [2014-04-02T01:16:27.771819 #65126] INFO -- : sh(65157) -- Writing! 2
73
+ I, [2014-04-02T01:16:27.914407 #65126] INFO -- : python(65160) -- 0
74
+ I, [2014-04-02T01:16:27.914674 #65126] INFO -- : python(65160) -- 1
75
+ I, [2014-04-02T01:16:27.914887 #65126] INFO -- : python(65160) -- 2
76
+ I, [2014-04-02T01:16:27.921333 #65126] INFO -- : python(65160) -- exited with code 0
77
+ I, [2014-04-02T01:16:33.226998 #65126] INFO -- : ruby(65158) -- And now writing! 0
78
+ I, [2014-04-02T01:16:33.227257 #65126] INFO -- : ruby(65158) -- And now writing! 1
79
+ I, [2014-04-02T01:16:33.227458 #65126] INFO -- : ruby(65158) -- And now writing! 2
80
+ I, [2014-04-02T01:16:33.227673 #65126] INFO -- : ruby(65158) -- And now writing! 3
81
+ I, [2014-04-02T01:16:33.248160 #65126] INFO -- : ruby(65158) -- And now writing! 4
82
+ I, [2014-04-02T01:16:33.248378 #65126] INFO -- : ruby(65158) -- And now writing! 5
83
+ I, [2014-04-02T01:16:33.248552 #65126] INFO -- : ruby(65158) -- And now writing! 6
84
+ I, [2014-04-02T01:16:33.301512 #65126] INFO -- : ruby(65158) -- And now writing! 7
85
+ I, [2014-04-02T01:16:33.301877 #65126] INFO -- : ruby(65158) -- And now writing! 8
86
+ I, [2014-04-02T01:16:33.302186 #65126] INFO -- : ruby(65158) -- And now writing! 9
87
+ I, [2014-04-02T01:16:33.363135 #65126] INFO -- : ruby(65158) -- exited with code 0
88
+ I, [2014-04-02T01:16:36.736210 #65126] INFO -- : sh(65157) -- Writing! 3
89
+ I, [2014-04-02T01:16:41.747375 #65126] INFO -- : sh(65157) -- Writing! 4
90
+ I, [2014-04-02T01:16:47.754810 #65126] INFO -- : sh(65157) -- Writing! 5
91
+ I, [2014-04-02T01:16:50.764513 #65126] INFO -- : sh(65157) -- exited with code 0
92
+ I, [2014-04-02T01:16:50.764636 #65126] INFO -- : Run has completed successfully.
93
+
45
94
  # How it works
46
95
 
47
96
  Org Converge uses an liberally extended version of Org Babel
@@ -52,9 +101,6 @@ For example, using Org Babel and macros we can easily spread config
52
101
  files on a server by writing the following on a `server.org` file.
53
102
 
54
103
  ```org
55
- #+MACRO: multitenancy_enabled true
56
- #+MACRO: status_port true
57
-
58
104
  #+begin_src yaml :tangle /etc/component.yml
59
105
  multitenant: false
60
106
  status_port: 10004
@@ -68,24 +114,11 @@ the correct permissions):
68
114
  $ org-converge server.org
69
115
  ```
70
116
 
71
- This leverages on the syntax already provided by Org Babel, but one
72
- difference here is that if we run it once again without changes...
73
-
74
- ```sh
75
- $ org-converge server.org
76
- ```
77
-
78
- ...it would finish soon since the configuration has already converged.
79
-
80
117
  Next, let's say that we no only one want to set the configured templates,
81
118
  but that we also want to install some packages. In that case, we
82
119
  should be able to do the following:
83
120
 
84
121
  ```org
85
- #+macro: multitenancy_enabled true
86
- #+macro: status_port true
87
- #+macro: project_path path/to/project
88
-
89
122
  * Configuring the component
90
123
 
91
124
  #+begin_src yaml :tangle /etc/component.yml
@@ -98,30 +131,24 @@ should be able to do the following:
98
131
  Need the following so that ~bundle install~ can compile
99
132
  the native extensions correctly.
100
133
 
101
- #+begin_src sh
134
+ #+begin_src sh :shebang #!/bin/bash
102
135
  apt-get install build-essentials -y
103
136
  #+end_src
104
137
 
105
138
  Then the following should work:
106
139
 
107
- #+begin_src sh
140
+ #+begin_src sh :shebang #!/bin/bash
108
141
  cd {{{project_path}}}
109
142
  bundle install
110
143
  #+end_src
111
144
  ```
112
145
 
113
146
  As long as the repo has been already checked out in the directory,
114
- the previous example will succeed.
115
-
116
- ```sh
117
- org-converge server.org
118
- ```
119
-
120
- If that is not the case, then org-converge will fail
121
- and pickup from that last step.
147
+ the previous example will succeed. Note that we are also setting
148
+ the `:shebang` on the scripts so that the script is executable.
122
149
 
123
- More practical examples can be found in the examples directory, more will be added as
124
- long as dogfooding from this goes well.
150
+ More practical examples can be found in the examples directory.
151
+ Many more will be added as long as dogfooding from this goes well.
125
152
 
126
153
  # Contributing
127
154
 
@@ -46,12 +46,15 @@ module Orgmode
46
46
  # Need to keep track of the options from a block before running it
47
47
  @scripts[@scripts_counter][:header] = {
48
48
  :shebang => line.block_header_arguments[':shebang'],
49
- :mkdirp => line.block_header_arguments[':mkdirp']
49
+ :mkdirp => line.block_header_arguments[':mkdirp'],
50
+ :name => line.properties['block_name']
50
51
  }
51
52
  @scripts[@scripts_counter][:lang] = line.block_lang
52
53
 
53
54
  # TODO: have a way to specify which are the default binaries to be used per language
54
55
  # when binary_detected?(@block_lang)
56
+ else
57
+ # pass
55
58
  end
56
59
  end
57
60
 
@@ -64,7 +67,7 @@ module Orgmode
64
67
  # into a runnable script
65
68
  @buffer << line.output_text << "\n"
66
69
  when (!@buffer.empty? and not (line.begin_block? or line.assigned_paragraph_type == :code))
67
- # Fix indentation and remove pre fix commas from Org mode before flushing
70
+ # Fix indentation and remove fix commas from Org mode before flushing
68
71
  strip_code_block!
69
72
  @scripts[@scripts_counter][:lines] << @buffer
70
73
  @buffer = ''
@@ -69,7 +69,8 @@ module OrgConverge
69
69
  with_running_engine do |engine|
70
70
  file = File.expand_path("#{@run_dir}/#{key}")
71
71
  cmd = "#{script[:lang]} #{file}"
72
- engine.register script[:lang], cmd, { :cwd => @root_dir, :logger => logger }
72
+ display_name = script[:header][:name] || script[:lang]
73
+ engine.register display_name, cmd, { :cwd => @root_dir, :logger => logger }
73
74
  end
74
75
  end
75
76
  logger.info "Run has completed successfully.".green
@@ -83,7 +84,8 @@ module OrgConverge
83
84
  babel.ob.scripts.each do |key, script|
84
85
  file = File.expand_path("#{@run_dir}/#{key}")
85
86
  cmd = "#{script[:lang]} #{file}"
86
- @engine.register script[:lang], cmd, { :cwd => @root_dir, :logger => logger }
87
+ display_name = script[:header][:name] || script[:lang]
88
+ @engine.register display_name, cmd, { :cwd => @root_dir, :logger => logger }
87
89
  end
88
90
  logger.info "Running code blocks now! (#{babel.ob.scripts.count} runnable blocks found in total)"
89
91
  @engine.start
@@ -4,6 +4,7 @@
4
4
  #
5
5
  require 'foreman/engine'
6
6
  require 'foreman/process'
7
+ require 'tco'
7
8
 
8
9
  module OrgConverge
9
10
  class Engine < Foreman::Engine
@@ -11,6 +12,8 @@ module OrgConverge
11
12
  attr_reader :logger
12
13
  attr_reader :babel
13
14
 
15
+ RAINBOW = ["#622e90", "#2d3091", "#00aaea", "#02a552", "#fdea22", "#eb443b", "#f37f5a"]
16
+
14
17
  def initialize(options={})
15
18
  super(options)
16
19
  @logger = options[:logger] || Logger.new(STDOUT)
@@ -35,7 +38,7 @@ module OrgConverge
35
38
  reader, writer = create_pipe
36
39
  begin
37
40
  pid = process.run(:output => writer)
38
- @names[process] = "#{@names[process]}(#{pid})"
41
+ @names[process] = "#{@names[process]}.#{pid}"
39
42
  writer.puts "started with pid #{pid}"
40
43
  rescue Errno::ENOENT
41
44
  writer.puts "unknown command: #{process.command}"
@@ -55,10 +58,9 @@ module OrgConverge
55
58
 
56
59
  def output(name, data)
57
60
  data.to_s.lines.map(&:chomp).each do |message|
58
-
59
61
  # FIXME: In case the process has finished before its lines where flushed
60
- ps = name.empty? ? '<defunct>' : name.split('.').first
61
- output = "#{pad_process_name(ps)}".yellow
62
+ ps, pid = name.empty? ? '<defunct>' : name.split('.')
63
+ output = "#{pad_process_name(ps)}(#{pid})".fg get_color_for_pid(pid.to_i)
62
64
  output += " -- "
63
65
  output += message
64
66
  # FIXME: When the process has stopped already,
@@ -80,6 +82,10 @@ module OrgConverge
80
82
  def pad_process_name(name)
81
83
  name.ljust(name_padding, " ")
82
84
  end
85
+
86
+ def get_color_for_pid(pid)
87
+ RAINBOW[pid % 7]
88
+ end
83
89
  end
84
90
 
85
91
  class CodeBlockProcess < Foreman::Process; end
@@ -1,3 +1,3 @@
1
1
  module OrgConverge
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/org-converge.gemspec CHANGED
@@ -17,4 +17,5 @@ Gem::Specification.new do |gem|
17
17
  gem.add_runtime_dependency('docopt', '0.5.0')
18
18
  gem.add_runtime_dependency('org-ruby', '~> 0.9.2')
19
19
  gem.add_runtime_dependency('foreman', '~> 0.63.0')
20
+ gem.add_runtime_dependency('tco', '~> 0.1.0')
20
21
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: org-converge
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-04-01 00:00:00.000000000 Z
12
+ date: 2014-04-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: docopt
16
- requirement: &70113563924580 !ruby/object:Gem::Requirement
16
+ requirement: &70205749443760 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - =
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.5.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70113563924580
24
+ version_requirements: *70205749443760
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: org-ruby
27
- requirement: &70113563923840 !ruby/object:Gem::Requirement
27
+ requirement: &70205749424220 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 0.9.2
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70113563923840
35
+ version_requirements: *70205749424220
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: foreman
38
- requirement: &70113563921200 !ruby/object:Gem::Requirement
38
+ requirement: &70205749407080 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,7 +43,18 @@ dependencies:
43
43
  version: 0.63.0
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70113563921200
46
+ version_requirements: *70205749407080
47
+ - !ruby/object:Gem::Dependency
48
+ name: tco
49
+ requirement: &70205749404660 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 0.1.0
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *70205749404660
47
58
  description: A light configuration management tool for Org mode
48
59
  email:
49
60
  - waldemar.quevedo@gmail.com