mdt-core 0.1.1 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/bin/mdt +27 -0
- data/lib/mdt/helpers/runner.rb +65 -5
- data/lib/mdt/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d4b360b10692c81ee67737d4a144883aac685dc396f8d4a8fb364ac508cdebd
|
4
|
+
data.tar.gz: 3b9cdc1c0cb40c950eadebc257649817842fb9d615a46df014ba6759be5d3393
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c8039873e1e5a0f0582d9fa21b542c81bda5b276235ce00b98a609df741cbe64101ad596b48c3181936702062a4b6b62449b1064e001200faa15eb241a4ee83d
|
7
|
+
data.tar.gz: 6095c6a169927bdd804dbfcc2c29a93250e2ceaf8c24100c5367b83e5eef367746acc217688568fb7b216b269d7fcae26152d3ee87df1874604a8174115d1e64
|
data/README.md
CHANGED
@@ -41,6 +41,8 @@ MDT defines 5 modular objects that can be used to build a simple deploy flow. Th
|
|
41
41
|
|
42
42
|
* [mdt-dummy](https://github.com/Phitherek/mdt-dummy "mdt-dummy") - a module containing dummy implementations of each extensible MDT class. They can be used to skip a particular deployment step.
|
43
43
|
* [mdt-simple](https://github.com/Phitherek/mdt-simple "mdt-simple") - a module that contains simple implementations for MDT.
|
44
|
+
* [mdt-versioned](https://github.com/Phitherek/mdt-versioned "mdt-versioned") - a module that implements versioned releases deployment flow for MDT.
|
45
|
+
* [mdt-git](https://github.com/Phitherek/mdt-git "mdt-git") - a Git module for MDT.
|
44
46
|
|
45
47
|
## Contributing
|
46
48
|
|
data/bin/mdt
CHANGED
@@ -25,6 +25,7 @@ op.parse!
|
|
25
25
|
|
26
26
|
if ARGV.count < 1
|
27
27
|
puts op.banner
|
28
|
+
exit 0
|
28
29
|
end
|
29
30
|
|
30
31
|
config = YAML.load_file(script_opts[:config_path])
|
@@ -41,6 +42,8 @@ unless subconfig.has_key?('directory_chooser') && subconfig.has_key?('fetcher')
|
|
41
42
|
exit 1
|
42
43
|
end
|
43
44
|
|
45
|
+
pre_contents = subconfig['pre_contents'] || []
|
46
|
+
|
44
47
|
dirchooser_config = subconfig['directory_chooser']
|
45
48
|
|
46
49
|
unless dirchooser_config.has_key?('type')
|
@@ -89,9 +92,23 @@ end
|
|
89
92
|
fetcher = fetcher.new
|
90
93
|
|
91
94
|
root_contents = subconfig['contents']
|
95
|
+
post_contents = subconfig['post_contents'] || []
|
92
96
|
|
93
97
|
puts "Successfully loaded config: #{config_key}! Starting deploy..."
|
94
98
|
|
99
|
+
puts 'Running pre-deploy commands...'
|
100
|
+
|
101
|
+
begin
|
102
|
+
unless MDT::Helpers::Runner.process_contents(pre_contents)
|
103
|
+
puts 'ERROR: Pre-deploy process finished with failure!'
|
104
|
+
exit 1
|
105
|
+
end
|
106
|
+
rescue => e
|
107
|
+
puts "Exception: #{e.message}"
|
108
|
+
puts e.backtrace
|
109
|
+
exit 1
|
110
|
+
end
|
111
|
+
|
95
112
|
unless dirchooser.mkdir(dirchooser_value, dirchooser_options) == 0
|
96
113
|
puts 'ERROR: Directory chooser could not create a directory!'
|
97
114
|
exit 1
|
@@ -99,25 +116,35 @@ end
|
|
99
116
|
begin
|
100
117
|
unless dirchooser.cd(dirchooser_value, dirchooser_options) == 0
|
101
118
|
puts 'ERROR: Directory chooser could not enter a directory!'
|
119
|
+
puts 'Running post-deploy commands...'
|
120
|
+
MDT::Helpers::Runner.process_post_contents(post_contents, [], true)
|
102
121
|
dirchooser.rm(dirchooser_value, dirchooser_options)
|
103
122
|
exit 1
|
104
123
|
end
|
105
124
|
unless fetcher.fetch(fetcher_value, fetcher_options) == 0
|
106
125
|
puts 'ERROR: Fetcher could not fetch!'
|
126
|
+
puts 'Running post-deploy commands...'
|
127
|
+
MDT::Helpers::Runner.process_post_contents(post_contents, [], true)
|
107
128
|
dirchooser.rm(dirchooser_value, dirchooser_options)
|
108
129
|
exit 1
|
109
130
|
end
|
110
131
|
unless MDT::Helpers::Runner.process_contents(root_contents) == 0
|
111
132
|
puts 'ERROR: Deploy process ended with failure!'
|
133
|
+
puts 'Running post-deploy commands...'
|
134
|
+
MDT::Helpers::Runner.process_post_contents(post_contents, [], true)
|
112
135
|
dirchooser.rm(dirchooser_value, dirchooser_options)
|
113
136
|
exit 1
|
114
137
|
end
|
115
138
|
rescue => e
|
116
139
|
puts "Exception: #{e.message}"
|
117
140
|
puts e.backtrace
|
141
|
+
puts 'Running post-deploy commands...'
|
142
|
+
MDT::Helpers::Runner.process_post_contents(post_contents, [], true)
|
118
143
|
dirchooser.rm(dirchooser_value, dirchooser_options)
|
119
144
|
exit 1
|
120
145
|
end
|
121
146
|
|
122
147
|
puts 'Deploy process finished successfully!'
|
148
|
+
puts 'Running post-deploy commands...'
|
149
|
+
MDT::Helpers::Runner.process_post_contents(post_contents)
|
123
150
|
exit 0
|
data/lib/mdt/helpers/runner.rb
CHANGED
@@ -33,15 +33,15 @@ module MDT
|
|
33
33
|
puts "ERROR: Could not find a command set with key #{cmd_key}. Check its correctness or install needed MDT modules."
|
34
34
|
if cmd_config['break_on_failure']
|
35
35
|
failure = true
|
36
|
-
next
|
37
36
|
end
|
37
|
+
next
|
38
38
|
end
|
39
39
|
unless cmd.subkeys.include?(cmd_value)
|
40
40
|
puts "ERROR: Command set with key #{cmd_key} does not have a command with key #{cmd_value}!"
|
41
41
|
if cmd_config['break_on_failure']
|
42
42
|
failure = true
|
43
|
-
next
|
44
43
|
end
|
44
|
+
next
|
45
45
|
end
|
46
46
|
cmd = cmd.new
|
47
47
|
code = cmd.execute(cmd_value, cmd_modifiers, cmd_options)
|
@@ -51,8 +51,8 @@ module MDT
|
|
51
51
|
puts "Command exited with error code #{code}"
|
52
52
|
if cmd_config['break_on_failure']
|
53
53
|
failure = true
|
54
|
-
next
|
55
54
|
end
|
55
|
+
next
|
56
56
|
end
|
57
57
|
elsif elem.has_key?('command_group')
|
58
58
|
cg_config = elem['command_group']
|
@@ -61,8 +61,8 @@ module MDT
|
|
61
61
|
puts "ERROR: Command group #{cg_config['name']} without contents!"
|
62
62
|
if cg_config['break_on_failure']
|
63
63
|
failure = true
|
64
|
-
next
|
65
64
|
end
|
65
|
+
next
|
66
66
|
end
|
67
67
|
puts "Executing command group: #{cg_config['name']}"
|
68
68
|
code = MDT::Helpers::Runner.process_contents(cg_config['contents'], modifiers + (cg_config['command_modifiers'] || []))
|
@@ -72,8 +72,8 @@ module MDT
|
|
72
72
|
puts "Command group: #{cg_config['name']} - finished with failure"
|
73
73
|
if cg_config['break_on_failure']
|
74
74
|
failure = true
|
75
|
-
next
|
76
75
|
end
|
76
|
+
next
|
77
77
|
end
|
78
78
|
else
|
79
79
|
puts 'WARNING: Encountered a config element that is not command nor command_group, skipping...'
|
@@ -82,6 +82,66 @@ module MDT
|
|
82
82
|
end
|
83
83
|
failure ? 1 : 0
|
84
84
|
end
|
85
|
+
|
86
|
+
# A method that processes an array of contents that includes configurations for commands and command groups.
|
87
|
+
# Arguments:
|
88
|
+
# * +contents+ - an array of configurations for commands and command groups. Refer to example configuration file in the code repository for structure description
|
89
|
+
# * +modifiers+ - an array of configurations for command modifiers that have to be applied to every command defined in +contents+
|
90
|
+
# * +failure+ - a boolean that describes if the deploy process has ended with failure, false by default
|
91
|
+
# Returns:
|
92
|
+
# * nil
|
93
|
+
def self.process_post_contents(contents, modifiers = [], failure = false)
|
94
|
+
contents.each do |elem|
|
95
|
+
if elem.has_key?('command')
|
96
|
+
cmd_config = elem['command']
|
97
|
+
cmd_config['status'] ||= 'all'
|
98
|
+
cmd_key = cmd_config['type'].split('.').first
|
99
|
+
cmd_value = cmd_config['type'].split('.').last
|
100
|
+
cmd_options = cmd_config['options'] || {}
|
101
|
+
cmd_modifiers = modifiers + (cmd_config['command_modifiers'] || [])
|
102
|
+
cmd = MDT::Commands::Base.descendants.select { |c| c.key == cmd_key }.first
|
103
|
+
if cmd == nil
|
104
|
+
puts "ERROR: Could not find a command set with key #{cmd_key}. Check its correctness or install needed MDT modules."
|
105
|
+
next
|
106
|
+
end
|
107
|
+
unless cmd.subkeys.include?(cmd_value)
|
108
|
+
puts "ERROR: Command set with key #{cmd_key} does not have a command with key #{cmd_value}!"
|
109
|
+
next
|
110
|
+
end
|
111
|
+
if cmd_config['status'] == 'all'
|
112
|
+
cmd = cmd.new
|
113
|
+
code = cmd.execute(cmd_value, cmd_modifiers, cmd_options)
|
114
|
+
puts "Command exited with code #{code}"
|
115
|
+
elsif cmd_config['status'] == 'success'
|
116
|
+
unless failure
|
117
|
+
cmd = cmd.new
|
118
|
+
code = cmd.execute(cmd_value, cmd_modifiers, cmd_options)
|
119
|
+
puts "Command exited with code #{code}"
|
120
|
+
end
|
121
|
+
elsif cmd_config['status'] == 'failure'
|
122
|
+
if failure
|
123
|
+
cmd = cmd.new
|
124
|
+
code = cmd.execute(cmd_value, cmd_modifiers, cmd_options)
|
125
|
+
puts "Command exited with code #{code}"
|
126
|
+
end
|
127
|
+
else
|
128
|
+
puts 'status config key should have value all, success or failure, skipping command...'
|
129
|
+
end
|
130
|
+
elsif elem.has_key?('command_group')
|
131
|
+
cg_config = elem['command_group']
|
132
|
+
unless cg_config.has_key?('contents')
|
133
|
+
puts "ERROR: Command group #{cg_config['name']} without contents!"
|
134
|
+
next
|
135
|
+
end
|
136
|
+
puts "Executing command group: #{cg_config['name']}"
|
137
|
+
MDT::Helpers::Runner.process_post_contents(cg_config['contents'], modifiers + (cg_config['command_modifiers'] || []), failure)
|
138
|
+
puts "Command group: #{cg_config['name']} - finished"
|
139
|
+
else
|
140
|
+
puts 'WARNING: Encountered a config element that is not command nor command_group, skipping...'
|
141
|
+
end
|
142
|
+
end
|
143
|
+
nil
|
144
|
+
end
|
85
145
|
end
|
86
146
|
end
|
87
147
|
end
|
data/lib/mdt/version.rb
CHANGED