rundock 0.5.2 → 0.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3d00dfb1b4e328b253c9a566e2ba01043018c993
4
- data.tar.gz: d76ebd204fa24b34db93c347f092cba6016dda66
3
+ metadata.gz: bcfd3d43abf83f98725cee3d7491bad4df9ee51f
4
+ data.tar.gz: 1d82c40d5cb2b880630eed568193ab042511be2a
5
5
  SHA512:
6
- metadata.gz: e4942411fc3dfb1419da7cbddf5434f627c1f6a94d925f6c643ce1305585a7fc98b168a2aec70340f2d738676123d3bc8b923ef8c85e6f4ceeafca5b57cfc8c7
7
- data.tar.gz: 07f54fb15feb55d8de8aef4e3241d6341d841cc2ae520283d2cc58ba0600f0457226cac957817ce98baf23b90b5c87af7025965ad38bdb36873c2e60a41dafff
6
+ metadata.gz: e29c7362f2454b6436fd199c156062e36740995ca57b25254de52e9fb34d711d4bd2dbce0a1ead397fdc5d7a31a52be02216d0b1f842a93249b90f2676ace9a2
7
+ data.tar.gz: 9db5cb49b8e533bfc59cfa3add439471abf1018cd426f369d372d0dfae987dbce4d89d601d7d72445e3272d1c2d1730781febf9a96bbfd669a47db118c7f7c92
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## v0.5.3
2
+
3
+ Update
4
+
5
+ - Support taskfile
6
+ - Support targetfile
7
+
1
8
  ## v0.5.2
2
9
 
3
10
  Update
data/Rakefile CHANGED
@@ -73,14 +73,17 @@ def do_rundock_scenarios(platform)
73
73
  default_ssh_opt = ''
74
74
  end
75
75
 
76
- if scenario =~ %r{^*scenarios/(.*_hooks_by_option)_scenario.yml$}
77
- hooks_opt = " -k ./spec/integration/hooks/#{Regexp.last_match(1)}.yml"
78
- else
79
- hooks_opt = ''
76
+ options = ''
77
+ if scenario =~ %r{^*scenarios/(.*hooks_by_option)_scenario.yml$}
78
+ options = " -k ./spec/integration/hooks/#{Regexp.last_match(1)}.yml"
79
+ elsif scenario =~ %r{^*scenarios/(.*task_by_option)_scenario.yml$}
80
+ options = " -t ./spec/integration/tasks/#{Regexp.last_match(1)}.yml"
81
+ elsif scenario =~ %r{^*scenarios/(.*target_by_option)_scenario.yml$}
82
+ options = " -g #{base_dir}/targets/#{Regexp.last_match(1)}.yml"
80
83
  end
81
84
 
82
85
  execute('bundle exec exe/rundock' \
83
- " do #{scenario}#{default_ssh_opt}#{hooks_opt} -l debug", true)
86
+ " do #{scenario}#{default_ssh_opt}#{options} -l debug", true)
84
87
  end
85
88
  end
86
89
 
@@ -4,7 +4,7 @@ module Rundock
4
4
  module Builder
5
5
  class HookBuilder < Base
6
6
  DEFAULT_HOOKS_FILE_PATH = './hooks.yml'
7
- HookStructureError = Class.new(NotImplementedError)
7
+ HookStructureError = Class.new(StandardError)
8
8
 
9
9
  attr_accessor :enable_hooks
10
10
 
@@ -21,9 +21,12 @@ module Rundock
21
21
  if FileTest.exist?(@options[:hooks])
22
22
  hooks_file = @options[:hooks]
23
23
  Logger.info("hooks file is #{hooks_file}")
24
- else
24
+ elsif FileTest.exist?(DEFAULT_HOOKS_FILE_PATH)
25
25
  Logger.warn("hooks file is not found. use #{DEFAULT_HOOKS_FILE_PATH}")
26
26
  hooks_file = DEFAULT_HOOKS_FILE_PATH
27
+ else
28
+ Logger.warn("Hook path is not available. (#{@options[:hooks]})")
29
+ return []
27
30
  end
28
31
  elsif hook_attributes.nil?
