kameleon-builder 2.2.5 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (151) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/CHANGELOG.rst +21 -0
  4. data/{templates → contrib}/steps/bootstrap/debian/debootstrap_arm.yaml +1 -1
  5. data/{templates → contrib}/steps/export/clean_appliance.yaml +0 -0
  6. data/{templates → contrib}/steps/export/compact_qcow_img.yaml +0 -0
  7. data/{templates → contrib}/steps/setup/archlinux/configure_ruby.yaml +0 -0
  8. data/{templates → contrib}/steps/setup/archlinux/install_dev_tools.yaml +0 -0
  9. data/{templates → contrib}/steps/setup/archlinux/install_gnome.yaml +0 -0
  10. data/{templates → contrib}/steps/setup/archlinux/install_yaourt.yaml +0 -0
  11. data/{templates → contrib}/steps/setup/centos/6.5/configure_repo.yaml +0 -0
  12. data/{templates → contrib}/steps/setup/debian/install_gnome.yaml +0 -0
  13. data/{templates → contrib}/steps/setup/debian/install_kde.yaml +0 -0
  14. data/{templates → erb}/extend.erb +2 -2
  15. data/erb/userconf.erb +5 -0
  16. data/kameleon-builder.gemspec +6 -1
  17. data/lib/kameleon.rb +53 -3
  18. data/lib/kameleon/cli.rb +146 -99
  19. data/lib/kameleon/engine.rb +20 -8
  20. data/lib/kameleon/environment.rb +11 -10
  21. data/lib/kameleon/persistent_cache.rb +1 -9
  22. data/lib/kameleon/recipe.rb +52 -24
  23. data/lib/kameleon/repository.rb +46 -0
  24. data/lib/kameleon/utils.rb +49 -0
  25. data/{templates → tests/recipes}/steps/aliases/defaults.yaml +0 -0
  26. data/tests/recipes/steps/bootstrap/linux/bootstrap.yaml +2 -0
  27. data/tests/recipes/steps/checkpoints/test.yaml +14 -0
  28. data/tests/recipes/steps/enable_something.yaml +2 -0
  29. data/tests/recipes/steps/export/save_appliance.yaml +10 -0
  30. data/tests/recipes/steps/setup/linux/software_install.yaml +7 -0
  31. data/tests/recipes/test_recipe.yaml +41 -0
  32. data/version.txt +1 -1
  33. metadata +34 -139
  34. data/templates/COPYRIGHT +0 -21
  35. data/templates/chroot/debian7-amd64.yaml +0 -119
  36. data/templates/docker/debian7.yaml +0 -107
  37. data/templates/grid5000/debian7.yaml +0 -97
  38. data/templates/qemu/archlinux-desktop-i686.yaml +0 -25
  39. data/templates/qemu/archlinux-desktop-x86_64.yaml +0 -25
  40. data/templates/qemu/archlinux-i686.yaml +0 -25
  41. data/templates/qemu/archlinux-x86_64.yaml +0 -109
  42. data/templates/qemu/centos6.5-x86_64.yaml +0 -122
  43. data/templates/qemu/centos7-x86_64.yaml +0 -122
  44. data/templates/qemu/debian7-amd64.yaml +0 -134
  45. data/templates/qemu/debian7-desktop-amd64.yaml +0 -24
  46. data/templates/qemu/debian7-kameleon-amd64.yaml +0 -40
  47. data/templates/qemu/debian7-oar-amd64.yaml +0 -51
  48. data/templates/qemu/debian8-amd64.yaml +0 -25
  49. data/templates/qemu/fedora20-desktop-x86_64.yaml +0 -21
  50. data/templates/qemu/fedora20-x86_64.yaml +0 -119
  51. data/templates/qemu/ubuntu-12.04-amd64.yaml +0 -132
  52. data/templates/qemu/ubuntu-12.04-desktop-amd64.yaml +0 -25
  53. data/templates/qemu/ubuntu-14.04-amd64.yaml +0 -25
  54. data/templates/qemu/ubuntu-14.04-desktop-amd64.yaml +0 -27
  55. data/templates/steps/bootstrap/archlinux/arch_bootstrap.yaml +0 -211
  56. data/templates/steps/bootstrap/centos/6.5/yum_bootstrap.yaml +0 -67
  57. data/templates/steps/bootstrap/debian/debootstrap.yaml +0 -20
  58. data/templates/steps/bootstrap/fedora/init_pxeboot.yaml +0 -13
  59. data/templates/steps/bootstrap/fedora/yum_bootstrap.yaml +0 -45
  60. data/templates/steps/bootstrap/g5k_reserv.yaml +0 -70
  61. data/templates/steps/bootstrap/initialize_disk.yaml +0 -16
  62. data/templates/steps/bootstrap/initialize_disk_chroot.yaml +0 -80
  63. data/templates/steps/bootstrap/install_requirements.yaml +0 -3
  64. data/templates/steps/bootstrap/prepare_chroot.yaml +0 -126
  65. data/templates/steps/bootstrap/prepare_docker.yaml +0 -51
  66. data/templates/steps/bootstrap/prepare_qemu.yaml +0 -41
  67. data/templates/steps/bootstrap/prepare_virtualbox.yaml +0 -67
  68. data/templates/steps/bootstrap/start_chroot.yaml +0 -51
  69. data/templates/steps/bootstrap/start_docker.yaml +0 -16
  70. data/templates/steps/bootstrap/start_qemu.yaml +0 -74
  71. data/templates/steps/bootstrap/start_virtualbox.yaml +0 -38
  72. data/templates/steps/bootstrap/switch_context_qemu.yaml +0 -84
  73. data/templates/steps/bootstrap/switch_context_virtualbox.yaml +0 -86
  74. data/templates/steps/breakpoint.yaml +0 -3
  75. data/templates/steps/checkpoints/docker.yaml +0 -17
  76. data/templates/steps/checkpoints/qcow2.yaml +0 -40
  77. data/templates/steps/checkpoints/qemu.yaml +0 -33
  78. data/templates/steps/checkpoints/virtualbox.yaml +0 -21
  79. data/templates/steps/disable_checkpoint.yaml +0 -3
  80. data/templates/steps/enable_checkpoint.yaml +0 -5
  81. data/templates/steps/export/qemu_save_appliance.yaml +0 -52
  82. data/templates/steps/export/save_appliance_from_g5k.yaml +0 -47
  83. data/templates/steps/export/vagrant_save_appliance.yaml +0 -14
  84. data/templates/steps/export/virtualbox_save_appliance.yaml +0 -61
  85. data/templates/steps/setup/archlinux/configure_keyboard.yaml +0 -9
  86. data/templates/steps/setup/archlinux/configure_network.yaml +0 -9
  87. data/templates/steps/setup/archlinux/configure_system.yaml +0 -20
  88. data/templates/steps/setup/archlinux/install_bootloader.yaml +0 -23
  89. data/templates/steps/setup/archlinux/install_software.yaml +0 -9
  90. data/templates/steps/setup/autologin.yaml +0 -16
  91. data/templates/steps/setup/centos/6.5/configure_network.yaml +0 -33
  92. data/templates/steps/setup/centos/6.5/configure_system.yaml +0 -46
  93. data/templates/steps/setup/centos/6.5/minimal_install.yaml +0 -3
  94. data/templates/steps/setup/centos/6.5/setup_vagrant_box.yaml +0 -77
  95. data/templates/steps/setup/create_group.yaml +0 -12
  96. data/templates/steps/setup/create_user.yaml +0 -11
  97. data/templates/steps/setup/debian/configure_apt.yaml +0 -73
  98. data/templates/steps/setup/debian/configure_kernel.yaml +0 -13
  99. data/templates/steps/setup/debian/configure_keyboard.yaml +0 -10
  100. data/templates/steps/setup/debian/configure_network.yaml +0 -30
  101. data/templates/steps/setup/debian/configure_system.yaml +0 -12
  102. data/templates/steps/setup/debian/install_bootloader.yaml +0 -36
  103. data/templates/steps/setup/debian/install_software.yaml +0 -2
  104. data/templates/steps/setup/debian/oar/oar_debian_config_frontend.yaml +0 -8
  105. data/templates/steps/setup/debian/oar/oar_debian_config_node.yaml +0 -5
  106. data/templates/steps/setup/debian/oar/oar_debian_config_server.yaml +0 -5
  107. data/templates/steps/setup/debian/oar/oar_prereq_install.yaml +0 -16
  108. data/templates/steps/setup/debian/setup_vagrant_box.yaml +0 -80
  109. data/templates/steps/setup/debian/upgrade_system.yaml +0 -10
  110. data/templates/steps/setup/fedora/configure_kernel.yaml +0 -9
  111. data/templates/steps/setup/fedora/configure_keyboard.yaml +0 -12
  112. data/templates/steps/setup/fedora/configure_network.yaml +0 -38
  113. data/templates/steps/setup/fedora/configure_system.yaml +0 -52
  114. data/templates/steps/setup/fedora/install_bootloader.yaml +0 -53
  115. data/templates/steps/setup/fedora/install_software.yaml +0 -3
  116. data/templates/steps/setup/fedora/minimal_install.yaml +0 -3
  117. data/templates/steps/setup/fedora/update_system.yaml +0 -16
  118. data/templates/steps/setup/oar/oar_config_devel.yaml +0 -21
  119. data/templates/steps/setup/oar/oar_config_frontend.yaml +0 -38
  120. data/templates/steps/setup/oar/oar_config_node.yaml +0 -4
  121. data/templates/steps/setup/oar/oar_config_server.yaml +0 -25
  122. data/templates/steps/setup/oar/oar_config_system.yaml +0 -34
  123. data/templates/steps/setup/oar/oar_devel_prereq_install.yaml +0 -5
  124. data/templates/steps/setup/oar/oar_git_install.yaml +0 -21
  125. data/templates/steps/setup/ubuntu/configure_apt.yaml +0 -62
  126. data/templates/virtualbox/archlinux-desktop-i686.yaml +0 -25
  127. data/templates/virtualbox/archlinux-desktop-x86_64.yaml +0 -28
  128. data/templates/virtualbox/archlinux-i686.yaml +0 -28
  129. data/templates/virtualbox/archlinux-x86_64.yaml +0 -108
  130. data/templates/virtualbox/centos6.5-i386.yaml +0 -39
  131. data/templates/virtualbox/centos6.5-vagrant-x86_64.yaml +0 -33
  132. data/templates/virtualbox/centos6.5-x86_64.yaml +0 -121
  133. data/templates/virtualbox/centos7-x86_64.yaml +0 -118
  134. data/templates/virtualbox/debian7-amd64.yaml +0 -128
  135. data/templates/virtualbox/debian7-desktop-amd64.yaml +0 -25
  136. data/templates/virtualbox/debian7-i386.yaml +0 -31
  137. data/templates/virtualbox/debian7-kameleon-amd64.yaml +0 -38
  138. data/templates/virtualbox/debian7-oar-amd64.yaml +0 -51
  139. data/templates/virtualbox/debian7-vagrant-amd64.yaml +0 -32
  140. data/templates/virtualbox/debian8-amd64.yaml +0 -25
  141. data/templates/virtualbox/debian8-i386.yaml +0 -31
  142. data/templates/virtualbox/fedora20-x86_64.yaml +0 -118
  143. data/templates/virtualbox/ubuntu-12.04-amd64.yaml +0 -128
  144. data/templates/virtualbox/ubuntu-12.04-desktop-amd64.yaml +0 -25
  145. data/templates/virtualbox/ubuntu-14.04-amd64.yaml +0 -25
  146. data/templates/virtualbox/ubuntu-14.04-desktop-amd64.yaml +0 -27
  147. data/tests/recipes/dummy_recipe.yaml +0 -48
  148. data/tests/recipes/steps/bootstrap/dummy_distro/dummy_bootstrap_static.yaml +0 -4
  149. data/tests/recipes/steps/export/dummy_save_appliance.yaml +0 -9
  150. data/tests/recipes/steps/setup/default/dummy_root_passwd.yaml +0 -8
  151. data/tests/recipes/steps/setup/dummy_distro/dummy_software_install.yaml +0 -7
