brpm_content_framework 0.2.32 → 0.2.33
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/config.yml +1 -1
- data/{infrastructure/docker → docker}/Dockerfile +2 -1
- data/{infrastructure/docker → docker}/docker_execute_automation +0 -0
- data/infrastructure/scripts/publish_module_version.sh +13 -8
- data/infrastructure/{create_output_file.rb → setup_brpm_core_framework.rb} +0 -0
- data/lib/brpm_auto.rb +11 -11
- data/lib/brpm_script_executor.rb +98 -93
- data/lib/logging/brpm_logger.rb +2 -2
- data/lib/module_installer.rb +16 -0
- data/tests/brpm_script_executor_spec.rb +1 -1
- data/tests/customer_include_spec.rb +1 -1
- data/tests/server_yaml_spec.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZGE3ODVjYmZiOTE3MzYwNTE0MjIwZWUzN2NkNDk5MGZlN2IwODE5YQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MDYzNWYwZjQyNjAzYzNhMDgxNmQ3ZDdmYzg3Y2Y3MzcwYjUwZTc5ZA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MzkxMDAyMDA4NGNmNTE0ZGY2ZjgyNTE5NDc3YjBjMDlkYmJiYzFhZWE3YjY5
|
10
|
+
ZTRkOGFhMjc1OGVlYzQ1ZWM5NDUyZTY0NzZiN2JmNjhiZmI1MjNhYWRkNWQ4
|
11
|
+
YWZkZDIyYzg2Mjg1YTU0NjYwZDRmZTBmNmNiZjIwMjNhYmRlNWQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OTRlZDMyNzk0Yjk0OTFmNzc0ZjhmOTk3M2Q1NmQwYzJiYWRjNGU2Y2NiYzc2
|
14
|
+
MmE4Njk4ZmM1ZDc3NTU3ZDg1M2VmYTdmMmY2YTMyMDE2NWJhNzI3Mzc1YzRl
|
15
|
+
NTliNWMwZDQyOWVjOGRkYTI1MzBmNDFiMWE0NDQyMmY5NmIxMzk=
|
data/config.yml
CHANGED
File without changes
|
@@ -2,7 +2,6 @@
|
|
2
2
|
USAGE="publish_module_version.sh <module name>"
|
3
3
|
|
4
4
|
MODULE_NAME=$1
|
5
|
-
MODULE_VERSION=$2
|
6
5
|
|
7
6
|
if [ -z "$MODULE_NAME" ]; then
|
8
7
|
echo "Module name is not specified. Aborting."
|
@@ -12,23 +11,29 @@ fi
|
|
12
11
|
|
13
12
|
cd $(dirname $0)/../../../$MODULE_NAME
|
14
13
|
|
14
|
+
echo ""
|
15
15
|
echo ">>> Publishing the module as a gem to rubygems.org..."
|
16
16
|
rake release
|
17
|
-
if [ -f "Dockerfile" ]; then
|
17
|
+
if [ -f "docker/Dockerfile" ]; then
|
18
18
|
MODULE_VERSION=$(eval "sed -n \"s=version: \(.*\)=\1=p\" config.yml")
|
19
19
|
|
20
|
+
cd docker
|
21
|
+
|
20
22
|
OLD_MODULE_VERSION=$(eval "sed -n \"s=ENV VERSION \(.*\)=\1=p\" Dockerfile")
|
21
23
|
sed -i "" s/$OLD_MODULE_VERSION/$MODULE_VERSION/ Dockerfile
|
22
24
|
|
25
|
+
echo ""
|
23
26
|
echo ">>> Building the docker image..."
|
24
|
-
docker build -t bmcrlm/$MODULE_NAME:$MODULE_VERSION .
|
27
|
+
docker build -t bmcrlm/$MODULE_NAME:$MODULE_VERSION . || { echo 'Aborting' ; exit 1; }
|
28
|
+
|
29
|
+
sed -i "" s/$MODULE_VERSION/$OLD_MODULE_VERSION/ Dockerfile
|
25
30
|
|
31
|
+
echo ""
|
26
32
|
echo ">>> Publishing the docker image to the docker hub..."
|
27
|
-
docker push bmcrlm/$MODULE_NAME:$MODULE_VERSION
|
33
|
+
docker push bmcrlm/$MODULE_NAME:$MODULE_VERSION || { echo 'Aborting' ; exit 1; }
|
28
34
|
|
35
|
+
echo ""
|
29
36
|
echo ">>> Tagging the module version as 'latest'..."
|
30
|
-
docker tag -f bmcrlm/$MODULE_NAME:$MODULE_VERSION bmcrlm/$MODULE_NAME:latest
|
31
|
-
docker push bmcrlm/$MODULE_NAME:latest
|
32
|
-
|
33
|
-
sed -i "" s/$MODULE_VERSION/$OLD_MODULE_VERSION/ Dockerfile
|
37
|
+
docker tag -f bmcrlm/$MODULE_NAME:$MODULE_VERSION bmcrlm/$MODULE_NAME:latest || { echo 'Aborting' ; exit 1; }
|
38
|
+
docker push bmcrlm/$MODULE_NAME:latest || { echo 'Aborting' ; exit 1; }
|
34
39
|
fi
|
File without changes
|
data/lib/brpm_auto.rb
CHANGED
@@ -25,6 +25,7 @@ class BrpmAuto
|
|
25
25
|
attr_reader :request_params
|
26
26
|
attr_reader :all_params
|
27
27
|
attr_reader :integration_settings
|
28
|
+
attr_reader :global_params
|
28
29
|
|
29
30
|
attr_reader :framework_root_path
|
30
31
|
|
@@ -42,8 +43,8 @@ class BrpmAuto
|
|
42
43
|
def setup(params = {})
|
43
44
|
@params = Params.new(params)
|
44
45
|
|
45
|
-
|
46
|
-
load_customer_include_file
|
46
|
+
@global_params = get_global_params
|
47
|
+
@global_params.merge!(load_customer_include_file)
|
47
48
|
|
48
49
|
if @params.run_from_brpm
|
49
50
|
@logger = BrpmLogger.new
|
@@ -78,27 +79,26 @@ class BrpmAuto
|
|
78
79
|
@params
|
79
80
|
end
|
80
81
|
|
81
|
-
def
|
82
|
+
def get_global_params
|
82
83
|
server_config_file_path = "#{self.params.config_dir}/server.yml"
|
83
84
|
if File.exists?(server_config_file_path)
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
end
|
85
|
+
YAML.load_file(server_config_file_path) || {}
|
86
|
+
else
|
87
|
+
{}
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
91
91
|
def load_customer_include_file
|
92
92
|
customer_include_file_path = "#{self.params.config_dir}/customer_include.rb"
|
93
|
+
params = {}
|
93
94
|
if File.exists?(customer_include_file_path)
|
94
95
|
load customer_include_file_path # use load instead of require to avoid having to restart BRPM after modifying the customer include file in a resource automation scenario
|
95
96
|
if defined?(get_customer_include_params)
|
96
|
-
|
97
|
-
customer_include_params.each do |key, value|
|
98
|
-
@params[key] = value
|
99
|
-
end
|
97
|
+
params = get_customer_include_params || {}
|
100
98
|
end
|
101
99
|
end
|
100
|
+
|
101
|
+
params
|
102
102
|
end
|
103
103
|
|
104
104
|
def initialize_logger(log_file, also_log_to_console = false)
|
data/lib/brpm_script_executor.rb
CHANGED
@@ -15,112 +15,117 @@ class BrpmScriptExecutor
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def execute_automation_script_in_separate_process_internal(modul, name, params, automation_type, parent_id = nil, offset = nil, max_records = nil)
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
18
|
+
begin
|
19
|
+
BrpmAuto.setup(params)
|
20
|
+
BrpmAuto.log ""
|
21
|
+
BrpmAuto.log "Executing #{automation_type} '#{name}' from module '#{modul}' in a separate process..."
|
22
|
+
|
23
|
+
BrpmAuto.log "Finding the module's version..."
|
24
|
+
case automation_type
|
25
|
+
when "automation"
|
26
|
+
module_version = params["module_version"] || get_latest_installed_version(modul)
|
27
|
+
when "resource_automation"
|
28
|
+
module_version = get_latest_installed_version(modul) #TODO: get the module version of the calling script
|
29
|
+
else
|
30
|
+
raise "Automation type #{automation_type} is not supported."
|
31
|
+
end
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
use_docker = true
|
35
|
-
when "if_docker_image_exists"
|
36
|
-
BrpmAuto.log "Checking if a docker image exists for bmcrlm/#{modul}:#{module_version}..."
|
37
|
-
output = `docker history -q bmcrlm/#{modul}:#{module_version} 2>&1 >/dev/null`
|
38
|
-
if output.empty?
|
33
|
+
case BrpmAuto.global_params["execute_automation_scripts_in_docker"] || params["execute_automation_scripts_in_docker"]
|
34
|
+
when "always"
|
39
35
|
use_docker = true
|
36
|
+
when "if_docker_image_exists"
|
37
|
+
BrpmAuto.log "Checking if a docker image exists for bmcrlm/#{modul}:#{module_version}..."
|
38
|
+
output = `docker history -q bmcrlm/#{modul}:#{module_version} 2>&1 >/dev/null`
|
39
|
+
use_docker = output.empty?
|
40
40
|
else
|
41
|
-
|
42
|
-
output = `docker pull bmcrlm/#{modul}:#{module_version}`
|
43
|
-
use_docker = (output =~ /Image is up to date for/)
|
41
|
+
use_docker = false
|
44
42
|
end
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
end
|
62
|
-
|
63
|
-
BrpmAuto.log "Temporarily storing the params to #{params_path}..."
|
64
|
-
File.open(params_path, "w") do |file|
|
65
|
-
file.puts(params.to_yaml)
|
66
|
-
end
|
67
|
-
|
68
|
-
if use_docker
|
69
|
-
BrpmAuto.log "Executing the script in a docker container..."
|
70
|
-
command = "docker run -v #{working_path}:/workdir -v #{automation_results_path}:/automation_results --rm bmcrlm/#{modul}:#{module_version} /docker_execute_automation \"#{name}\" \"/workdir/#{params_file}\" \"#{automation_type}\""
|
71
|
-
if automation_type == "resource_automation"
|
72
|
-
command += " \"#{parent_id}\"" if parent_id
|
73
|
-
command += " \"#{offset}\"" if offset
|
74
|
-
command += " \"#{max_records}\"" if max_records
|
43
|
+
BrpmAuto.log "The automation script will be executed in a docker container." if use_docker
|
44
|
+
|
45
|
+
working_path = File.expand_path(BrpmAuto.params.output_dir)
|
46
|
+
params_file = "params_#{params["SS_run_key"] || params["run_key"] || "000"}.yml"
|
47
|
+
params_path = "#{working_path}/#{params_file}"
|
48
|
+
automation_results_path = params["SS_automation_results_dir"] || working_path
|
49
|
+
script_support_path = params["SS_script_support_path"] || working_path
|
50
|
+
|
51
|
+
if use_docker
|
52
|
+
params = params.clone # we don't want to modify the current session's params
|
53
|
+
params["SS_output_dir"] = "/workdir"
|
54
|
+
params["SS_output_file"].sub!(working_path, "/workdir") if params["SS_output_file"]
|
55
|
+
params["SS_automation_results_dir"] = "/automation_results"
|
56
|
+
params["SS_script_support_path"] = "/script_support"
|
57
|
+
|
58
|
+
params["log_file"].sub!(working_path, "/workdir") if params["log_file"]
|
75
59
|
end
|
76
|
-
BrpmAuto.log command
|
77
|
-
return_value = system(command)
|
78
|
-
else
|
79
|
-
env_vars = {}
|
80
|
-
env_vars["GEM_HOME"] = ENV["BRPM_CONTENT_HOME"] || "#{ENV["BRPM_HOME"]}/modules"
|
81
60
|
|
82
|
-
|
61
|
+
BrpmAuto.log "Temporarily storing the params to #{params_path}..."
|
62
|
+
File.open(params_path, "w") do |file|
|
63
|
+
file.puts(params.to_yaml)
|
64
|
+
end
|
83
65
|
|
84
|
-
if
|
85
|
-
BrpmAuto.log "
|
66
|
+
if use_docker
|
67
|
+
BrpmAuto.log "Executing the script in a docker container..."
|
68
|
+
command = "docker run -v #{working_path}:/workdir -v #{automation_results_path}:/automation_results -v #{script_support_path}:/script_support --rm bmcrlm/#{modul}:#{module_version} /docker_execute_automation \"#{name}\" \"/workdir/#{params_file}\" \"#{automation_type}\""
|
69
|
+
if automation_type == "resource_automation"
|
70
|
+
command += " \"#{parent_id}\"" if parent_id
|
71
|
+
command += " \"#{offset}\"" if offset
|
72
|
+
command += " \"#{max_records}\"" if max_records
|
73
|
+
end
|
74
|
+
BrpmAuto.log command
|
75
|
+
return_value = system(command)
|
86
76
|
else
|
87
|
-
|
77
|
+
env_vars = {}
|
78
|
+
env_vars["GEM_HOME"] = ENV["BRPM_CONTENT_HOME"] || "#{ENV["BRPM_HOME"]}/modules"
|
79
|
+
|
80
|
+
module_path = get_module_gem_path(modul, module_version)
|
81
|
+
|
82
|
+
if File.exists?(module_path)
|
83
|
+
BrpmAuto.log "Found module #{modul} #{module_version || ""} in path #{module_path}."
|
84
|
+
else
|
85
|
+
raise Gem::GemNotFoundException, "Module #{modul} version #{module_version} is not installed. Expected it on path #{module_path}."
|
86
|
+
end
|
87
|
+
|
88
|
+
gemfile_path = "#{module_path}/Gemfile"
|
89
|
+
if File.exists?(gemfile_path)
|
90
|
+
BrpmAuto.log "Using Gemfile #{gemfile_path}."
|
91
|
+
env_vars["BUNDLE_GEMFILE"] = gemfile_path
|
92
|
+
require_bundler = "require 'bundler/setup';"
|
93
|
+
else
|
94
|
+
BrpmAuto.log("This module doesn't have a Gemfile.")
|
95
|
+
require_bundler = ""
|
96
|
+
end
|
97
|
+
|
98
|
+
BrpmAuto.log "Executing the script in a separate process..."
|
99
|
+
return_value = Bundler.clean_system(env_vars, "ruby", "-e", "#{require_bundler}require 'brpm_script_executor'; BrpmScriptExecutor.execute_automation_script_from_other_process(\"#{modul}\", \"#{name}\", \"#{params_path}\", \"#{automation_type}\", \"#{parent_id}\", \"#{offset}\", \"#{max_records}\")")
|
88
100
|
end
|
89
101
|
|
90
|
-
|
91
|
-
if
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
102
|
+
FileUtils.rm(params_path) if File.exists?(params_path)
|
103
|
+
if return_value.nil?
|
104
|
+
message = "The process that executed the automation script returned with 'Command execution failed'."
|
105
|
+
BrpmAuto.log_error message
|
106
|
+
raise message
|
107
|
+
elsif return_value == false
|
108
|
+
message = "The process that executed the automation script returned with non-zero exit code: #{$?.exitstatus}"
|
109
|
+
BrpmAuto.log_error message
|
110
|
+
raise message
|
98
111
|
end
|
99
112
|
|
100
|
-
|
101
|
-
|
102
|
-
|
113
|
+
if automation_type == "resource_automation"
|
114
|
+
result_path = params_path.sub!("params", "result")
|
115
|
+
BrpmAuto.log "Loading the result from #{result_path} and cleaning it up..."
|
116
|
+
result = YAML.load_file(result_path)
|
117
|
+
FileUtils.rm result_path
|
103
118
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
raise message
|
109
|
-
elsif return_value == false
|
110
|
-
message = "The process that executed the automation script returned with non-zero exit code: #{$?.exitstatus}"
|
111
|
-
BrpmAuto.log_error message
|
112
|
-
raise message
|
113
|
-
end
|
119
|
+
result
|
120
|
+
else
|
121
|
+
return_value
|
122
|
+
end
|
114
123
|
|
115
|
-
|
116
|
-
|
117
|
-
BrpmAuto.log "
|
118
|
-
result = YAML.load_file(result_file)
|
119
|
-
FileUtils.rm result_file
|
124
|
+
rescue Exception => e
|
125
|
+
BrpmAuto.log_error "#{e}"
|
126
|
+
BrpmAuto.log "\n\t" + e.backtrace.join("\n\t")
|
120
127
|
|
121
|
-
|
122
|
-
else
|
123
|
-
return_value
|
128
|
+
raise e
|
124
129
|
end
|
125
130
|
end
|
126
131
|
|
@@ -136,8 +141,8 @@ class BrpmScriptExecutor
|
|
136
141
|
BrpmAuto.log " BRPM Content framework is version #{BrpmAuto.version}."
|
137
142
|
|
138
143
|
if BrpmAuto.params["SS_run_key"] and BrpmAuto.params["SS_script_support_path"]
|
139
|
-
BrpmAuto.log "
|
140
|
-
load File.expand_path("#{File.dirname(__FILE__)}/../infrastructure/
|
144
|
+
BrpmAuto.log " Setting up the BRPM core framework..."
|
145
|
+
load File.expand_path("#{File.dirname(__FILE__)}/../infrastructure/setup_brpm_core_framework.rb")
|
141
146
|
end
|
142
147
|
|
143
148
|
result = execute_automation_script_internal(modul, name, params, automation_type, parent_id, offset, max_records)
|
data/lib/logging/brpm_logger.rb
CHANGED
@@ -26,6 +26,8 @@ class BrpmLogger < LoggerBase
|
|
26
26
|
|
27
27
|
log_message = "#{prefix}#{message}\n"
|
28
28
|
|
29
|
+
print(log_message) if BrpmAuto.params.also_log_to_console
|
30
|
+
|
29
31
|
File.open(@request_log_file_path, "a") do |log_file|
|
30
32
|
log_file.print(log_message)
|
31
33
|
end
|
@@ -33,7 +35,5 @@ class BrpmLogger < LoggerBase
|
|
33
35
|
File.open(@step_run_log_file_path, "a") do |log_file|
|
34
36
|
log_file.print(log_message)
|
35
37
|
end
|
36
|
-
|
37
|
-
print(log_message) if BrpmAuto.params.also_log_to_console
|
38
38
|
end
|
39
39
|
end
|
data/lib/module_installer.rb
CHANGED
@@ -13,6 +13,7 @@ class ModuleInstaller
|
|
13
13
|
brpm_content_spec = specs.find { |spec| spec.name == "brpm_content_framework" } if specs
|
14
14
|
|
15
15
|
install_bundle(module_spec)
|
16
|
+
pull_docker_image(module_spec)
|
16
17
|
else
|
17
18
|
module_name = module_name_or_path
|
18
19
|
module_spec = Gem::Specification.find_by_name(module_name)
|
@@ -166,6 +167,21 @@ class ModuleInstaller
|
|
166
167
|
end
|
167
168
|
end
|
168
169
|
|
170
|
+
def pull_docker_image(spec)
|
171
|
+
case BrpmAuto.global_params["execute_automation_scripts_in_docker"]
|
172
|
+
when "always", "if_docker_image_exists"
|
173
|
+
BrpmAuto.log "Pulling the docker image from the Docker Hub..."
|
174
|
+
output = `docker pull bmcrlm/#{spec.name}:#{spec.version}`
|
175
|
+
unless output =~ /Image is up to date for/
|
176
|
+
if BrpmAuto.global_params["execute_automation_scripts_in_docker"] == "always"
|
177
|
+
raise "Docker image bmcrlm/#{spec.name}:#{spec.version} doesn't exist."
|
178
|
+
elsif BrpmAuto.global_params["execute_automation_scripts_in_docker"] == "if_docker_image_exists"
|
179
|
+
BrpmAuto.log "Docker image bmcrlm/#{spec.name}:#{spec.version} doesn't exist."
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
169
185
|
def get_symlink_path
|
170
186
|
"#{ENV["GEM_HOME"]}/gems/brpm_content_framework-latest"
|
171
187
|
end
|
@@ -76,7 +76,7 @@ describe 'BRPM Script Executor' do
|
|
76
76
|
expect(result.count).to eql(3)
|
77
77
|
end
|
78
78
|
|
79
|
-
|
79
|
+
xit "should execute a resource automation script in a docker container" do
|
80
80
|
params = get_default_params
|
81
81
|
params['output_dir'] = File.expand_path("~/tmp/brpm_content") # docker volume mappong only works from the current user's home directory on Mac OSX
|
82
82
|
params["execute_automation_scripts_in_docker"] = "always"
|
data/tests/server_yaml_spec.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: brpm_content_framework
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.33
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Niek Bartholomeus
|
@@ -179,13 +179,12 @@ files:
|
|
179
179
|
- bin/event_handler
|
180
180
|
- bin/webhook_receiver
|
181
181
|
- config.yml
|
182
|
+
- docker/Dockerfile
|
183
|
+
- docker/docker_execute_automation
|
182
184
|
- infrastructure/.bashrc
|
183
185
|
- infrastructure/.brpm
|
184
186
|
- infrastructure/config/customer_include.rb
|
185
187
|
- infrastructure/config/server.yml
|
186
|
-
- infrastructure/create_output_file.rb
|
187
|
-
- infrastructure/docker/Dockerfile
|
188
|
-
- infrastructure/docker/docker_execute_automation
|
189
188
|
- infrastructure/log.html
|
190
189
|
- infrastructure/module_template/Dockerfile
|
191
190
|
- infrastructure/module_template/Gemfile
|
@@ -211,6 +210,7 @@ files:
|
|
211
210
|
- infrastructure/scripts/run_event_handler.sh
|
212
211
|
- infrastructure/scripts/run_webhook_receiver.cmd
|
213
212
|
- infrastructure/scripts/run_webhook_receiver.sh
|
213
|
+
- infrastructure/setup_brpm_core_framework.rb
|
214
214
|
- infrastructure/silent_install_options_4.6.txt
|
215
215
|
- infrastructure/silent_install_options_upgrade_4.6.txt
|
216
216
|
- infrastructure/smtp_settings.rb
|