itamae-mitsurin 0.50 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (172) hide show
  1. checksums.yaml +5 -5
  2. data/lib/itamae-mitsurin/cli.rb +0 -2
  3. data/lib/itamae-mitsurin/logger.rb +74 -20
  4. data/lib/itamae-mitsurin/mitsurin/base.rb +109 -0
  5. data/lib/itamae-mitsurin/mitsurin/base_task.rb +147 -0
  6. data/lib/itamae-mitsurin/mitsurin/creators/templates/project/site-cookbooks/_base/_base/recipes/default.rb +0 -11
  7. data/lib/itamae-mitsurin/mitsurin/itamae_task.rb +44 -130
  8. data/lib/itamae-mitsurin/mitsurin/itamae_with_target_task.rb +64 -157
  9. data/lib/itamae-mitsurin/mitsurin/local_task.rb +57 -131
  10. data/lib/itamae-mitsurin/mitsurin/serverspec_task.rb +56 -81
  11. data/lib/itamae-mitsurin/mitsurin/serverspec_with_target_task.rb +80 -143
  12. data/lib/itamae-mitsurin/node.rb +0 -1
  13. data/lib/itamae-mitsurin/notification.rb +0 -1
  14. data/lib/itamae-mitsurin/recipe.rb +2 -5
  15. data/lib/itamae-mitsurin/resource.rb +1 -1
  16. data/lib/itamae-mitsurin/resource/base.rb +0 -12
  17. data/lib/itamae-mitsurin/resource/http_request.rb +23 -8
  18. data/lib/itamae-mitsurin/resource/s3_file.rb +33 -0
  19. data/lib/itamae-mitsurin/runner.rb +4 -5
  20. data/lib/itamae-mitsurin/version.txt +1 -1
  21. metadata +6 -221
  22. data/lib/itamae-mitsurin/mitsurin/itamae_with_git_task.rb +0 -159
  23. data/lib/itamae-mitsurin/mitsurin/task_base.rb +0 -100
  24. data/test/test_itamae-mitsurin.rb +0 -18
  25. data/test/test_itamae-mitsurin/ext/test_specinfra.rb +0 -39
  26. data/test/test_itamae-mitsurin/handler/test_base.rb +0 -40
  27. data/test/test_itamae-mitsurin/handler/test_debug.rb +0 -10
  28. data/test/test_itamae-mitsurin/handler/test_fluentd.rb +0 -44
  29. data/test/test_itamae-mitsurin/handler/test_json.rb +0 -22
  30. data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/.rspec +0 -2
  31. data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/Gemfile +0 -3
  32. data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/Rakefile +0 -2
  33. data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/environments/.keep +0 -0
  34. data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/environments/sample.json +0 -7
  35. data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/keys/.keep +0 -0
  36. data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/nodes/.keep +0 -0
  37. data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/nodes/sample01.json +0 -9
  38. data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/roles/.keep +0 -0
  39. data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/site-cookbooks/_base/_base/attributes/.keep +0 -0
  40. data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/site-cookbooks/_base/_base/files/.keep +0 -0
  41. data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/site-cookbooks/_base/_base/recipes/default.rb +0 -1
  42. data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/site-cookbooks/_base/_base/spec/default_spec.rb +0 -1
  43. data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/site-cookbooks/_base/_base/templates/.keep +0 -0
  44. data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/spec/spec_helper.rb +0 -33
  45. data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/tmp-nodes/.keep +0 -0
  46. data/test/test_itamae-mitsurin/mitsurin/creators/templates/site-cookbooks/attributes/.keep +0 -0
  47. data/test/test_itamae-mitsurin/mitsurin/creators/templates/site-cookbooks/files/.keep +0 -0
  48. data/test/test_itamae-mitsurin/mitsurin/creators/templates/site-cookbooks/recipes/default.rb +0 -0
  49. data/test/test_itamae-mitsurin/mitsurin/creators/templates/site-cookbooks/spec/.keep +0 -0
  50. data/test/test_itamae-mitsurin/mitsurin/creators/templates/site-cookbooks/templates/.keep +0 -0
  51. data/test/test_itamae-mitsurin/mitsurin/creators/test_cookbook.rb +0 -24
  52. data/test/test_itamae-mitsurin/mitsurin/creators/test_project.rb +0 -24
  53. data/test/test_itamae-mitsurin/mitsurin/test_cli.rb +0 -56
  54. data/test/test_itamae-mitsurin/mitsurin/test_creators.rb +0 -19
  55. data/test/test_itamae-mitsurin/mitsurin/test_itamae_task.rb +0 -197
  56. data/test/test_itamae-mitsurin/mitsurin/test_itamae_with_git_task.rb +0 -213
  57. data/test/test_itamae-mitsurin/mitsurin/test_serverspec_task.rb +0 -123
  58. data/test/test_itamae-mitsurin/resource/test_aws_ebs_volume.rb +0 -84
  59. data/test/test_itamae-mitsurin/resource/test_base.rb +0 -374
  60. data/test/test_itamae-mitsurin/resource/test_directory.rb +0 -63
  61. data/test/test_itamae-mitsurin/resource/test_execute.rb +0 -26
  62. data/test/test_itamae-mitsurin/resource/test_file.rb +0 -176
  63. data/test/test_itamae-mitsurin/resource/test_gem_package.rb +0 -81
  64. data/test/test_itamae-mitsurin/resource/test_git.rb +0 -94
  65. data/test/test_itamae-mitsurin/resource/test_group.rb +0 -42
  66. data/test/test_itamae-mitsurin/resource/test_http_request.rb +0 -71
  67. data/test/test_itamae-mitsurin/resource/test_link.rb +0 -33
  68. data/test/test_itamae-mitsurin/resource/test_local_ruby_block.rb +0 -15
  69. data/test/test_itamae-mitsurin/resource/test_package.rb +0 -44
  70. data/test/test_itamae-mitsurin/resource/test_remote_directory.rb +0 -84
  71. data/test/test_itamae-mitsurin/resource/test_remote_file.rb +0 -54
  72. data/test/test_itamae-mitsurin/resource/test_service.rb +0 -69
  73. data/test/test_itamae-mitsurin/resource/test_template.rb +0 -53
  74. data/test/test_itamae-mitsurin/resource/test_user.rb +0 -93
  75. data/test/test_itamae-mitsurin/test_backend.rb +0 -297
  76. data/test/test_itamae-mitsurin/test_cli.rb +0 -88
  77. data/test/test_itamae-mitsurin/test_definition.rb +0 -40
  78. data/test/test_itamae-mitsurin/test_ext.rb +0 -1
  79. data/test/test_itamae-mitsurin/test_handler.rb +0 -21
  80. data/test/test_itamae-mitsurin/test_handler_proxy.rb +0 -38
  81. data/test/test_itamae-mitsurin/test_logger.rb +0 -124
  82. data/test/test_itamae-mitsurin/test_mitsurin.rb +0 -14
  83. data/test/test_itamae-mitsurin/test_node.rb +0 -74
  84. data/test/test_itamae-mitsurin/test_notification.rb +0 -46
  85. data/test/test_itamae-mitsurin/test_recipe.rb +0 -171
  86. data/test/test_itamae-mitsurin/test_recipe_children.rb +0 -86
  87. data/test/test_itamae-mitsurin/test_resource.rb +0 -73
  88. data/test/test_itamae-mitsurin/test_runner.rb +0 -124
  89. data/test/test_itamae-mitsurin/test_version.rb +0 -3
  90. data/test/test_itamae-mitsurin/version.txt +0 -1
  91. data/test_project/.rspec +0 -2
  92. data/test_project/Gemfile +0 -4
  93. data/test_project/Rakefile +0 -3
  94. data/test_project/environments/.keep +0 -0
  95. data/test_project/keys/.keep +0 -0
  96. data/test_project/nodes/.keep +0 -0
  97. data/test_project/nodes/test.json +0 -9
  98. data/test_project/roles/.keep +0 -0
  99. data/test_project/roles/test.json +0 -14
  100. data/test_project/site-cookbooks/_base/_base/attributes/.keep +0 -0
  101. data/test_project/site-cookbooks/_base/_base/files/.keep +0 -0
  102. data/test_project/site-cookbooks/_base/_base/recipes/default.rb +0 -1
  103. data/test_project/site-cookbooks/_base/_base/spec/default_spec.rb +0 -1
  104. data/test_project/site-cookbooks/_base/_base/templates/.keep +0 -0
  105. data/test_project/site-cookbooks/a_test/directory/attributes/.keep +0 -0
  106. data/test_project/site-cookbooks/a_test/directory/files/.keep +0 -0
  107. data/test_project/site-cookbooks/a_test/directory/recipes/default.rb +0 -8
  108. data/test_project/site-cookbooks/a_test/directory/spec/.keep +0 -0
  109. data/test_project/site-cookbooks/a_test/directory/spec/default_spec.rb +0 -4
  110. data/test_project/site-cookbooks/a_test/directory/templates/.keep +0 -0
  111. data/test_project/site-cookbooks/a_test/package/attributes/.keep +0 -0
  112. data/test_project/site-cookbooks/a_test/package/files/.keep +0 -0
  113. data/test_project/site-cookbooks/a_test/package/recipes/default.rb +0 -2
  114. data/test_project/site-cookbooks/a_test/package/spec/.keep +0 -0
  115. data/test_project/site-cookbooks/a_test/package/spec/default_spec.rb +0 -4
  116. data/test_project/site-cookbooks/a_test/package/templates/.keep +0 -0
  117. data/test_project/site-cookbooks/a_test/service/attributes/.keep +0 -0
  118. data/test_project/site-cookbooks/a_test/service/files/.keep +0 -0
  119. data/test_project/site-cookbooks/a_test/service/recipes/default.rb +0 -5
  120. data/test_project/site-cookbooks/a_test/service/spec/.keep +0 -0
  121. data/test_project/site-cookbooks/a_test/service/spec/default_spec.rb +0 -6
  122. data/test_project/site-cookbooks/a_test/service/templates/.keep +0 -0
  123. data/test_project/site-cookbooks/b_test/git/attributes/.keep +0 -0
  124. data/test_project/site-cookbooks/b_test/git/files/.keep +0 -0
  125. data/test_project/site-cookbooks/b_test/git/recipes/default.rb +0 -5
  126. data/test_project/site-cookbooks/b_test/git/spec/.keep +0 -0
  127. data/test_project/site-cookbooks/b_test/git/spec/default_spec.rb +0 -5
  128. data/test_project/site-cookbooks/b_test/git/templates/.keep +0 -0
  129. data/test_project/site-cookbooks/b_test/link/attributes/.keep +0 -0
  130. data/test_project/site-cookbooks/b_test/link/files/.keep +0 -0
  131. data/test_project/site-cookbooks/b_test/link/recipes/default.rb +0 -5
  132. data/test_project/site-cookbooks/b_test/link/spec/.keep +0 -0
  133. data/test_project/site-cookbooks/b_test/link/spec/default_spec.rb +0 -5
  134. data/test_project/site-cookbooks/b_test/link/templates/.keep +0 -0
  135. data/test_project/site-cookbooks/b_test/remote_file/attributes/.keep +0 -0
  136. data/test_project/site-cookbooks/b_test/remote_file/files/.keep +0 -0
  137. data/test_project/site-cookbooks/b_test/remote_file/files/remote_file.sh +0 -1
  138. data/test_project/site-cookbooks/b_test/remote_file/recipes/default.rb +0 -9
  139. data/test_project/site-cookbooks/b_test/remote_file/spec/.keep +0 -0
  140. data/test_project/site-cookbooks/b_test/remote_file/spec/default_spec.rb +0 -7
  141. data/test_project/site-cookbooks/b_test/remote_file/templates/.keep +0 -0
  142. data/test_project/site-cookbooks/b_test/template/attributes/.keep +0 -0
  143. data/test_project/site-cookbooks/b_test/template/files/.keep +0 -0
  144. data/test_project/site-cookbooks/b_test/template/recipes/default.rb +0 -5
  145. data/test_project/site-cookbooks/b_test/template/spec/.keep +0 -0
  146. data/test_project/site-cookbooks/b_test/template/spec/default_spec.rb +0 -7
  147. data/test_project/site-cookbooks/b_test/template/templates/.keep +0 -0
  148. data/test_project/site-cookbooks/b_test/template/templates/template.erb +0 -2
  149. data/test_project/site-cookbooks/c_test/execute/attributes/.keep +0 -0
  150. data/test_project/site-cookbooks/c_test/execute/files/.keep +0 -0
  151. data/test_project/site-cookbooks/c_test/execute/recipes/default.rb +0 -6
  152. data/test_project/site-cookbooks/c_test/execute/spec/.keep +0 -0
  153. data/test_project/site-cookbooks/c_test/execute/spec/default_spec.rb +0 -6
  154. data/test_project/site-cookbooks/c_test/execute/templates/.keep +0 -0
  155. data/test_project/site-cookbooks/c_test/remote_directory/attributes/.keep +0 -0
  156. data/test_project/site-cookbooks/c_test/remote_directory/files/.keep +0 -0
  157. data/test_project/site-cookbooks/c_test/remote_directory/recipes/default.rb +0 -10
  158. data/test_project/site-cookbooks/c_test/remote_directory/spec/.keep +0 -0
  159. data/test_project/site-cookbooks/c_test/remote_directory/spec/default_spec.rb +0 -20
  160. data/test_project/site-cookbooks/c_test/remote_directory/templates/.keep +0 -0
  161. data/test_project/site-cookbooks/c_test/remote_directory/templates/remote_dir/a.txt +0 -0
  162. data/test_project/site-cookbooks/c_test/remote_directory/templates/remote_dir/b.txt +0 -0
  163. data/test_project/site-cookbooks/c_test/remote_directory/templates/remote_dir/c.txt +0 -0
  164. data/test_project/site-cookbooks/d_spec/air/attributes/.keep +0 -0
  165. data/test_project/site-cookbooks/d_spec/air/files/.keep +0 -0
  166. data/test_project/site-cookbooks/d_spec/air/recipes/default.rb +0 -0
  167. data/test_project/site-cookbooks/d_spec/air/spec/.keep +0 -0
  168. data/test_project/site-cookbooks/d_spec/air/spec/default_spec.rb +0 -0
  169. data/test_project/site-cookbooks/d_spec/air/templates/.keep +0 -0
  170. data/test_project/spec/spec_helper.rb +0 -33
  171. data/test_project/tmp-nodes/.keep +0 -0
  172. data/test_project/tmp-nodes/test.json +0 -12