@@ -13,9 +13,9 @@ module Kameleon
13
13
  @recipe = recipe
14
14
  @cleaned_sections = []
15
15
  @cwd = @recipe.global["kameleon_cwd"]
16
- @build_recipe_path = File.join(@cwd, "kameleon_build_recipe.yaml")
16
+ @build_recipe_path = File.join(@cwd, ".build_recipe")
17
17
 
18
- @recipe.global["persistent_cache"] = @options[:cache] ? "true" : "false"
18
+ @recipe.global["persistent_cache"] = @options[:enable_cache] ? "true" : "false"
19
19
 
20
20
  build_recipe = load_build_recipe
21
21
  # restore previous build uuid
@@ -24,7 +24,7 @@ module Kameleon
24
24
  @recipe.global[key] = build_recipe["global"][key]
25
25
  end
26
26
  end
27
- @enable_checkpoint = @options[:checkpoint]
27
+ @enable_checkpoint = @options[:enable_checkpoint]
28
28
  # Check if the recipe have checkpoint entry
29
29
  if @enable_checkpoint && @recipe.checkpoint.nil?
30
30
  fail BuildError, "Checkpoint is unavailable for this recipe"
@@ -32,12 +32,12 @@ module Kameleon
32
32
 
33
33
  @recipe.resolve!