29
32
  Logger.warn("Hook source is not found. (enables:#{enables.join(',')})") unless enables.empty?
@@ -2,10 +2,6 @@ module Rundock
2
2
  module Builder
3
3
  class OperationBuilder < Base
4
4
  def build_first(scenario, targets, tasks, hooks)
5
- if @options[:targetgroup] && !@options[:command]
6
- raise CommandArgNotFoundError, %("--command or -c" option is required if targetgroup specified.)
7
- end
8
-
9
5
  parsing_node_attribute = nil
10
6
  scen = Scenario.new
11
7
  scen.tasks = tasks
@@ -52,8 +52,8 @@ module Rundock
52
52
  ope = OperationBuilder.new(@options)
53
53
  ope.build_first(
54
54
  scenario_data[:main],
55
- scenario_data[:target_info],
56
- scenario_data[:tasks],
55
+ @options[:command] ? scenario_data[:target_info] : TargetGroupBuilder.new(@options).build(scenario_data[:target_info]),
56
+ TaskBuilder.new(@options).build(scenario_data[:tasks]),
57
57
  scenario_data[:hooks])
58
58
  end
59
59
  end
@@ -0,0 +1,29 @@
1
+ require 'yaml'
2
+
3
+ module Rundock
4
+ module Builder
5
+ class TargetGroupBuilder < Base
6
+ DEFAULT_TARGET_GROUP_FILE_PATH = './targetgroup.yml'
7
+
8
+ def build(scenario_targets)
9
+ targets = {} unless scenario_targets
10
+
11
+ if @options[:targetgroup]
12
+ if FileTest.exist?(@options[:targetgroup])
13
+ targets.merge!(YAML.load_file(@options[:targetgroup]).deep_symbolize_keys)
14
+ Logger.info("merged target file #{@options[:targetgroup]}")
15
+ elsif FileTest.exist?(DEFAULT_TARGET_GROUP_FILE_PATH)
16
+ Logger.warn("targetgroup file is not found. use #{DEFAULT_TARGET_GROUP_FILE_PATH}")
17
+ targets.merge!(YAML.load_file(DEFAULT_TARGET_GROUP_FILE_PATH).deep_symbolize_keys)
18
+ else
19
+ Logger.warn("Targetgroup path is not available. (#{@options[:targetgroup]})")
20
+ end
21
+ else
22
+ return scenario_targets
23
+ end
24
+
25
+ targets
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,29 @@
1
+ require 'yaml'
2
+
3
+ module Rundock
4
+ module Builder
5
+ class TaskBuilder < Base
6
+ DEFAULT_TASKS_FILE_PATH = './tasks.yml'
7
+
8
+ def build(scenario_tasks)
9
+ tasks = {} unless scenario_tasks
10
+
11
+ if @options[:tasks]
12
+ if FileTest.exist?(@options[:tasks])
13
+ tasks.merge!(YAML.load_file(@options[:tasks]).deep_symbolize_keys)
14
+ Logger.info("merged tasks file #{@options[:tasks]}")
15
+ elsif FileTest.exist?(DEFAULT_TASKS_FILE_PATH)
16
+ Logger.warn("tasks file is not found. use #{DEFAULT_TASKS_FILE_PATH}")
17
+ tasks.merge!(YAML.load_file(DEFAULT_TASKS_FILE_PATH).deep_symbolize_keys)
18
+ else
19
+ Logger.warn("Task path is not available. (#{@options[:tasks]})")
20
+ end
21
+ else
22
+ return scenario_tasks
23
+ end
24
+
25
+ tasks
26
+ end
27
+ end
28
+ end
29
+ end
data/lib/rundock/cli.rb CHANGED
@@ -31,6 +31,8 @@ module Rundock
31
31
  desc 'do [SCENARIO] [options]', 'Run rundock from scenario file'
32
32
  option :sudo, type: :boolean, default: false
33
33
  option :default_ssh_opts, type: :string, aliases: ['-d'], default: DEFAULT_SSH_OPTIONS_DEFAULT_FILE_PATH
34
+ option :targetgroup, type: :string, aliases: ['-g']
35
+ option :tasks, type: :string, aliases: ['-t']
34
36
  option :hooks, type: :string, aliases: ['-k']
