itamae-mitsurin 0.4 → 0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (235) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +1 -1
  3. data/README.md +2 -1
  4. data/Rakefile +17 -15
  5. data/bin/itamae +2 -3
  6. data/bin/manaita +5 -0
  7. data/itamae-mitsurin.gemspec +4 -4
  8. data/lib/itamae-mitsurin.rb +17 -0
  9. data/lib/{itamae → itamae-mitsurin}/backend.rb +13 -13
  10. data/lib/{itamae → itamae-mitsurin}/cli.rb +5 -5
  11. data/lib/{itamae → itamae-mitsurin}/definition.rb +2 -2
  12. data/lib/itamae-mitsurin/ext.rb +1 -0
  13. data/lib/{itamae → itamae-mitsurin}/ext/specinfra.rb +0 -0
  14. data/lib/{itamae → itamae-mitsurin}/handler.rb +3 -3
  15. data/lib/{itamae → itamae-mitsurin}/handler/base.rb +1 -1
  16. data/lib/{itamae → itamae-mitsurin}/handler/debug.rb +2 -2
  17. data/lib/{itamae → itamae-mitsurin}/handler/fluentd.rb +2 -2
  18. data/lib/{itamae → itamae-mitsurin}/handler/json.rb +1 -1
  19. data/lib/{itamae → itamae-mitsurin}/handler_proxy.rb +1 -1
  20. data/lib/{itamae → itamae-mitsurin}/logger.rb +5 -5
  21. data/lib/itamae-mitsurin/mitsurin.rb +14 -0
  22. data/lib/{itamae → itamae-mitsurin}/mitsurin/cli.rb +5 -5
  23. data/lib/{itamae → itamae-mitsurin}/mitsurin/creators.rb +3 -3
  24. data/lib/itamae-mitsurin/mitsurin/creators/cookbook.rb +24 -0
  25. data/lib/itamae-mitsurin/mitsurin/creators/project.rb +24 -0
  26. data/lib/{itamae → itamae-mitsurin}/mitsurin/creators/templates/project/.rspec +0 -0
  27. data/lib/{itamae → itamae-mitsurin}/mitsurin/creators/templates/project/Gemfile +0 -1
  28. data/lib/itamae-mitsurin/mitsurin/creators/templates/project/Rakefile +2 -0
  29. data/lib/{itamae/generators/templates/cookbook/files → itamae-mitsurin/mitsurin/creators/templates/project/environments}/.keep +0 -0
  30. data/lib/{itamae → itamae-mitsurin}/mitsurin/creators/templates/project/environments/sample.json +0 -0
  31. data/lib/{itamae/generators/templates/cookbook/templates → itamae-mitsurin/mitsurin/creators/templates/project/keys}/.keep +0 -0
  32. data/lib/{itamae/generators/templates/project/cookbooks → itamae-mitsurin/mitsurin/creators/templates/project/nodes}/.keep +0 -0
  33. data/lib/itamae-mitsurin/mitsurin/creators/templates/project/nodes/sample01.json +10 -0
  34. data/lib/{itamae/generators → itamae-mitsurin/mitsurin/creators}/templates/project/roles/.keep +0 -0
  35. data/lib/{itamae/generators/templates/role/files → itamae-mitsurin/mitsurin/creators/templates/project/site-cookbooks/_base/_base/attributes}/.keep +0 -0
  36. data/lib/itamae-mitsurin/mitsurin/creators/templates/project/site-cookbooks/_base/_base/recipes/default.rb +1 -0
  37. data/lib/{itamae/generators/templates/role/templates → itamae-mitsurin/mitsurin/creators/templates/project/site-cookbooks/_base/_base/recipes/directories}/.keep +0 -0
  38. data/lib/{itamae/mitsurin/creators/templates/project/environments → itamae-mitsurin/mitsurin/creators/templates/project/site-cookbooks/_base/_base/recipes/files}/.keep +0 -0
  39. data/lib/{itamae/mitsurin/creators/templates/project/keys → itamae-mitsurin/mitsurin/creators/templates/project/site-cookbooks/_base/_base/recipes/templates}/.keep +0 -0
  40. data/lib/{itamae → itamae-mitsurin}/mitsurin/creators/templates/project/site-cookbooks/_base/_base/spec/default_spec.rb +0 -0
  41. data/lib/{itamae → itamae-mitsurin}/mitsurin/creators/templates/project/spec/spec_helper.rb +0 -0
  42. data/lib/{itamae/mitsurin/creators/templates/project/nodes → itamae-mitsurin/mitsurin/creators/templates/project/tmp-nodes}/.keep +0 -0
  43. data/lib/{itamae/mitsurin/creators/templates/project/roles → itamae-mitsurin/mitsurin/creators/templates/site-cookbooks/attributes}/.keep +0 -0
  44. data/lib/{itamae/generators/templates/cookbook → itamae-mitsurin/mitsurin/creators/templates/site-cookbooks/recipes}/default.rb +0 -0
  45. data/lib/{itamae/mitsurin/creators/templates/project/site-cookbooks/_base/_base/attributes → itamae-mitsurin/mitsurin/creators/templates/site-cookbooks/recipes/directories}/.keep +0 -0
  46. data/lib/{itamae/mitsurin/creators/templates/project/site-cookbooks/_base/_base → itamae-mitsurin/mitsurin/creators/templates/site-cookbooks/recipes}/files/.keep +0 -0
  47. data/lib/{itamae/mitsurin/creators/templates/project/site-cookbooks/_base/_base → itamae-mitsurin/mitsurin/creators/templates/site-cookbooks/recipes}/templates/.keep +0 -0
  48. data/lib/{itamae/generators/templates/role/default.rb → itamae-mitsurin/mitsurin/creators/templates/site-cookbooks/spec/default_spec.rb} +0 -0
  49. data/lib/itamae-mitsurin/mitsurin/itamae_task.rb +197 -0
  50. data/lib/itamae-mitsurin/mitsurin/itamae_with_git_task.rb +213 -0
  51. data/lib/itamae-mitsurin/mitsurin/serverspec_task.rb +123 -0
  52. data/lib/{itamae → itamae-mitsurin}/node.rb +3 -3
  53. data/lib/{itamae → itamae-mitsurin}/notification.rb +3 -3
  54. data/lib/{itamae → itamae-mitsurin}/recipe.rb +6 -6
  55. data/lib/{itamae → itamae-mitsurin}/recipe_children.rb +2 -2
  56. data/lib/{itamae → itamae-mitsurin}/resource.rb +23 -23
  57. data/lib/{itamae → itamae-mitsurin}/resource/aws_ebs_volume.rb +3 -3
  58. data/lib/{itamae → itamae-mitsurin}/resource/base.rb +23 -23
  59. data/lib/{itamae → itamae-mitsurin}/resource/directory.rb +2 -2
  60. data/lib/{itamae → itamae-mitsurin}/resource/execute.rb +2 -2
  61. data/lib/itamae-mitsurin/resource/file.rb +180 -0
  62. data/lib/{itamae → itamae-mitsurin}/resource/gem_package.rb +2 -2
  63. data/lib/{itamae → itamae-mitsurin}/resource/git.rb +2 -2
  64. data/lib/{itamae → itamae-mitsurin}/resource/group.rb +2 -2
  65. data/lib/{itamae → itamae-mitsurin}/resource/http_request.rb +3 -3
  66. data/lib/{itamae → itamae-mitsurin}/resource/link.rb +2 -2
  67. data/lib/{itamae → itamae-mitsurin}/resource/local_ruby_block.rb +2 -2
  68. data/lib/{itamae → itamae-mitsurin}/resource/package.rb +2 -2
  69. data/lib/{itamae → itamae-mitsurin}/resource/remote_directory.rb +5 -5
  70. data/lib/{itamae → itamae-mitsurin}/resource/remote_file.rb +3 -3
  71. data/lib/{itamae → itamae-mitsurin}/resource/service.rb +2 -2
  72. data/lib/{itamae → itamae-mitsurin}/resource/template.rb +2 -2
  73. data/lib/{itamae → itamae-mitsurin}/resource/user.rb +2 -2
  74. data/lib/{itamae → itamae-mitsurin}/runner.rb +8 -8
  75. data/lib/{itamae/mitsurin → itamae-mitsurin}/version.rb +1 -3
  76. data/lib/itamae-mitsurin/version.txt +1 -0
  77. data/test/test_itamae-mitsurin.rb +18 -0
  78. data/test/test_itamae-mitsurin/ext/test_specinfra.rb +39 -0
  79. data/test/test_itamae-mitsurin/handler/test_base.rb +40 -0
  80. data/test/test_itamae-mitsurin/handler/test_debug.rb +10 -0
  81. data/test/test_itamae-mitsurin/handler/test_fluentd.rb +44 -0
  82. data/test/test_itamae-mitsurin/handler/test_json.rb +22 -0
  83. data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/.rspec +2 -0
  84. data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/Gemfile +3 -0
  85. data/{lib/itamae → test/test_itamae-mitsurin}/mitsurin/creators/templates/project/Rakefile +0 -0
  86. data/{lib/itamae/mitsurin/creators/templates/project/tmp-nodes → test/test_itamae-mitsurin/mitsurin/creators/templates/project/environments}/.keep +0 -0
  87. data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/environments/sample.json +7 -0
  88. data/{lib/itamae/mitsurin/creators/templates/site-cookbooks/attributes → test/test_itamae-mitsurin/mitsurin/creators/templates/project/keys}/.keep +0 -0
  89. data/{lib/itamae/mitsurin/creators/templates/site-cookbooks/files → test/test_itamae-mitsurin/mitsurin/creators/templates/project/nodes}/.keep +0 -0
  90. data/{lib/itamae → test/test_itamae-mitsurin}/mitsurin/creators/templates/project/nodes/sample01.json +0 -0
  91. data/{lib/itamae/mitsurin/creators/templates/site-cookbooks/spec → test/test_itamae-mitsurin/mitsurin/creators/templates/project/roles}/.keep +0 -0
  92. data/{lib/itamae/mitsurin/creators/templates/site-cookbooks/templates → test/test_itamae-mitsurin/mitsurin/creators/templates/project/site-cookbooks/_base/_base/attributes}/.keep +0 -0
  93. data/{lib/itamae/mitsurin/creators/templates/site-cookbooks/recipes/default.rb → test/test_itamae-mitsurin/mitsurin/creators/templates/project/site-cookbooks/_base/_base/files/.keep} +0 -0
  94. data/{lib/itamae → test/test_itamae-mitsurin}/mitsurin/creators/templates/project/site-cookbooks/_base/_base/recipes/default.rb +0 -0
  95. data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/site-cookbooks/_base/_base/spec/default_spec.rb +1 -0
  96. data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/site-cookbooks/_base/_base/templates/.keep +0 -0
  97. data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/spec/spec_helper.rb +33 -0
  98. data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/tmp-nodes/.keep +0 -0
  99. data/test/test_itamae-mitsurin/mitsurin/creators/templates/site-cookbooks/attributes/.keep +0 -0
  100. data/test/test_itamae-mitsurin/mitsurin/creators/templates/site-cookbooks/files/.keep +0 -0
  101. data/test/test_itamae-mitsurin/mitsurin/creators/templates/site-cookbooks/recipes/default.rb +0 -0
  102. data/test/test_itamae-mitsurin/mitsurin/creators/templates/site-cookbooks/spec/.keep +0 -0
  103. data/test/test_itamae-mitsurin/mitsurin/creators/templates/site-cookbooks/templates/.keep +0 -0
  104. data/{lib/itamae/mitsurin/creators/cookbook.rb → test/test_itamae-mitsurin/mitsurin/creators/test_cookbook.rb} +0 -0
  105. data/{lib/itamae/mitsurin/creators/project.rb → test/test_itamae-mitsurin/mitsurin/creators/test_project.rb} +0 -0
  106. data/test/test_itamae-mitsurin/mitsurin/test_cli.rb +56 -0
  107. data/test/test_itamae-mitsurin/mitsurin/test_creators.rb +19 -0
  108. data/{lib/itamae/mitsurin/itamae_task.rb → test/test_itamae-mitsurin/mitsurin/test_itamae_task.rb} +0 -1
  109. data/{lib/itamae/mitsurin/itamae_with_git_task.rb → test/test_itamae-mitsurin/mitsurin/test_itamae_with_git_task.rb} +0 -1
  110. data/{lib/itamae/mitsurin/serverspec_task.rb → test/test_itamae-mitsurin/mitsurin/test_serverspec_task.rb} +1 -1
  111. data/test/test_itamae-mitsurin/resource/test_aws_ebs_volume.rb +84 -0
  112. data/test/test_itamae-mitsurin/resource/test_base.rb +374 -0
  113. data/test/test_itamae-mitsurin/resource/test_directory.rb +63 -0
  114. data/test/test_itamae-mitsurin/resource/test_execute.rb +26 -0
  115. data/{lib/itamae/resource/file.rb → test/test_itamae-mitsurin/resource/test_file.rb} +6 -6
  116. data/test/test_itamae-mitsurin/resource/test_gem_package.rb +81 -0
  117. data/test/test_itamae-mitsurin/resource/test_git.rb +94 -0
  118. data/test/test_itamae-mitsurin/resource/test_group.rb +42 -0
  119. data/test/test_itamae-mitsurin/resource/test_http_request.rb +71 -0
  120. data/test/test_itamae-mitsurin/resource/test_link.rb +33 -0
  121. data/test/test_itamae-mitsurin/resource/test_local_ruby_block.rb +15 -0
  122. data/test/test_itamae-mitsurin/resource/test_package.rb +44 -0
  123. data/test/test_itamae-mitsurin/resource/test_remote_directory.rb +84 -0
  124. data/test/test_itamae-mitsurin/resource/test_remote_file.rb +54 -0
  125. data/test/test_itamae-mitsurin/resource/test_service.rb +69 -0
  126. data/test/test_itamae-mitsurin/resource/test_template.rb +53 -0
  127. data/test/test_itamae-mitsurin/resource/test_user.rb +93 -0
  128. data/test/test_itamae-mitsurin/test_backend.rb +297 -0
  129. data/test/test_itamae-mitsurin/test_cli.rb +88 -0
  130. data/test/test_itamae-mitsurin/test_definition.rb +40 -0
  131. data/test/test_itamae-mitsurin/test_ext.rb +1 -0
  132. data/test/test_itamae-mitsurin/test_handler.rb +21 -0
  133. data/test/test_itamae-mitsurin/test_handler_proxy.rb +38 -0
  134. data/test/test_itamae-mitsurin/test_logger.rb +124 -0
  135. data/test/test_itamae-mitsurin/test_mitsurin.rb +14 -0
  136. data/test/test_itamae-mitsurin/test_node.rb +74 -0
  137. data/test/test_itamae-mitsurin/test_notification.rb +46 -0
  138. data/test/test_itamae-mitsurin/test_recipe.rb +171 -0
  139. data/test/test_itamae-mitsurin/test_recipe_children.rb +86 -0
  140. data/test/test_itamae-mitsurin/test_resource.rb +73 -0
  141. data/test/test_itamae-mitsurin/test_runner.rb +124 -0
  142. data/test/test_itamae-mitsurin/test_version.rb +3 -0
  143. data/{lib/itamae/mitsurin → test/test_itamae-mitsurin}/version.txt +0 -0
  144. data/test_project/.rspec +2 -0
  145. data/test_project/Gemfile +4 -0
  146. data/test_project/Rakefile +3 -0
  147. data/test_project/environments/.keep +0 -0
  148. data/test_project/keys/.keep +0 -0
  149. data/test_project/nodes/.keep +0 -0
  150. data/test_project/nodes/test.json +9 -0
  151. data/test_project/roles/.keep +0 -0
  152. data/test_project/roles/test.json +14 -0
  153. data/test_project/site-cookbooks/_base/_base/attributes/.keep +0 -0
  154. data/test_project/site-cookbooks/_base/_base/files/.keep +0 -0
  155. data/test_project/site-cookbooks/_base/_base/recipes/default.rb +1 -0
  156. data/test_project/site-cookbooks/_base/_base/spec/default_spec.rb +1 -0
  157. data/test_project/site-cookbooks/_base/_base/templates/.keep +0 -0
  158. data/test_project/site-cookbooks/a_test/directory/attributes/.keep +0 -0
  159. data/test_project/site-cookbooks/a_test/directory/files/.keep +0 -0
  160. data/test_project/site-cookbooks/a_test/directory/recipes/default.rb +8 -0
  161. data/test_project/site-cookbooks/a_test/directory/spec/.keep +0 -0
  162. data/test_project/site-cookbooks/a_test/directory/spec/default_spec.rb +4 -0
  163. data/test_project/site-cookbooks/a_test/directory/templates/.keep +0 -0
  164. data/test_project/site-cookbooks/a_test/package/attributes/.keep +0 -0
  165. data/test_project/site-cookbooks/a_test/package/files/.keep +0 -0
  166. data/test_project/site-cookbooks/a_test/package/recipes/default.rb +2 -0
  167. data/test_project/site-cookbooks/a_test/package/spec/.keep +0 -0
  168. data/test_project/site-cookbooks/a_test/package/spec/default_spec.rb +4 -0
  169. data/test_project/site-cookbooks/a_test/package/templates/.keep +0 -0
  170. data/test_project/site-cookbooks/a_test/service/attributes/.keep +0 -0
  171. data/test_project/site-cookbooks/a_test/service/files/.keep +0 -0
  172. data/test_project/site-cookbooks/a_test/service/recipes/default.rb +5 -0
  173. data/test_project/site-cookbooks/a_test/service/spec/.keep +0 -0
  174. data/test_project/site-cookbooks/a_test/service/spec/default_spec.rb +6 -0
  175. data/test_project/site-cookbooks/a_test/service/templates/.keep +0 -0
  176. data/test_project/site-cookbooks/b_test/git/attributes/.keep +0 -0
  177. data/test_project/site-cookbooks/b_test/git/files/.keep +0 -0
  178. data/test_project/site-cookbooks/b_test/git/recipes/default.rb +5 -0
  179. data/test_project/site-cookbooks/b_test/git/spec/.keep +0 -0
  180. data/test_project/site-cookbooks/b_test/git/spec/default_spec.rb +5 -0
  181. data/test_project/site-cookbooks/b_test/git/templates/.keep +0 -0
  182. data/test_project/site-cookbooks/b_test/link/attributes/.keep +0 -0
  183. data/test_project/site-cookbooks/b_test/link/files/.keep +0 -0
  184. data/test_project/site-cookbooks/b_test/link/recipes/default.rb +5 -0
  185. data/test_project/site-cookbooks/b_test/link/spec/.keep +0 -0
  186. data/test_project/site-cookbooks/b_test/link/spec/default_spec.rb +5 -0
  187. data/test_project/site-cookbooks/b_test/link/templates/.keep +0 -0
  188. data/test_project/site-cookbooks/b_test/remote_file/attributes/.keep +0 -0
  189. data/test_project/site-cookbooks/b_test/remote_file/files/.keep +0 -0
  190. data/test_project/site-cookbooks/b_test/remote_file/files/remote_file.sh +1 -0
  191. data/test_project/site-cookbooks/b_test/remote_file/recipes/default.rb +9 -0
  192. data/test_project/site-cookbooks/b_test/remote_file/spec/.keep +0 -0
  193. data/test_project/site-cookbooks/b_test/remote_file/spec/default_spec.rb +7 -0
  194. data/test_project/site-cookbooks/b_test/remote_file/templates/.keep +0 -0
  195. data/test_project/site-cookbooks/b_test/template/attributes/.keep +0 -0
  196. data/test_project/site-cookbooks/b_test/template/files/.keep +0 -0
  197. data/test_project/site-cookbooks/b_test/template/recipes/default.rb +5 -0
  198. data/test_project/site-cookbooks/b_test/template/spec/.keep +0 -0
  199. data/test_project/site-cookbooks/b_test/template/spec/default_spec.rb +7 -0
  200. data/test_project/site-cookbooks/b_test/template/templates/.keep +0 -0
  201. data/test_project/site-cookbooks/b_test/template/templates/template.erb +2 -0
  202. data/test_project/site-cookbooks/c_test/execute/attributes/.keep +0 -0
  203. data/test_project/site-cookbooks/c_test/execute/files/.keep +0 -0
  204. data/test_project/site-cookbooks/c_test/execute/recipes/default.rb +6 -0
  205. data/test_project/site-cookbooks/c_test/execute/spec/.keep +0 -0
  206. data/test_project/site-cookbooks/c_test/execute/spec/default_spec.rb +6 -0
  207. data/test_project/site-cookbooks/c_test/execute/templates/.keep +0 -0
  208. data/test_project/site-cookbooks/c_test/remote_directory/attributes/.keep +0 -0
  209. data/test_project/site-cookbooks/c_test/remote_directory/files/.keep +0 -0
  210. data/test_project/site-cookbooks/c_test/remote_directory/recipes/default.rb +10 -0
  211. data/test_project/site-cookbooks/c_test/remote_directory/spec/.keep +0 -0
  212. data/test_project/site-cookbooks/c_test/remote_directory/spec/default_spec.rb +20 -0
  213. data/test_project/site-cookbooks/c_test/remote_directory/templates/.keep +0 -0
  214. data/test_project/site-cookbooks/c_test/remote_directory/templates/remote_dir/a.txt +0 -0
  215. data/test_project/site-cookbooks/c_test/remote_directory/templates/remote_dir/b.txt +0 -0
  216. data/test_project/site-cookbooks/c_test/remote_directory/templates/remote_dir/c.txt +0 -0
  217. data/test_project/site-cookbooks/d_spec/air/attributes/.keep +0 -0
  218. data/test_project/site-cookbooks/d_spec/air/files/.keep +0 -0
  219. data/test_project/site-cookbooks/d_spec/air/recipes/default.rb +0 -0
  220. data/test_project/site-cookbooks/d_spec/air/spec/.keep +0 -0
  221. data/test_project/site-cookbooks/d_spec/air/spec/default_spec.rb +0 -0
  222. data/test_project/site-cookbooks/d_spec/air/templates/.keep +0 -0
  223. data/test_project/spec/spec_helper.rb +33 -0
  224. data/test_project/tmp-nodes/.keep +0 -0
  225. data/test_project/tmp-nodes/test.json +12 -0
  226. metadata +337 -138
  227. data/bin/itamae-mitsurin +0 -5
  228. data/lib/itamae.rb +0 -18
  229. data/lib/itamae/ext.rb +0 -1
  230. data/lib/itamae/generators.rb +0 -20
  231. data/lib/itamae/generators/cookbook.rb +0 -22
  232. data/lib/itamae/generators/project.rb +0 -22
  233. data/lib/itamae/generators/role.rb +0 -22
  234. data/lib/itamae/generators/templates/project/Gemfile +0 -4
  235. data/lib/itamae/mitsurin.rb +0 -14