34
34
 
35
- if @options[:cache] || @options[:from_cache] then
35
+ if @options[:enable_cache] || @options[:from_cache] then
36
36
  @cache = Kameleon::Persistent_cache.instance
37
37
  @cache.cwd = @cwd
38
38
  @cache.polipo_path = @options[:proxy_path]
39
39
  @cache.name = @recipe.name
40
- @cache.mode = @options[:cache] ? :build : :from
40
+ @cache.mode = @options[:enable_cache] ? :build : :from
41
41
  @cache.cache_path = @options[:from_cache]
42
42
  @cache.recipe_files = @recipe.files + @recipe.base_recipes_files# I'm passing the Pathname objects
43
43
  @cache.recipe_path = @recipe.path
@@ -93,6 +93,12 @@ module Kameleon
93
93
  :fail_silently => fail_silently)
94
94
  end
95
95
 
96
+ def reload_contexts
97
+ [@local_context, @out_context, @in_context].each do |ctx|
98
+ ctx.reload if ctx.shell.started?
99
+ end
100
+ end
101
+
96
102
  def saving_steps_files
97
103
  @recipe.files.each do |file|
98
104
  Kameleon.ui.info("File #{file} loaded from the recipe")
@@ -182,13 +188,18 @@ module Kameleon
182
188
  end