35
37
  option :run_anyway, type: :boolean, default: false
36
38
  option :dry_run, type: :boolean, aliases: ['-n']
@@ -44,6 +46,7 @@ module Rundock
44
46
  desc 'ssh [options]', 'Run rundock ssh with various options'
45
47
  option :command, type: :string, aliases: ['-c']
46
48
  option :default_ssh_opts, type: :string, aliases: ['-d'], default: DEFAULT_SSH_OPTIONS_DEFAULT_FILE_PATH
49
+ option :tasks, type: :string, aliases: ['-t']
47
50
  option :hooks, type: :string, aliases: ['-k']
48
51
  option :host, type: :string, aliases: ['-h'], banner: 'You can specify comma separated hosts.[ex: host1,host2,..]'
49
52
  option :targetgroup, type: :string, aliases: ['-g']
@@ -31,11 +31,11 @@ module Rundock
31
31
  if options[:scenario] || options[:targetgroup]
32
32
  if options[:scenario] && !FileTest.exist?(options[:scenario])
33
33
  raise ScenarioNotFoundError, "'#{options[:scenario]}' scenario file is not found."
34
- elsif options[:targetgroup] && !FileTest.exist?(options[:targetgroup])
34
+ elsif options[:command] && options[:targetgroup] && !FileTest.exist?(options[:targetgroup])
35
35
  raise ScenarioNotFoundError, "'#{options[:targetgroup]}' targetgroup file is not found."
36
36
  end
37
37
 
38
- options[:scenario] = options[:targetgroup] if options[:targetgroup]
38
+ options[:scenario] = options[:targetgroup] if options[:command] && options[:targetgroup]
39
39
 
40
40
  # parse scenario