@@ -0,0 +1,63 @@
1
+ require 'itamae-mitsurin'
2
+
3
+ module ItamaeMitsurin
4
+ module Resource
5
+ class Directory < Base
6
+ define_attribute :action, default: :create
7
+ define_attribute :path, type: String, default_name: true
8
+ define_attribute :mode, type: String
9
+ define_attribute :owner, type: String
10
+ define_attribute :group, type: String
11
+
12
+ def pre_action
13
+ case @current_action
14
+ when :create
15
+ attributes.exist = true
16
+ when :delete
17
+ attributes.exist = false
18
+ end
19
+ end
20
+
21
+ def show_differences
22
+ current.mode = current.mode.rjust(4, '0') if current.mode
23
+ attributes.mode = attributes.mode.rjust(4, '0') if attributes.mode
24
+
25
+ super
26
+ end
27
+
28
+ def set_current_attributes
29
+ exist = run_specinfra(:check_file_is_directory, attributes.path)
30
+ current.exist = exist
31
+
32
+ if exist
33
+ current.mode = run_specinfra(:get_file_mode, attributes.path).stdout.chomp
34
+ current.owner = run_specinfra(:get_file_owner_user, attributes.path).stdout.chomp
35
+ current.group = run_specinfra(:get_file_owner_group, attributes.path).stdout.chomp
36
+ else
37
+ current.mode = nil
38
+ current.owner = nil
39
+ current.group = nil
40
+ end
41
+ end
42
+
43
+ def action_create(options)
44
+ if !run_specinfra(:check_file_is_directory, attributes.path)
45
+ run_specinfra(:create_file_as_directory, attributes.path)
46
+ end
47
+ if attributes.mode
48
+ run_specinfra(:change_file_mode, attributes.path, attributes.mode)
49
+ end
50
+ if attributes.owner || attributes.group
51
+ run_specinfra(:change_file_owner, attributes.path, attributes.owner, attributes.group)
52
+ end
53
+ end
54
+
55
+ def action_delete(options)
56
+ if run_specinfra(:check_file_is_directory, attributes.path)
57
+ run_specinfra(:remove_file, attributes.path)
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+
@@ -0,0 +1,26 @@
1
+ require 'itamae-mitsurin'
2
+
3
+ module ItamaeMitsurin
4
+ module Resource
5
+ class Execute < Base
6
+ define_attribute :action, default: :run
7
+ define_attribute :command, type: String, default_name: true
8
+
9
+ def pre_action
10
+ case @current_action
11
+ when :run
12
+ attributes.executed = true
13
+ end
14
+ end
15
+
16
+ def set_current_attributes
17
+ current.executed = false
18
+ end
19
+
20
+ def action_run(options)
21
+ run_command(attributes.command)
22
+ updated!
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,6 +1,6 @@
1
- require 'itamae'
1
+ require 'itamae-mitsurin'
2
2
 