183
189
  end
184
190
  else
191
+ begin
185
192
  Kameleon.ui.info("--> Running the step...")
186
193
  microstep.commands.each do |cmd|
187
194
  safe_exec_cmd(cmd)
188
195
  end
196
+ rescue SystemExit, Interrupt
197
+ reload_contexts
198
+ breakpoint(nil)
199
+ end
189
200
  end
190
- end
191
201
  Kameleon.ui.info("Step #{macrostep.name} took: #{Time.now.to_i-macrostep_time} secs")
202
+ end
192
203
  end
193
204
  @cleaned_sections.push(section.name)
194
205
  end
@@ -198,7 +209,8 @@ module Kameleon
198
209
  begin
199
210
  exec_cmd(cmd, kwargs)
200
211
  finished = true
201
- rescue ExecError
212
+ rescue SystemExit, Interrupt, ExecError
213
+ reload_contexts
202
214
  finished = rescue_exec_error(cmd)
203
215
  end until finished
204
216
  end
@@ -350,7 +362,7 @@ module Kameleon
350
362
  end
351
363
  end
352
364
  end
353
- @cache.stop_web_proxy if @options[:cache] ## stopping polipo
365
+ @cache.stop_web_proxy if @options[:enable_cache] ## stopping polipo
354
366
  end
