grifork 0.4.0 → 0.5.0

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: 051978666d0eb719ebe0d1fb7396767f2849b60b
4
- data.tar.gz: d1db36aff5d670f124ab13dadfa8288347ed1998
3
+ metadata.gz: 140949f8595ff1cc52066e358268d58378b4274e
4
+ data.tar.gz: ffd353ed0b6ce568d9f8f598b55c6b92e1ebfce6
5
5
  SHA512:
6
- metadata.gz: 728ccefbb4558dc6caccd3a8a1504a52ad19fd8627d993046a82003545d0ee812cd66285088b96a858013eac16db4b25257207eadf1d6a94d7fd49b735be692d
7
- data.tar.gz: b61507b73b372ba673b1d4eb9a78c85efce6c49d7a4b1534723392ceca9e80b9274c67b926490c044849f91a6753f03dda902b6b1914440a44ce7ae518f1bd57
6
+ metadata.gz: 85dfb2017ae8dc051c23ca48fd8c179c3ec0c98b7c111fa8a49a1c7300ea87e87494e0d7a7950f0a51067c5a959c61ea9ca6ca1a987ef2db88ca7cf277392e11
7
+ data.tar.gz: 5c5cfe37f565437fba03aaddb48071319cd04c58c591e4b76499160facc167ef287081ad667a4403f92e81e085acc6b5f5a4ea75cbf30979740ef8dc745719f8
@@ -1,3 +1,12 @@
1
+ ## 0.5.0 (2016/10/10)
2
+
3
+ Features: (#4)
4
+
5
+ - New DSL methods:
6
+ - `#prepare`, `#finish`: Initialize or teardown the whole build procedure
7
+ - `#prepare_remote`, `#finish_remote`: Initialize or teardown the procedure on
8
+ remote hosts in `:grifork` mode
9
+
1
10
  ## 0.4.0 (2016/10/9)
2
11
 
3
12
  Bug Fix: (#3)
@@ -32,6 +32,12 @@ hosts ['web1.internal', 'web2.internal', '192.168.10.1', '192.168.10.2']
32
32
  # Available full Hash options are bellow:
33
33
  rsync delete: true, bwlimit: 4096, verbose: false, excludes: [], rsh: nil, dry_run: false
34
34
 
35
+ # Prepare before running tasks on localhost
36
+ prepare do
37
+ sh :echo, ['Prepare grifork mode.']
38
+ sh :mkdir, %w(-p path/to/tmp)
39
+ end
40
+
35
41
  # Define task run on localhost
36
42
  local do
37
43
  sh :echo, %W(LOCAL: #{src} => #{dst})
@@ -39,6 +45,12 @@ local do
39
45
  rsync '/path/to/src/', '/path/to/dest/'
40
46
  end
41
47
 
48
+ # Prepare in the beginning of grifork tasks on remote
49
+ prepare_remote do
50
+ sh :echo, ['Prepare grifork on remote.']
51
+ sh %(cd path/to/app && bundle install)
52
+ end
53
+
42
54
  # Define task run on remote hosts
43
55
  # NOTE: This task is run as "local" task on remote
44
56
  # different from "remote" task in :standalone mode
@@ -48,3 +60,15 @@ remote do
48
60
  rsync '/path/to/src/', '/path/to/dest/'
49
61
  end
50
62
 
63
+ # Closing tasks on remote
64
+ finish_remote do
65
+ sh :echo, ['Finish grifork on remote.']
66
+ sh %(cd path/to/app && bundle clean)
67
+ end
68
+
69
+ # Closing tasks finally on localhost
70
+ finish do
71
+ sh :echo, ['Finish grifork mode.']
72
+ sh :rm, %w(-rf path/to/tmp)
73
+ end
74
+
@@ -23,6 +23,12 @@ ssh user: 'someone', keys: ['path/to/identity_file'], passphrase: 'xxx'
23
23
  # Available full Hash options are bellow:
24
24
  rsync delete: true, bwlimit: 4096, verbose: false, excludes: [], rsh: nil, dry_run: false
25
25
 
26
+ # Prepare before running tasks
27
+ prepare do
28
+ sh :echo, ['Prepare standalone mode.']
29
+ sh :mkdir, %w(-p path/to/tmp)
30
+ end
31
+
26
32
  # Define task run on localhost
27
33
  local do
28
34
  sh :echo, %W(LOCAL: #{src} => #{dst})
@@ -37,3 +43,9 @@ remote do
37
43
  rsync_remote '/path/to/src/', '/path/to/dest/'
38
44
  end
39
45
 
46
+ # Closing tasks
47
+ finish do
48
+ sh :echo, ['Finish standalone mode.']
49
+ sh :rm, %w(-rf path/to/tmp)
50
+ end
51
+
@@ -17,7 +17,8 @@ class Grifork
17
17
  require_relative 'grifork/executor'
18
18
  require_relative 'grifork/mixin/executable'
19
19
  require_relative 'grifork/executor/grifork'
20
- require_relative 'grifork/executor/task'
20
+ require_relative 'grifork/executor/carrier'
21
+ require_relative 'grifork/executor/local'
21
22
  require_relative 'grifork/dsl'
22
23
  require_relative 'grifork/cli'
23
24
  require_relative 'grifork/version'
@@ -1,6 +1,10 @@
1
1
  class Grifork::Config
2
- attr_reader :branches, :hosts, :log, :local_task, :remote_task, :grifork
3
- attr_accessor :griforkfile, :dry_run
2
+ attrs = {
3
+ ro: %i(branches hosts log grifork local_task remote_task prepare_task finish_task),
4
+ rw: %i(griforkfile dry_run),
5
+ }
6
+ attr_reader *attrs[:ro]
7
+ attr_accessor *attrs[:rw]
4
8
 
5
9
  def initialize(args)
6
10
  args.each do |key, val|
@@ -114,24 +114,59 @@ class Grifork::DSL
114
114
  end
115
115
 
116
116
  # Define tasks to execute at localhost
117
- # @param &task [Proc] Codes to be executed by an object of {Grifork::Executor::Task}
117
+ # @param &task [Proc] Codes to be executed by an object of {Grifork::Executor::Carrier}
118
+ # @note In +:grifork+ mode, this is executed only at localhost
118
119
  def local(&task)
119
120
  return if @on_remote
120
- config_set(:local_task, Grifork::Executor::Task.new(:local, &task))
121
+ config_set(:local_task, Grifork::Executor::Carrier.new(:local, &task))
121
122
  end
122
123
 
123
124
  # Define tasks to execute at remote host
124
- # @param &task [Proc] Codes to be executed by an object of {Grifork::Executor::Task}
125
+ # @param &task [Proc] Codes to be executed by an object of {Grifork::Executor::Carrier}
125
126
  # @note In +:standalone+ mode, the task is executed at localhost actually.
126
127
  # In +:grifork+ mode, it is executed at remote hosts via +grifork+ command on remote hosts
127
128
  def remote(&task)
128
129
  if @on_remote
129
- config_set(:local_task, Grifork::Executor::Task.new(:local, &task))
130
+ config_set(:local_task, Grifork::Executor::Carrier.new(:local, &task))
130
131
  else
131
- config_set(:remote_task, Grifork::Executor::Task.new(:remote, &task))
132
+ config_set(:remote_task, Grifork::Executor::Carrier.new(:remote, &task))
132
133
  end
133
134
  end
134
135
 
136
+ # Define tasks to execute at localhost before starting procedure
137
+ # @param &task [Proc] Codes to be executed by an object of {Grifork::Executor::Local}
138
+ # @note In +:grifork+ mode, this is executed only at localhost
139
+ def prepare(&task)
140
+ return if @on_remote
141
+ config_set(:prepare_task, Grifork::Executor::Local.new(:prepare, &task))
142
+ end
143
+
144
+ # Define tasks to execute at localhost in the end of procedure
145
+ # @param &task [Proc] Codes to be executed by an object of {Grifork::Executor::Local}
146
+ # @note In +:grifork+ mode, this is executed only at localhost
147
+ def finish(&task)
148
+ return if @on_remote
149
+ config_set(:finish_task, Grifork::Executor::Local.new(:finish, &task))
150
+ end
151
+
152
+ # Define tasks to execute at remote host which execute +grifork+ tasks in +:grifork+
153
+ # mode before starting its procedure
154
+ # @param &task [Proc] Codes to be executed by an object of {Grifork::Executor::Local}
155
+ # @note In +:standalone+ mode, this is never executed
156
+ def prepare_remote(&task)
157
+ return unless @on_remote
158
+ config_set(:prepare_task, Grifork::Executor::Local.new(:prepare, &task))
159
+ end
160
+
161
+ # Define tasks to execute at remote host which execute +grifork+ tasks in +:grifork+
162
+ # mode in the end of its procedure
163
+ # @param &task [Proc] Codes to be executed by an object of {Grifork::Executor::Local}
164
+ # @note In +:standalone+ mode, this is never executed
165
+ def finish_remote(&task)
166
+ return unless @on_remote
167
+ config_set(:finish_task, Grifork::Executor::Local.new(:finish, &task))
168
+ end
169
+
135
170
  private
136
171
 
137
172
  def config_set(key, value)
@@ -1,4 +1,4 @@
1
- class Grifork::Executor::Task
1
+ class Grifork::Executor::Carrier
2
2
  include Grifork::Executable
3
3
 
4
4
  # Initialize with task
@@ -0,0 +1,15 @@
1
+ class Grifork::Executor::Local
2
+ include Grifork::Executable
3
+
4
+ # Initialize with task
5
+ # @param &task [Proc] task to execute
6
+ def initialize(type, &task)
7
+ @type = type
8
+ @task = task
9
+ end
10
+
11
+ # Run the task
12
+ def run
13
+ instance_eval(&@task)
14
+ end
15
+ end
@@ -29,6 +29,8 @@ class Grifork::Graph
29
29
 
30
30
  # Launch local and remote tasks through whole graph
31
31
  def launch_tasks
32
+ config.prepare_task.run if config.prepare_task
33
+
32
34
  # level = 1
33
35
  Parallel.map(root.children, config.parallel => root.children.size) do |node|
34
36
  logger.info("Run locally. localhost => #{node.host}")
@@ -36,10 +38,14 @@ class Grifork::Graph
36
38
  end
37
39
  # level in (2..depth)
38
40
  fork_remote_tasks(root.children)
41
+
42
+ config.finish_task.run if config.finish_task
39
43
  end
40
44
 
41
45
  # Run grifork command on child nodes recursively
42
46
  def grifork
47
+ config.prepare_task.run if config.prepare_task
48
+
43
49
  if root.children.size.zero?
44
50
  logger.debug("#{root} Reached leaf. Nothing to do.")
45
51
  return
@@ -53,6 +59,8 @@ class Grifork::Graph
53
59
  end
54
60
  Grifork::Executor::Grifork.new.run(child)
55
61
  end
62
+
63
+ config.finish_task.run if config.finish_task
56
64
  end
57
65
 
58
66
  # Print graph structure for debug usage
@@ -1,3 +1,3 @@
1
1
  class Grifork
2
- VERSION = '0.4.0'
2
+ VERSION = '0.5.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grifork
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - key-amb
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-08 00:00:00.000000000 Z
11
+ date: 2016-10-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-ssh
@@ -134,8 +134,9 @@ files:
134
134
  - lib/grifork/config.rb
135
135
  - lib/grifork/dsl.rb
136
136
  - lib/grifork/executor.rb
137
+ - lib/grifork/executor/carrier.rb
137
138
  - lib/grifork/executor/grifork.rb
138
- - lib/grifork/executor/task.rb
139
+ - lib/grifork/executor/local.rb
139
140
  - lib/grifork/graph.rb
140
141
  - lib/grifork/graph/node.rb
141
142
  - lib/grifork/logger.rb