3
- module Itamae
3
+ module ItamaeMitsurin
4
4
  module Resource
5
5
  class File < Base
6
6
  define_attribute :action, default: :create
@@ -125,9 +125,9 @@ module Itamae
125
125
  diff = run_command(["diff", "-u", compare_to, @temppath], error: false)
126
126
  if diff.exit_status == 0
127
127
  # no change
128
- Itamae.logger.debug "file content will not change"
128
+ ItamaeMitsurin.logger.debug "file content will not change"
129
129
  else
130
- Itamae.logger.info "diff:"
130
+ ItamaeMitsurin.logger.info "diff:"
131
131
  diff.stdout.each_line do |line|
132
132
  color = if line.start_with?('+')
133
133
  :green
@@ -136,8 +136,8 @@ module Itamae
136
136
  else
137
137
  :clear
138
138
  end
139
- Itamae.logger.color(color) do
140
- Itamae.logger.info line.chomp
139
+ ItamaeMitsurin.logger.color(color) do
140
+ ItamaeMitsurin.logger.info line.chomp
141
141
  end
142
142
  end
143
143
  runner.handler.event(:file_content_changed, diff: diff.stdout)
@@ -0,0 +1,81 @@
1
+ require 'itamae-mitsurin'
2
+
3
+ module ItamaeMitsurin
4
+ module Resource
5
+ class GemPackage < Base
6
+ define_attribute :action, default: :install
7
+ define_attribute :package_name, type: String, default_name: true
8
+ define_attribute :gem_binary, type: [String, Array], default: 'gem'
9
+ define_attribute :options, type: [String, Array], default: []
10
+ define_attribute :version, type: String
11
+ define_attribute :source, type: String
12
+
13
+ def pre_action
14
+ case @current_action
15
+ when :install
16
+ attributes.installed = true
17
+ end
18
+ end
19
+
20
+ def set_current_attributes
21
+ installed = installed_gems.find {|g| g[:name] == attributes.package_name }
22
+ current.installed = !!installed
23
+
24
+ if current.installed
25
+ versions = installed[:versions]
26
+ if versions.include?(attributes.version)
27
+ current.version = attributes.version
28
+ else
29
+ current.version = versions.first
30
+ end
31
+ end
32
+ end
33
+
34
+ def action_install(action_options)
35
+ if current.installed
36
+ if attributes.version && current.version != attributes.version
37
+ install!
38
+ updated!
39
+ end
40
+ else
41
+ install!
42
+ updated!
43
+ end
44
+ end
45
+
46
+ def action_upgrade(action_options)
47
+ return if current.installed && attributes.version && current.version == attributes.version
48
+
49
+ install!
50
+ updated!
51
+ end
52
+
53
+ def installed_gems
54
+ gems = []
55
+ run_command([*Array(attributes.gem_binary), 'list', '-l']).stdout.each_line do |line|
56
+ if /\A([^ ]+) \(([^\)]+)\)\z/ =~ line.strip
57
+ name = $1
58
+ versions = $2.split(', ')
59
+ gems << {name: name, versions: versions}
60
+ end
61
+ end
62
+ gems
63
+ rescue Backend::CommandExecutionError
64
+ []
65
+ end
66
+
67
+ def install!
68
+ cmd = [*Array(attributes.gem_binary), 'install', *Array(attributes.options)]
69
+ if attributes.version
70
+ cmd << '-v' << attributes.version
71
+ end
72
+ if attributes.source
73
+ cmd << '--source' << attributes.source
74
+ end
75
+ cmd << attributes.package_name
76
+
77
+ run_command(cmd)
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,94 @@
1
+ require 'itamae-mitsurin'
2
+
3
+ module ItamaeMitsurin
4
+ module Resource
5
+ class Git < Base
6
+ DEPLOY_BRANCH = "deploy"
7
+
8
+ define_attribute :action, default: :sync
9
+ define_attribute :destination, type: String, default_name: true
10
+ define_attribute :repository, type: String, required: true
11
+ define_attribute :revision, type: String
12
+ define_attribute :recursive, type: [TrueClass, FalseClass], default: false
13
+
14
+ def pre_action
15
+ case @current_action
16
+ when :sync
17
+ attributes.exist = true
18
+ end
19
+ end
20
+
21
+ def set_current_attributes
22
+ current.exist = run_specinfra(:check_file_is_directory, attributes.destination)
23
+ end
24
+
25
+ def action_sync(options)
26
+ ensure_git_available
27
+
28
+ new_repository = false
29
+
30
+ if check_empty_dir
31
+ cmd = ['git', 'clone']
32
+ cmd << '--recursive' if attributes.recursive
33
+ cmd << attributes.repository << attributes.destination
34
+ run_command(cmd)
35
+ new_repository = true
36
+ end
37
+
38
+ target = if attributes.revision
39
+ get_revision(attributes.revision)
40
+ else
41
+ fetch_origin!
42
+ run_command_in_repo("git ls-remote origin HEAD | cut -f1").stdout.strip
43
+ end
44
+
45
+ if new_repository || target != get_revision('HEAD')
46
+ updated!
47
+
48
+ deploy_old_created = false
49
+ if current_branch == DEPLOY_BRANCH
50
+ run_command_in_repo("git branch -m deploy-old")
51
+ deploy_old_created = true
52
+ end
53
+
54
+ fetch_origin!
55
+ run_command_in_repo(["git", "checkout", target, "-b", DEPLOY_BRANCH])
56
+
57
+ if deploy_old_created
58
+ run_command_in_repo("git branch -d deploy-old")
59
+ end
60
+ end
61
+ end
62
+
63
+ private
64
+ def ensure_git_available
65
+ unless run_command("which git", error: false).exit_status == 0
66
+ raise "`git` command is not available. Please install git."
67
+ end
68
+ end
69
+
70
+ def check_empty_dir
71
+ run_command("test -z \"$(ls -A #{shell_escape(attributes.destination)})\"", error: false).success?
72
+ end
73
+
74
+ def run_command_in_repo(*args)
75
+ run_command(*args, cwd: attributes.destination)
76
+ end
77
+
78
+ def current_branch
79
+ run_command_in_repo("git rev-parse --abbrev-ref HEAD").stdout.strip
80
+ end
81
+
82
+ def get_revision(branch)
83
+ run_command_in_repo("git rev-list #{shell_escape(branch)} | head -n1").stdout.strip
84
+ end
85
+
86
+ def fetch_origin!
87
+ return if @origin_fetched
88
+ @origin_fetched = true
89
+ run_command_in_repo(['git', 'fetch', 'origin'])
90
+ end
91
+ end
92
+ end
93
+ end
94
+
@@ -0,0 +1,42 @@
1
+ require 'itamae-mitsurin'
2
+
3
+ module ItamaeMitsurin
4
+ module Resource
5
+ class Group < Base
6
+ define_attribute :action, default: :create
7
+ define_attribute :groupname, type: String, default_name: true
8
+ define_attribute :gid, type: Integer
9
+
10
+ def set_current_attributes
11
+ current.exist = exist?
12
+
13
+ if current.exist
14
+ current.gid = run_specinfra(:get_group_gid, attributes.groupname).stdout.strip.to_i
15
+ end
16
+ end
17
+
18
+ def action_create(options)
19
+ if run_specinfra(:check_group_exists, attributes.groupname)
20
+ if attributes.gid && attributes.gid != current.gid
21
+ run_specinfra(:update_group_gid, attributes.groupname, attributes.gid)
22
+ updated!
23
+ end
24
+ else
25
+ options = {
26
+ gid: attributes.gid,
27
+ }
28
+
29
+ run_specinfra(:add_group, attributes.groupname, options)
30
+
31
+ updated!
32
+ end
33
+ end
34
+
35
+ private
36
+ def exist?
37
+ run_specinfra(:check_group_exists, attributes.groupname)
38
+ end
39
+ end
40
+ end
41
+ end
42
+
@@ -0,0 +1,71 @@
1
+ require 'itamae-mitsurin'
2
+ require 'uri'
3
+ require 'net/https'
4
+
5
+ module ItamaeMitsurin
6
+ module Resource
7
+ class HttpRequest < File
8
+ RedirectLimitExceeded = Class.new(StandardError)
9
+
10
+ define_attribute :action, default: :get
11
+ define_attribute :headers, type: Hash, default: {}
12
+ define_attribute :message, type: String, default: ""
13
+ define_attribute :redirect_limit, type: Integer, default: 10
14
+ define_attribute :url, type: String, required: true
15
+
16
+ def pre_action
17
+ uri = URI.parse(attributes.url)
18
+ response = nil
19
+ redirects_followed = 0
20
+
21
+ loop do
22
+ http = Net::HTTP.new(uri.host, uri.port)
23
+ http.use_ssl = true if uri.scheme == "https"
24
+
25
+ case attributes.action
26
+ when :delete, :get, :options
27
+ response = http.method(attributes.action).call(uri.request_uri, attributes.headers)
28
+ when :post, :put
29
+ response = http.method(attributes.action).call(uri.request_uri, attributes.message, attributes.headers)
30
+ end
31
+
32
+ if response.kind_of?(Net::HTTPRedirection)
33
+ if redirects_followed < attributes.redirect_limit
34
+ uri = URI.parse(response["location"])
35
+ redirects_followed += 1
36
+ ItamaeMitsurin.logger.debug "Following redirect #{redirects_followed}/#{attributes.redirect_limit}"
37
+ else
38
+ raise RedirectLimitExceeded
39
+ end
40
+ else
41
+ break
42
+ end
43
+ end
44
+
45
+ attributes.content = response.body
46
+
47
+ super
48
+ end
49
+
50
+ def action_delete(options)
51
+ action_create(options)
52
+ end
53
+
54
+ def action_get(options)
55
+ action_create(options)
56
+ end
57
+
58
+ def action_options(options)
59
+ action_create(options)
60
+ end
61
+
62
+ def action_post(options)
63
+ action_create(options)
64
+ end
65
+
66
+ def action_put(options)
67
+ action_create(options)
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,33 @@
1
+ require 'itamae-mitsurin'
2
+
3
+ module ItamaeMitsurin
4
+ module Resource
5
+ class Link < Base
6
+ define_attribute :action, default: :create
7
+ define_attribute :link, type: String, default_name: true
8
+ define_attribute :to, type: String, required: true
9
+ define_attribute :force, type: [TrueClass, FalseClass], default: false
10
+
11
+ def pre_action
12
+ case @current_action
13
+ when :create
14
+ attributes.exist = true
15
+ end
16
+ end
17
+
18
+ def set_current_attributes
19
+ current.exist = run_specinfra(:check_file_is_link, attributes.link)
20
+
21
+ if current.exist
22
+ current.to = run_specinfra(:get_file_link_target, attributes.link).stdout.strip
23
+ end
24
+ end
25
+
26
+ def action_create(options)
27
+ unless run_specinfra(:check_file_is_linked_to, attributes.link, attributes.to)
28
+ run_specinfra(:link_file_to, attributes.link, attributes.to, force: attributes.force)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end