355
367
 
356
368
  def build
@@ -4,36 +4,37 @@ module Kameleon
4
4
  # this environment
5
5
  class Environment
6
6
 
7
- attr_accessor :workspace
8
- attr_accessor :templates_path
9
- attr_accessor :build_path
10
- attr_accessor :cache_path
11
- attr_accessor :debug
12
-
13
7
  def script?
14
8
  @script
15
9
  end
16
10
 
17
11
  def initialize(options = {})
18
12
  # symbolify commandline options
19
- options = options.inject({}) {|result,(key,value)| result.update({key.to_sym => value})}
13
+ options = options.inject({}) {|result,(key, value)| result.update({key.to_sym => value})}
20
14
  workspace = File.expand_path(Dir.pwd)
21
- templates_path = File.expand_path(options[:templates_path] || Kameleon.default_templates_path)
15
+ # templates_path = File.expand_path(options[:templates_path] || Kameleon.default_templates_path)
22
16
  build_path = File.expand_path(options[:build_path] || File.join(workspace, "build"))
23
17
  cache_path = File.expand_path(options[:cache_path] || File.join(build_path, "cache"))
24
- options = {
18
+ repositories_path = File.expand_path(Kameleon.default_values[:repositories_path])
19
+ env_options = {
25
20
  :workspace => Pathname.new(workspace),
26
- :templates_path => Pathname.new(templates_path),
21
+ # :templates_path => Pathname.new(templates_path),
27
22
  :build_path => Pathname.new(build_path),
28
23
  :cache_path => Pathname.new(cache_path),
24
+ :repositories_path => Pathname.new(repositories_path),
29
25
  }
26
+ options = Kameleon.default_values.merge(options).merge(env_options)
30
27
  Kameleon.ui.debug("Environment initialized (#{self})")
31
28
  # Injecting all variables of the options and assign the variables
32
29
  options.each do |key, value|
30
+ self.class.__send__(:attr_accessor, "#{key}")
33
31
  instance_variable_set("@#{key}".to_sym, options[key])
34
32
  Kameleon.ui.debug(" @#{key} : #{options[key]}")
35
33
  end
36
34
  @debug = true if ENV['KAMELEON_DEBUG']
35
+
36
+ Dir.mkdir(@repositories_path.to_path) unless File.exists?(@repositories_path.to_path)
37
+
37
38
  end
38
39
  end
39
40
  end
@@ -75,7 +75,7 @@ module Kameleon
75
75
 
76
76
  def check_polipo_binary
77
77
 
78
- @polipo_path ||= which("polipo")
78
+ @polipo_path ||= Utils.which("polipo")
79
79
 
80
80
  if @polipo_path.nil? then
81
81
  Kameleon.ui.error("Polipo binary not found, make sure it is in your current PATH")
@@ -236,14 +236,6 @@ module Kameleon
236
236
  process.wait
237
237
  end
238
238
 
239
- def which(cmd)
240
- ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
241
- exe = File.join(path, "#{cmd}")
242
- return path if File.executable? exe
243
- end
244
- return nil
245
- end
246
-
247
239
  def common_prefix(paths)
248
240
  return '' if paths.empty?
249
241
  return paths.first.split('/').slice(0...-1).join('/') if paths.length <= 1
@@ -38,6 +38,7 @@ module Kameleon
38
38
  @files = []
39
39
  Kameleon.ui.debug("Initialize new recipe (#{path})")
40
40
  @base_recipes_files = [@path]
41
+ @steps_dirs = []
41
42
  load! :strict => false
42
43
  end
43
44
 
@@ -48,12 +49,22 @@ module Kameleon
48
49
  unless File.file? @path
49
50
  yaml_recipe = YAML.load_file @path
50
51
  unless yaml_recipe.kind_of? Hash
51
- fail RecipeError, "Invalid yaml error"
52
+ fail RecipeError, "Invalid yaml error : #{@path}"
52
53
  end
53
54
  # Load entended recipe variables
54
55
  yaml_recipe = load_base_recipe(yaml_recipe, @path)
55
56
  yaml_recipe.delete("extend")
56
57
 
58
+ # Where we can find steps
59
+ @steps_dirs = @base_recipes_files.map do |recipe_path|
60
+ dirname = File.dirname(recipe_path)
61
+ [ File.expand_path(File.join(dirname, 'steps')),
62
+ File.expand_path(File.join(dirname, '.steps')),
63
+ File.expand_path(File.join(dirname, '..', 'steps')),
64
+ File.expand_path(File.join(dirname, '..', '.steps')),
65
+ ]
66
+ end.flatten(1)
67
+
57
68
  # Load Global variables
58
69
  @global.merge!(yaml_recipe.fetch("global", {}))
59
70
  # Resolve dynamically-defined variables !!
@@ -64,23 +75,17 @@ module Kameleon
64
75
  # Loads checkpoint configuration
65
76
  load_checkpoint_config(yaml_recipe)
66
77
 
67
- #Find and load steps
68
- steps_dirs = [
69
- File.join(File.dirname(@path), 'steps'),
70
- File.expand_path(File.join(File.dirname(@path), '..', 'steps')),
71
- ]
72
78
  resolved_global['include_steps'] ||= []
73
79
  resolved_global['include_steps'].push ''
74
80
  resolved_global['include_steps'].flatten!
75
81
  resolved_global['include_steps'].compact!
76
82
  @sections.values.each do |section|
77
83
  dir_to_search = resolved_global['include_steps'].map do |path|
78
- steps_dirs.map do |steps_dir|
84
+ @steps_dirs.map do |steps_dir|
79
85
  [File.join(steps_dir, section.name, path),
80
86
  File.join(steps_dir, path)]
81
87
  end
82
- end
83
- dir_to_search.flatten!
88
+ end.flatten
84
89
  if yaml_recipe.key? section.name
85
90
  yaml_section = yaml_recipe.fetch(section.name)
86
91
  next unless yaml_section.kind_of? Array
@@ -157,7 +162,7 @@ module Kameleon
157
162
  unless File.file? path
158
163
  base_yaml_recipe = YAML.load_file base_recipe_path
159
164
  unless yaml_recipe.kind_of? Hash
160
- fail RecipeError, "Invalid yaml error"
165
+ fail RecipeError, "Invalid yaml error : #{base_yaml_recipe}"
161
166
  end
162
167
  base_yaml_recipe.keys.each do |key|
163
168
  if ["export", "bootstrap", "setup"].include? key
@@ -186,7 +191,7 @@ module Kameleon
186
191
  base_yaml_recipe[key] = base_section.merge(recipe_section)
187
192
  end
188
193
  end
189
- @base_recipes_files.push(Pathname.new(base_recipe_path))
194
+ @base_recipes_files.push(Pathname.new(File.expand_path(base_recipe_path)))
190
195
  return load_base_recipe(base_yaml_recipe, base_recipe_path)
191
196
  end
192
197
 
@@ -196,11 +201,9 @@ module Kameleon
196
201
  if aliases.kind_of? Hash
197
202
  @aliases = aliases
198
203
  elsif aliases.kind_of? String
199
- dir_search = [
200
- File.join(File.dirname(@path), "steps", "aliases"),
201
- File.join(File.dirname(@path), "..", "steps", "aliases"),
202
- File.join(File.dirname(@path), "aliases")
203
- ]
204
+ dir_search = @steps_dirs.map do |steps_dir|
205
+ File.join(steps_dir, "aliases")
206
+ end.flatten
204
207
  dir_search.each do |dir_path|
205
208
  path = Pathname.new(File.join(dir_path, aliases))
206
209
  if File.file?(path)
@@ -210,7 +213,7 @@ module Kameleon
210
213
  return path
211
214
  end
212
215
  end
213
- fail RecipeError, "Aliases file '#{path}' does not exists"
216
+ fail RecipeError, "Aliases file for recipe '#{path}' does not exists"
214
217
  end
215
218
  end
216
219
  end
@@ -222,11 +225,9 @@ module Kameleon
222
225
  @checkpoint = checkpoint
223
226
  @checkpoint["path"] = @path
224
227
  elsif checkpoint.kind_of? String
225
- dir_search = [
226
- File.join(File.dirname(@path), "steps", "checkpoints"),
227
- File.join(File.dirname(@path), "..", "steps", "checkpoints"),
228
- File.join(File.dirname(@path), "checkpoints")
229
- ]
228
+ dir_search = @steps_dirs.map do |steps_dir|
229
+ File.join(steps_dir, "checkpoints")
230
+ end.flatten
230
231
  dir_search.each do |dir_path|
231
232
  path = Pathname.new(File.join(dir_path, checkpoint))
232
233
  if File.file?(path)
@@ -234,6 +235,7 @@ module Kameleon
234
235
  @checkpoint = YAML.load_file(path)
235
236
  @checkpoint["path"] = path.to_s
236
237
  @files.push(path)
238
+ break
237
239
  end
238
240
  end
239
241
  fail RecipeError, "Checkpoint configuraiton file '#{path}' " \
@@ -250,6 +252,7 @@ module Kameleon
250
252
  def load_macrostep(step_path, name, args)
251
253
  if step_path.nil?
252
254
  macrostep_yaml = args
255
+ step_path = @path
253
256
  else
254
257
  macrostep_yaml = YAML.load_file(step_path)
255
258
  # Basic macrostep syntax check
@@ -547,6 +550,28 @@ module Kameleon
547
550
  return recipe_hash
548
551
  end
549
552
 
553
+ def display_info
554
+ def prefix
555
+ Kameleon.ui.shell.say " -> ", :blue
556
+ end
557
+ Kameleon.ui.info("Description:")
558
+ prefix ; Kameleon.ui.info("#{@metainfo['description']}")
559
+ Kameleon.ui.info("Path:")
560
+ prefix ; Kameleon.ui.info("#{@path}")
561
+ Kameleon.ui.info("Parent recipes:")
562
+ (@base_recipes_files - [@path]).each do |base_recipe_file|
563
+ prefix ; Kameleon.ui.info("#{base_recipe_file}")
564
+ end
565
+ Kameleon.ui.info("Steps:")
566
+ @files.each do |step|
567
+ prefix ; Kameleon.ui.info("#{step}")
568
+ end
569
+ Kameleon.ui.info("Variables:")
570
+ @global.each do |key, value|
571
+ prefix ; Kameleon.ui.info("#{key}: #{value}")
572
+ end
573
+ end
574
+
550
575
  def to_array
551
576
  array = []
552
577
  @sections.values.each do |section|
@@ -558,8 +583,11 @@ module Kameleon
558
583
  end
559
584
 
560
585
  class RecipeTemplate < Recipe
561
- def relative_path()
562
- @path.relative_path_from(Kameleon.env.templates_path)
586
+ def relative_path_from_recipe(recipe_path)
587
+ recipe_path = Pathname.new(recipe_path)
588
+ relative_path_tpl_repo = @path.relative_path_from(Kameleon.env.repositories_path)
589
+ absolute_path = Pathname.new(Kameleon.env.workspace).join(relative_path_tpl_repo)
590
+ return absolute_path.relative_path_from(recipe_path.dirname)
563
591
  end
564
592
  end
565
593
  end
@@ -0,0 +1,46 @@
1
+ require 'kameleon/utils'
2
+ require 'kameleon/step'
3
+
4
+ module Kameleon
5
+
6
+ class Repository
7
+ def self.check_git_binary
8
+ git_path ||= Utils.which("git")
9
+ if git_path.nil? then
10
+ raise KameleonError, "git binary not found, make sure it is in your current PATH"
11
+ end
12
+ end
13
+
14
+ def self.add(name, url, kwargs = {})
15
+ check_git_binary
16
+ cmd = ["git", "clone"]
17
+ if kwargs[:branch]
18
+ cmd.push("-b", kwargs[:branch])
19
+ end
20
+ cmd.push("--", url, File.join(Kameleon.env.repositories_path, name))
21
+ process = ChildProcess.build(*cmd)
22
+ process.io.inherit!
23
+ process.start
24
+ process.wait
25
+ process.stop
26
+ end
27
+
28
+ def self.update(name)
29
+ check_git_binary
30
+ git_repo = File.join(Kameleon.env.repositories_path, name)
31
+ cmd = ["git", "--git-dir", File.join(git_repo, ".git"), "--work-tree",
32
+ git_repo, "pull", "--verbose"]
33
+ process = ChildProcess.build(*cmd)
34
+ process.io.inherit!
35
+ process.start
36
+ process.wait
37
+ process.stop
38
+ end
39
+
40
+ def self.list
41
+ Dir["#{Kameleon.env.repositories_path}/*"].each do |repo_path|
42
+ Kameleon.ui.info File.basename("#{repo_path}")
43
+ end
44
+ end
45
+ end
46
+ end
@@ -52,5 +52,54 @@ module Kameleon
52
52
  end
53
53
  end
54
54
 
55
+ def self.list_recipes(repository_path, kwargs = {})
56
+ catch_exception = kwargs.fetch(:catch_exception, true)
57
+ recipes_hash = []
58
+ recipes_files = get_recipes(repository_path)
59
+ recipes_files.each do |f|
60
+ path = f.to_path
61
+ begin
62
+ recipe = RecipeTemplate.new(path)
63
+ name = path.gsub(repository_path.to_path + '/', '').chomp('.yaml')
64
+ recipes_hash.push({
65
+ "name" => name,
66
+ "description" => recipe.metainfo['description'],
67
+ })
68
+ rescue => e
69
+ raise e if Kameleon.env.debug or not catch_exception
70
+ end
71
+ end
72
+ unless recipes_hash.empty?
73
+ recipes_hash = recipes_hash.sort_by{ |k| k["name"] }
74
+ name_width = recipes_hash.map { |k| k['name'].size }.max
75
+ desc_width = Kameleon.ui.shell.terminal_width - name_width - 3
76
+ desc_width = (80 - name_width - 3) if desc_width < 0
77
+ end
78
+ tp(recipes_hash,
79
+ {"name" => {:width => name_width}},
80
+ { "description" => {:width => desc_width}})
81
+ end
82
+
83
+ def self.get_recipes(path)
84
+ path.children.collect do |child|
85
+ if child.file?
86
+ if child.extname == ".yaml"
87
+ unless child.to_path.include? "/steps/" or child.to_path.include? "/.steps/"
88
+ child
89
+ end
90
+ end
91
+ elsif child.directory?
92
+ get_recipes(child)
93
+ end
94
+ end.select { |x| x }.flatten(1)
95
+ end
96
+
97
+ def self.which(cmd)
98
+ ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
99
+ exe = File.join(path, "#{cmd}")
100
+ return path if File.executable? exe
101
+ end
102
+ return nil
103
+ end
55
104
  end
56
105
  end
@@ -0,0 +1,2 @@
1
+ - bootstrap:
2
+ - exec_out: echo $include_pkg
@@ -0,0 +1,14 @@
1
+ enabled?:
2
+ - exec_local: touch $KAMELEON_WORKDIR/list_checkpoint.txt
3
+
4
+ create:
5
+ - exec_local: echo @microstep_id | tee -a $KAMELEON_WORKDIR/list_checkpoint.txt
6
+
7
+ apply:
8
+ - exec_local: echo @microstep_id
9
+
10
+ list:
11
+ - exec_local: cat $KAMELEON_WORKDIR/list_checkpoint.txt
12
+
13
+ clear:
14
+ - exec_local: rm -f $KAMELEON_WORKDIR/list_checkpoint.txt