41
41
  if options[:scenario] =~ %r{^(http|https)://}
@@ -1,3 +1,3 @@
1
1
  module Rundock
2
- VERSION = '0.5.2'
2
+ VERSION = '0.5.3'
3
3
  end
data/lib/rundock.rb CHANGED
@@ -15,6 +15,8 @@ require 'rundock/scenario'
15
15
  require 'rundock/backend'
16
16
  require 'rundock/builder/base'
17
17
  require 'rundock/builder/default_ssh_builder'
18
+ require 'rundock/builder/target_group_builder'
19
+ require 'rundock/builder/task_builder'
18
20
  require 'rundock/builder/target_builder'
19
21
  require 'rundock/builder/backend_builder'
20
22
  require 'rundock/builder/hook_builder'
@@ -17,15 +17,18 @@ DOCKER_SSH_KEY_PUBLIC_REMOTE="${PLATFORM_DIR}/authorized_keys"
17
17
  DOCKER_SSH_CONFIG="${HOME}/.ssh/config_${PROJECT_NAME}_${PLATFORM_NAME}"
18
18
  RUNDOCK_SCENARIO_DIR="${PROJECT_ROOT}/scenarios"
19
19
  RUNDOCK_GROUP_DIR="${PROJECT_ROOT}/groups"
20
+ RUNDOCK_TARGET_DIR="${PROJECT_ROOT}/targets"
20
21
  RUNDOCK_CACHE_DIR="${HOME}/.rundock/${PLATFORM_NAME}"
21
22
  RUNDOCK_DEFAULT_SSH_YML="${RUNDOCK_CACHE_DIR}/integration_default_ssh.yml"
22
23
  RUNDOCK_SCENARIO_CACHE_DIR="${RUNDOCK_CACHE_DIR}/scenarios"
23
24
  RUNDOCK_GROUP_CACHE_DIR="${RUNDOCK_CACHE_DIR}/groups"
25
+ RUNDOCK_TARGET_CACHE_DIR="${RUNDOCK_CACHE_DIR}/targets"
24
26
 
25
27
  if [ "${1}x" = "--cleanx" ];then
26
28
  rm -f ${RUNDOCK_DEFAULT_SSH_YML}
27
29
  rm -f ${RUNDOCK_SCENARIO_CACHE_DIR}/*.yml
28
30
  rm -f ${RUNDOCK_GROUP_CACHE_DIR}/*.yml
31
+ rm -f ${RUNDOCK_TARGET_CACHE_DIR}/*.yml
29
32
  if sudo docker ps | grep "${DOCKER_IMAGE_NAME}" > /dev/null; then
30
33
  rm -f ${DOCKER_CACHE_IMAGE_PATH}
31
34
  rm -f ${DOCKER_SSH_KEY_PRIVATE}
@@ -41,6 +44,7 @@ fi
41
44
 
42
45
  mkdir -p "${RUNDOCK_SCENARIO_CACHE_DIR}"
43
46
  mkdir -p "${RUNDOCK_GROUP_CACHE_DIR}"
47
+ mkdir -p "${RUNDOCK_TARGET_CACHE_DIR}"
44
48
 
45
49
  if [ ! -f ${RUNDOCK_DEFAULT_SSH_YML} ]; then
46
50
  (
@@ -55,11 +59,14 @@ fi
55
59
 
56
60
  cp ${RUNDOCK_SCENARIO_DIR}/* ${RUNDOCK_SCENARIO_CACHE_DIR}
57
61
  cp ${RUNDOCK_GROUP_DIR}/* ${RUNDOCK_GROUP_CACHE_DIR}
62
+ cp ${RUNDOCK_TARGET_DIR}/* ${RUNDOCK_TARGET_CACHE_DIR}
58
63
 
59
64
  find ${RUNDOCK_SCENARIO_CACHE_DIR} -type f -name "*_scenario.yml" | \
60
65
  xargs sed -i -e "s#<replaced_by_platforms>#${DOCKER_SSH_KEY_PRIVATE}#g"
61
66
  find ${RUNDOCK_GROUP_CACHE_DIR} -type f -name "*_group.yml" | \
62
67
  xargs sed -i -e "s#<replaced_by_platforms>#${DOCKER_SSH_KEY_PRIVATE}#g"
68
+ find ${RUNDOCK_TARGET_CACHE_DIR} -type f -name "*.yml" | \
69
+ xargs sed -i -e "s#<replaced_by_platforms>#${DOCKER_SSH_KEY_PRIVATE}#g"
63
70
 
64
71
  sudo docker ps | grep "${DOCKER_IMAGE_NAME}" && { echo "docker image is already standing."; exit 0; }
65
72
 
@@ -0,0 +1,10 @@
1
+ - target: anyhost-01
2
+ command:
3
+ - "rm -f /var/tmp/hello_rundock_from_target_by_option_scenario"
4
+ task:
5
+ - write_echo
6
+ ---
7
+ ---
8
+ write_echo:
9
+ command:
10
+ - "echo 'Hello Rundock from target by option Scenario.' > /var/tmp/hello_rundock_from_target_by_option_scenario"
@@ -0,0 +1,5 @@
1
+ - target: localhost
2
+ command:
3
+ - "rm -f /var/tmp/hello_rundock_from_task_by_option_scenario"
4
+ task:
5
+ - write_echo
@@ -0,0 +1,2 @@
1
+ anyhost-01:
2
+ host: localhost
@@ -0,0 +1,6 @@
1
+ require 'spec_helper'
2
+
3
+ describe file('/var/tmp/hello_rundock_from_target_by_option_scenario') do
4
+ it { should be_file }
5
+ its(:content) { should match(/Hello Rundock from target by option Scenario./) }
6
+ end
@@ -0,0 +1,6 @@
1
+ require 'spec_helper'
2
+
3
+ describe file('/var/tmp/hello_rundock_from_task_by_option_scenario') do
4
+ it { should be_file }
5
+ its(:content) { should match(/Hello Rundock from task by option Scenario./) }
6
+ end
@@ -0,0 +1,13 @@
1
+ - target: localhost
2
+ command:
3
+ - "rm -f /var/tmp/hello_rundock_from_target_by_option_scenario"
4
+ - target: anyhost-01
5
+ command:
6
+ - "uname -a"
7
+ task:
8
+ - write_echo
9
+ ---
10
+ ---
11
+ write_echo:
12
+ command:
13
+ - "echo 'Hello Rundock from target by option Scenario.' > /var/tmp/hello_rundock_from_target_by_option_scenario"
@@ -0,0 +1,16 @@
1
+ - target: localhost
2
+ command:
3
+ - "rm -f /var/tmp/hello_rundock_from_task_by_option_scenario"
4
+ - target: anyhost-01
5
+ command:
6
+ - "uname -a"
7
+ task:
8
+ - write_echo
9
+ ---
10
+ anyhost-01:
11
+ target_type: host
12
+ host: 172.17.42.1
13
+ ssh_opts:
14
+ port: 22222
15
+ user: tester
16
+ key: "<replaced_by_platforms>"
@@ -0,0 +1,8 @@
1
+ anyhost-01:
2
+ target_type: host
3
+ host: 172.17.42.1
4
+ ssh_opts:
5
+ port: 22222
6
+ user: tester
7
+ key: "<replaced_by_platforms>"
8
+
@@ -0,0 +1,3 @@
1
+ write_echo:
2
+ command:
3
+ - "echo 'Hello Rundock from task by option Scenario.' > /var/tmp/hello_rundock_from_task_by_option_scenario"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rundock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - hiracy
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-09-16 00:00:00.000000000 Z
11
+ date: 2015-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -162,6 +162,8 @@ files:
162
162
  - lib/rundock/builder/operation_builder.rb
163
163
  - lib/rundock/builder/scenario_builder.rb
164
164
  - lib/rundock/builder/target_builder.rb
165
+ - lib/rundock/builder/target_group_builder.rb
166
+ - lib/rundock/builder/task_builder.rb
165
167
  - lib/rundock/cli.rb
166
168
  - lib/rundock/ext/hash.rb
167
169
  - lib/rundock/ext/object/blank.rb
@@ -195,8 +197,11 @@ files:
195
197
  - spec/integration/platforms/localhost/scenarios/run_anyway_scenario.yml
196
198
  - spec/integration/platforms/localhost/scenarios/simple_echo_scenario.yml
197
199
  - spec/integration/platforms/localhost/scenarios/simple_plugin_scenario.yml
200
+ - spec/integration/platforms/localhost/scenarios/target_by_option_scenario.yml
198
201
  - spec/integration/platforms/localhost/scenarios/target_group_scenario.yml
202
+ - spec/integration/platforms/localhost/scenarios/task_by_option_scenario.yml
199
203
  - spec/integration/platforms/localhost/scenarios/use_default_ssh_scenario.yml
204
+ - spec/integration/platforms/localhost/targets/target_by_option.yml
200
205
  - spec/integration/recipes/deploy_erb_spec.rb
201
206
  - spec/integration/recipes/deploy_spec.rb
202
207
  - spec/integration/recipes/file_hook_by_option_spec.rb
@@ -205,6 +210,8 @@ files:
205
210
  - spec/integration/recipes/simple_echo_spec.rb
206
211
  - spec/integration/recipes/simple_plugin_scenario_spec.rb
207
212
  - spec/integration/recipes/tareget_group_scenario_spec.rb
213
+ - spec/integration/recipes/target_by_option_spec.rb
214
+ - spec/integration/recipes/task_by_option_spec.rb
208
215
  - spec/integration/scenarios/all_file_hooks_by_option_scenario.yml
209
216
  - spec/integration/scenarios/deploy_erb_scenario.yml
210
217
  - spec/integration/scenarios/deploy_scenario.yml
@@ -212,9 +219,13 @@ files:
212
219
  - spec/integration/scenarios/file_hooks_scenario.yml
213
220
  - spec/integration/scenarios/simple_echo_scenario.yml
214
221
  - spec/integration/scenarios/simple_plugin_scenario.yml
222
+ - spec/integration/scenarios/target_by_option_scenario.yml
215
223
  - spec/integration/scenarios/target_group_scenario.yml
224
+ - spec/integration/scenarios/task_by_option_scenario.yml
216
225
  - spec/integration/scenarios/use_default_ssh_scenario.yml
217
226
  - spec/integration/spec_helper.rb
227
+ - spec/integration/targets/target_by_option.yml
228
+ - spec/integration/tasks/task_by_option.yml
218
229
  homepage: https://github.com/hiracy/rundock
219
230
  licenses:
220
231
  - MIT