itamae-mitsurin 0.50 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/itamae-mitsurin/cli.rb +0 -2
- data/lib/itamae-mitsurin/logger.rb +74 -20
- data/lib/itamae-mitsurin/mitsurin/base.rb +109 -0
- data/lib/itamae-mitsurin/mitsurin/base_task.rb +147 -0
- data/lib/itamae-mitsurin/mitsurin/creators/templates/project/site-cookbooks/_base/_base/recipes/default.rb +0 -11
- data/lib/itamae-mitsurin/mitsurin/itamae_task.rb +44 -130
- data/lib/itamae-mitsurin/mitsurin/itamae_with_target_task.rb +64 -157
- data/lib/itamae-mitsurin/mitsurin/local_task.rb +57 -131
- data/lib/itamae-mitsurin/mitsurin/serverspec_task.rb +56 -81
- data/lib/itamae-mitsurin/mitsurin/serverspec_with_target_task.rb +80 -143
- data/lib/itamae-mitsurin/node.rb +0 -1
- data/lib/itamae-mitsurin/notification.rb +0 -1
- data/lib/itamae-mitsurin/recipe.rb +2 -5
- data/lib/itamae-mitsurin/resource.rb +1 -1
- data/lib/itamae-mitsurin/resource/base.rb +0 -12
- data/lib/itamae-mitsurin/resource/http_request.rb +23 -8
- data/lib/itamae-mitsurin/resource/s3_file.rb +33 -0
- data/lib/itamae-mitsurin/runner.rb +4 -5
- data/lib/itamae-mitsurin/version.txt +1 -1
- metadata +6 -221
- data/lib/itamae-mitsurin/mitsurin/itamae_with_git_task.rb +0 -159
- data/lib/itamae-mitsurin/mitsurin/task_base.rb +0 -100
- data/test/test_itamae-mitsurin.rb +0 -18
- data/test/test_itamae-mitsurin/ext/test_specinfra.rb +0 -39
- data/test/test_itamae-mitsurin/handler/test_base.rb +0 -40
- data/test/test_itamae-mitsurin/handler/test_debug.rb +0 -10
- data/test/test_itamae-mitsurin/handler/test_fluentd.rb +0 -44
- data/test/test_itamae-mitsurin/handler/test_json.rb +0 -22
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/.rspec +0 -2
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/Gemfile +0 -3
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/Rakefile +0 -2
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/environments/.keep +0 -0
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/environments/sample.json +0 -7
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/keys/.keep +0 -0
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/nodes/.keep +0 -0
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/nodes/sample01.json +0 -9
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/roles/.keep +0 -0
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/site-cookbooks/_base/_base/attributes/.keep +0 -0
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/site-cookbooks/_base/_base/files/.keep +0 -0
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/site-cookbooks/_base/_base/recipes/default.rb +0 -1
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/site-cookbooks/_base/_base/spec/default_spec.rb +0 -1
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/site-cookbooks/_base/_base/templates/.keep +0 -0
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/spec/spec_helper.rb +0 -33
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/tmp-nodes/.keep +0 -0
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/site-cookbooks/attributes/.keep +0 -0
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/site-cookbooks/files/.keep +0 -0
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/site-cookbooks/recipes/default.rb +0 -0
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/site-cookbooks/spec/.keep +0 -0
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/site-cookbooks/templates/.keep +0 -0
- data/test/test_itamae-mitsurin/mitsurin/creators/test_cookbook.rb +0 -24
- data/test/test_itamae-mitsurin/mitsurin/creators/test_project.rb +0 -24
- data/test/test_itamae-mitsurin/mitsurin/test_cli.rb +0 -56
- data/test/test_itamae-mitsurin/mitsurin/test_creators.rb +0 -19
- data/test/test_itamae-mitsurin/mitsurin/test_itamae_task.rb +0 -197
- data/test/test_itamae-mitsurin/mitsurin/test_itamae_with_git_task.rb +0 -213
- data/test/test_itamae-mitsurin/mitsurin/test_serverspec_task.rb +0 -123
- data/test/test_itamae-mitsurin/resource/test_aws_ebs_volume.rb +0 -84
- data/test/test_itamae-mitsurin/resource/test_base.rb +0 -374
- data/test/test_itamae-mitsurin/resource/test_directory.rb +0 -63
- data/test/test_itamae-mitsurin/resource/test_execute.rb +0 -26
- data/test/test_itamae-mitsurin/resource/test_file.rb +0 -176
- data/test/test_itamae-mitsurin/resource/test_gem_package.rb +0 -81
- data/test/test_itamae-mitsurin/resource/test_git.rb +0 -94
- data/test/test_itamae-mitsurin/resource/test_group.rb +0 -42
- data/test/test_itamae-mitsurin/resource/test_http_request.rb +0 -71
- data/test/test_itamae-mitsurin/resource/test_link.rb +0 -33
- data/test/test_itamae-mitsurin/resource/test_local_ruby_block.rb +0 -15
- data/test/test_itamae-mitsurin/resource/test_package.rb +0 -44
- data/test/test_itamae-mitsurin/resource/test_remote_directory.rb +0 -84
- data/test/test_itamae-mitsurin/resource/test_remote_file.rb +0 -54
- data/test/test_itamae-mitsurin/resource/test_service.rb +0 -69
- data/test/test_itamae-mitsurin/resource/test_template.rb +0 -53
- data/test/test_itamae-mitsurin/resource/test_user.rb +0 -93
- data/test/test_itamae-mitsurin/test_backend.rb +0 -297
- data/test/test_itamae-mitsurin/test_cli.rb +0 -88
- data/test/test_itamae-mitsurin/test_definition.rb +0 -40
- data/test/test_itamae-mitsurin/test_ext.rb +0 -1
- data/test/test_itamae-mitsurin/test_handler.rb +0 -21
- data/test/test_itamae-mitsurin/test_handler_proxy.rb +0 -38
- data/test/test_itamae-mitsurin/test_logger.rb +0 -124
- data/test/test_itamae-mitsurin/test_mitsurin.rb +0 -14
- data/test/test_itamae-mitsurin/test_node.rb +0 -74
- data/test/test_itamae-mitsurin/test_notification.rb +0 -46
- data/test/test_itamae-mitsurin/test_recipe.rb +0 -171
- data/test/test_itamae-mitsurin/test_recipe_children.rb +0 -86
- data/test/test_itamae-mitsurin/test_resource.rb +0 -73
- data/test/test_itamae-mitsurin/test_runner.rb +0 -124
- data/test/test_itamae-mitsurin/test_version.rb +0 -3
- data/test/test_itamae-mitsurin/version.txt +0 -1
- data/test_project/.rspec +0 -2
- data/test_project/Gemfile +0 -4
- data/test_project/Rakefile +0 -3
- data/test_project/environments/.keep +0 -0
- data/test_project/keys/.keep +0 -0
- data/test_project/nodes/.keep +0 -0
- data/test_project/nodes/test.json +0 -9
- data/test_project/roles/.keep +0 -0
- data/test_project/roles/test.json +0 -14
- data/test_project/site-cookbooks/_base/_base/attributes/.keep +0 -0
- data/test_project/site-cookbooks/_base/_base/files/.keep +0 -0
- data/test_project/site-cookbooks/_base/_base/recipes/default.rb +0 -1
- data/test_project/site-cookbooks/_base/_base/spec/default_spec.rb +0 -1
- data/test_project/site-cookbooks/_base/_base/templates/.keep +0 -0
- data/test_project/site-cookbooks/a_test/directory/attributes/.keep +0 -0
- data/test_project/site-cookbooks/a_test/directory/files/.keep +0 -0
- data/test_project/site-cookbooks/a_test/directory/recipes/default.rb +0 -8
- data/test_project/site-cookbooks/a_test/directory/spec/.keep +0 -0
- data/test_project/site-cookbooks/a_test/directory/spec/default_spec.rb +0 -4
- data/test_project/site-cookbooks/a_test/directory/templates/.keep +0 -0
- data/test_project/site-cookbooks/a_test/package/attributes/.keep +0 -0
- data/test_project/site-cookbooks/a_test/package/files/.keep +0 -0
- data/test_project/site-cookbooks/a_test/package/recipes/default.rb +0 -2
- data/test_project/site-cookbooks/a_test/package/spec/.keep +0 -0
- data/test_project/site-cookbooks/a_test/package/spec/default_spec.rb +0 -4
- data/test_project/site-cookbooks/a_test/package/templates/.keep +0 -0
- data/test_project/site-cookbooks/a_test/service/attributes/.keep +0 -0
- data/test_project/site-cookbooks/a_test/service/files/.keep +0 -0
- data/test_project/site-cookbooks/a_test/service/recipes/default.rb +0 -5
- data/test_project/site-cookbooks/a_test/service/spec/.keep +0 -0
- data/test_project/site-cookbooks/a_test/service/spec/default_spec.rb +0 -6
- data/test_project/site-cookbooks/a_test/service/templates/.keep +0 -0
- data/test_project/site-cookbooks/b_test/git/attributes/.keep +0 -0
- data/test_project/site-cookbooks/b_test/git/files/.keep +0 -0
- data/test_project/site-cookbooks/b_test/git/recipes/default.rb +0 -5
- data/test_project/site-cookbooks/b_test/git/spec/.keep +0 -0
- data/test_project/site-cookbooks/b_test/git/spec/default_spec.rb +0 -5
- data/test_project/site-cookbooks/b_test/git/templates/.keep +0 -0
- data/test_project/site-cookbooks/b_test/link/attributes/.keep +0 -0
- data/test_project/site-cookbooks/b_test/link/files/.keep +0 -0
- data/test_project/site-cookbooks/b_test/link/recipes/default.rb +0 -5
- data/test_project/site-cookbooks/b_test/link/spec/.keep +0 -0
- data/test_project/site-cookbooks/b_test/link/spec/default_spec.rb +0 -5
- data/test_project/site-cookbooks/b_test/link/templates/.keep +0 -0
- data/test_project/site-cookbooks/b_test/remote_file/attributes/.keep +0 -0
- data/test_project/site-cookbooks/b_test/remote_file/files/.keep +0 -0
- data/test_project/site-cookbooks/b_test/remote_file/files/remote_file.sh +0 -1
- data/test_project/site-cookbooks/b_test/remote_file/recipes/default.rb +0 -9
- data/test_project/site-cookbooks/b_test/remote_file/spec/.keep +0 -0
- data/test_project/site-cookbooks/b_test/remote_file/spec/default_spec.rb +0 -7
- data/test_project/site-cookbooks/b_test/remote_file/templates/.keep +0 -0
- data/test_project/site-cookbooks/b_test/template/attributes/.keep +0 -0
- data/test_project/site-cookbooks/b_test/template/files/.keep +0 -0
- data/test_project/site-cookbooks/b_test/template/recipes/default.rb +0 -5
- data/test_project/site-cookbooks/b_test/template/spec/.keep +0 -0
- data/test_project/site-cookbooks/b_test/template/spec/default_spec.rb +0 -7
- data/test_project/site-cookbooks/b_test/template/templates/.keep +0 -0
- data/test_project/site-cookbooks/b_test/template/templates/template.erb +0 -2
- data/test_project/site-cookbooks/c_test/execute/attributes/.keep +0 -0
- data/test_project/site-cookbooks/c_test/execute/files/.keep +0 -0
- data/test_project/site-cookbooks/c_test/execute/recipes/default.rb +0 -6
- data/test_project/site-cookbooks/c_test/execute/spec/.keep +0 -0
- data/test_project/site-cookbooks/c_test/execute/spec/default_spec.rb +0 -6
- data/test_project/site-cookbooks/c_test/execute/templates/.keep +0 -0
- data/test_project/site-cookbooks/c_test/remote_directory/attributes/.keep +0 -0
- data/test_project/site-cookbooks/c_test/remote_directory/files/.keep +0 -0
- data/test_project/site-cookbooks/c_test/remote_directory/recipes/default.rb +0 -10
- data/test_project/site-cookbooks/c_test/remote_directory/spec/.keep +0 -0
- data/test_project/site-cookbooks/c_test/remote_directory/spec/default_spec.rb +0 -20
- data/test_project/site-cookbooks/c_test/remote_directory/templates/.keep +0 -0
- data/test_project/site-cookbooks/c_test/remote_directory/templates/remote_dir/a.txt +0 -0
- data/test_project/site-cookbooks/c_test/remote_directory/templates/remote_dir/b.txt +0 -0
- data/test_project/site-cookbooks/c_test/remote_directory/templates/remote_dir/c.txt +0 -0
- data/test_project/site-cookbooks/d_spec/air/attributes/.keep +0 -0
- data/test_project/site-cookbooks/d_spec/air/files/.keep +0 -0
- data/test_project/site-cookbooks/d_spec/air/recipes/default.rb +0 -0
- data/test_project/site-cookbooks/d_spec/air/spec/.keep +0 -0
- data/test_project/site-cookbooks/d_spec/air/spec/default_spec.rb +0 -0
- data/test_project/site-cookbooks/d_spec/air/templates/.keep +0 -0
- data/test_project/spec/spec_helper.rb +0 -33
- data/test_project/tmp-nodes/.keep +0 -0
- 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
|
-
|