@@ -1,63 +0,0 @@
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
-
@@ -1,26 +0,0 @@
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,176 +0,0 @@
1
- require 'itamae-mitsurin'
2
-
3
- module ItamaeMitsurin
4
- module Resource
5
- class File < Base
6
- define_attribute :action, default: :create
7
- define_attribute :path, type: String, default_name: true
8
- define_attribute :content, type: String, default: nil
9
- define_attribute :mode, type: String
10
- define_attribute :owner, type: String
11
- define_attribute :group, type: String
12
- define_attribute :block, type: Proc, default: proc {}
13
-
14
- def pre_action
15
- case @current_action
16
- when :create
17
- attributes.exist = true
18
- when :delete
19
- attributes.exist = false
20
- when :edit
21
- attributes.exist = true
22
-
23
- unless runner.dry_run?
24
- content = backend.receive_file(attributes.path)
25
- attributes.block.call(content)
26
- attributes.content = content
27
- end
28
- end
29
-
30
- send_tempfile
31
- end
32
-
33
- def set_current_attributes
34
- current.exist = run_specinfra(:check_file_is_file, attributes.path)
35
-
36
- if current.exist
37
- current.mode = run_specinfra(:get_file_mode, attributes.path).stdout.chomp
38
- current.owner = run_specinfra(:get_file_owner_user, attributes.path).stdout.chomp
39
- current.group = run_specinfra(:get_file_owner_group, attributes.path).stdout.chomp
40
- else
41
- current.mode = nil
42
- current.owner = nil
43
- current.group = nil
44
- end
45
- end
46
-
47
- def show_differences
48
- current.mode = current.mode.rjust(4, '0') if current.mode
49
- attributes.mode = attributes.mode.rjust(4, '0') if attributes.mode
50
-
51
- super
52
-
53
- if @temppath
54
- compare_file
55
- end
56
- end
57
-
58
- def action_create(options)
59
- if !current.exist && !@temppath
60
- run_command(["touch", attributes.path])
61
- end
62
-
63
- change_target = @temppath || attributes.path
64
-
65
- if attributes.mode
66
- run_specinfra(:change_file_mode, change_target, attributes.mode)
67
- end
68
- if attributes.owner || attributes.group
69
- run_specinfra(:change_file_owner, change_target, attributes.owner, attributes.group)
70
- end
71
-
72
- if @temppath
73
- if run_specinfra(:check_file_is_file, attributes.path)
74
- unless check_command(["diff", "-q", @temppath, attributes.path])
75
- # the file is modified
76
- updated!
77
- end
78
- else
79
- # new file
80
- updated!
81
- end
82
-
83
- if updated?
84
- run_specinfra(:move_file, @temppath, attributes.path)
85
- end
86
- end
87
- end
88
-
89
- def action_delete(options)
90
- if run_specinfra(:check_file_is_file, attributes.path)
91
- run_specinfra(:remove_file, attributes.path)
92
- end
93
- end
94
-
95
- def action_edit(options)
96
- if attributes.mode
97
- run_specinfra(:change_file_mode, @temppath, attributes.mode)
98
- else
99
- run_command(['chmod', '--reference', attributes.path, @temppath])
100
- end
101
-
102
- if attributes.owner || attributes.group
103
- run_specinfra(:change_file_owner, @temppath, attributes.owner, attributes.group)
104
- else
105
- run_command(['chown', '--reference', attributes.path, @temppath])
106
- end
107
-
108
- unless check_command(["diff", "-q", @temppath, attributes.path])
109
- # the file is modified
110
- updated!
111
- end
112
-
113
- run_specinfra(:move_file, @temppath, attributes.path)
114
- end
115
-
116
- private
117
-
118
- def compare_file
119
- compare_to = if current.exist
120
- attributes.path
121
- else
122
- '/dev/null'
123
- end
124
-
125
- diff = run_command(["diff", "-u", compare_to, @temppath], error: false)
126
- if diff.exit_status == 0
127
- # no change
128
- ItamaeMitsurin.logger.debug "file content will not change"
129
- else
130
- ItamaeMitsurin.logger.info "diff:"
131
- diff.stdout.each_line do |line|
132
- color = if line.start_with?('+')
133
- :green
134
- elsif line.start_with?('-')
135
- :red
136
- else
137
- :clear
138
- end
139
- ItamaeMitsurin.logger.color(color) do
140
- ItamaeMitsurin.logger.info line.chomp
141
- end
142
- end
143
- runner.handler.event(:file_content_changed, diff: diff.stdout)
144
- end
145
- end
146
-
147
- # will be overridden
148
- def content_file
149
- nil
150
- end
151
-
152
- def send_tempfile
153
- if !attributes.content && !content_file
154
- @temppath = nil
155
- return
156
- end
157
-
158
- begin
159
- src = if content_file
160
- content_file
161
- else
162
- f = Tempfile.open('itamae')
163
- f.write(attributes.content)
164
- f.close
165
- f.path
166
- end
167
-
168
- @temppath = ::File.join(runner.tmpdir, Time.now.to_f.to_s)
169
- backend.send_file(src, @temppath)
170
- ensure
171
- f.unlink if f
172
- end
173
- end
174
- end
175
- end
176
- end
@@ -1,81 +0,0 @@
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
@@ -1,94 +0,0 @@
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
-
@@ -1,42 +0,0 @@
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
-