From 1f286adddedd6b82effa6b5cf05fe335333ad603 Mon Sep 17 00:00:00 2001 From: william Date: Thu, 13 Sep 2018 17:35:40 +0100 Subject: [PATCH 1/6] Add a super into the start and complete hooks This allows the default behaviour to be defined in `BuildMethod` class. However allows alternative methods to redefine this completely. --- src/build_methods/kickstarts/kickstart.rb | 2 ++ src/build_methods/local.rb | 1 + 2 files changed, 3 insertions(+) diff --git a/src/build_methods/kickstarts/kickstart.rb b/src/build_methods/kickstarts/kickstart.rb index d9467934..60e4c498 100644 --- a/src/build_methods/kickstarts/kickstart.rb +++ b/src/build_methods/kickstarts/kickstart.rb @@ -8,10 +8,12 @@ module BuildMethods module Kickstarts class Kickstart < BuildMethod def start_hook + super render_pxelinux(firstboot: true) end def complete_hook + super render_pxelinux(firstboot: false) end diff --git a/src/build_methods/local.rb b/src/build_methods/local.rb index 38d434b3..7953e9b1 100644 --- a/src/build_methods/local.rb +++ b/src/build_methods/local.rb @@ -8,6 +8,7 @@ module Metalware module BuildMethods class Local < BuildMethod def start_hook + super rendered_local_template = file_path.template_save_path(:local, node: node) FileUtils.chmod 'u+x', rendered_local_template From 19abc02c66b606f92d96339241d3c60b3e04ee41 Mon Sep 17 00:00:00 2001 From: william Date: Thu, 13 Sep 2018 17:51:24 +0100 Subject: [PATCH 2/6] Create the build_hooks directory on install This directory will contain files that will be rendered and ran on each build --- scripts/install | 1 + src/file_path.rb | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/scripts/install b/scripts/install index bb7b8142..4f8fe05e 100644 --- a/scripts/install +++ b/scripts/install @@ -84,6 +84,7 @@ mkdir -p /var/lib/metalware/repo mkdir -p /var/lib/metalware/plugins mkdir -p /var/lib/metalware/answers/{groups,nodes} mkdir -p /var/lib/metalware/assets +mkdir -p /var/lib/metalware/build_hooks mkdir -p /etc/named touch /etc/named/metalware.conf chmod a+rw /var/lib/metalware/events diff --git a/src/file_path.rb b/src/file_path.rb index d6569324..a16d78c8 100644 --- a/src/file_path.rb +++ b/src/file_path.rb @@ -176,6 +176,10 @@ def cached_template(name) File.join(cache, 'templates', name) end + def build_hooks + File.join(metalware_data, 'build_hooks') + end + private def record(record_dir, types_dir, name) From 15a4157ef7a335f1cfbc8af0d00f3c2cec2c8da0 Mon Sep 17 00:00:00 2001 From: william Date: Fri, 14 Sep 2018 10:37:01 +0100 Subject: [PATCH 3/6] Glob the `build_hooks` directory for the files These will be rendered at some point --- src/build_methods/build_method.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/build_methods/build_method.rb b/src/build_methods/build_method.rb index 41ac534c..88a03f23 100644 --- a/src/build_methods/build_method.rb +++ b/src/build_methods/build_method.rb @@ -18,7 +18,11 @@ def render_staging_templates(templater) end def start_hook - # Runs at the start of the build process + # Renders the build hook scripts and runs them + regex = File.join(FilePath.build_hooks, '*') + Dir.glob(regex).each do |file| + puts file + end end def complete_hook From de64dbc0d9f1b9ac75806405f4c28f3f50baf595 Mon Sep 17 00:00:00 2001 From: william Date: Fri, 14 Sep 2018 10:49:42 +0100 Subject: [PATCH 4/6] Render the files content It can be assumed all the build_hook scripts are templates --- src/build_methods/build_method.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/build_methods/build_method.rb b/src/build_methods/build_method.rb index 88a03f23..52beb7d5 100644 --- a/src/build_methods/build_method.rb +++ b/src/build_methods/build_method.rb @@ -20,8 +20,9 @@ def render_staging_templates(templater) def start_hook # Renders the build hook scripts and runs them regex = File.join(FilePath.build_hooks, '*') - Dir.glob(regex).each do |file| - puts file + Dir.glob(regex).each do |src| + rendered_content = Templater.render(node, src) + puts rendered_content end end From 1740f04772f8541e84478d71b76ca91fd2998e70 Mon Sep 17 00:00:00 2001 From: william Date: Fri, 14 Sep 2018 10:54:31 +0100 Subject: [PATCH 5/6] Run the rendered script through bash The rendered content needs to be written to a temporary file before being ran --- src/build_methods/build_method.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/build_methods/build_method.rb b/src/build_methods/build_method.rb index 52beb7d5..f7f7efa3 100644 --- a/src/build_methods/build_method.rb +++ b/src/build_methods/build_method.rb @@ -22,7 +22,11 @@ def start_hook regex = File.join(FilePath.build_hooks, '*') Dir.glob(regex).each do |src| rendered_content = Templater.render(node, src) - puts rendered_content + temp_file = Tempfile.new("#{node.name}-#{File.basename(src)}") + temp_file.write rendered_content + temp_file.close + puts SystemCommand.run("bash #{temp_file.path}") + temp_file.unlink end end From 03b7f144b66562e277d63a9264d077652bd1f7e4 Mon Sep 17 00:00:00 2001 From: william Date: Fri, 14 Sep 2018 10:58:52 +0100 Subject: [PATCH 6/6] Update the bootstrap gem to remove security threat --- Gemfile | 2 +- Gemfile.lock | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Gemfile b/Gemfile index 0a5f6d28..ffe2ac22 100644 --- a/Gemfile +++ b/Gemfile @@ -38,7 +38,7 @@ group :development do end # Gems added for GUI app. -gem 'bootstrap', '~> 4.0.0.beta' +gem 'bootstrap' gem 'concurrent-ruby', require: 'concurrent' gem 'jquery-rails' # Required for Bootstrap. diff --git a/Gemfile.lock b/Gemfile.lock index 6b6deb77..ce2a5cb6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -60,10 +60,10 @@ GEM tzinfo (~> 1.1) arel (8.0.0) ast (2.4.0) - autoprefixer-rails (8.2.0) + autoprefixer-rails (9.1.4) execjs bindex (0.5.0) - bootstrap (4.0.0) + bootstrap (4.1.3) autoprefixer-rails (>= 6.0.3) popper_js (>= 1.12.9, < 2) sass (>= 3.5.2) @@ -105,7 +105,7 @@ GEM erubi (1.7.1) execjs (2.7.0) fakefs (0.13.3) - ffi (1.9.23) + ffi (1.9.25) globalid (0.4.1) activesupport (>= 4.2.0) hashie (3.5.7) @@ -144,7 +144,7 @@ GEM parallel (1.12.1) parser (2.5.1.0) ast (~> 2.4.0) - popper_js (1.12.9) + popper_js (1.14.3) powerpack (0.1.1) pry (0.11.3) coderay (~> 1.1.0) @@ -210,7 +210,7 @@ GEM ruby-progressbar (1.9.0) ruby_dep (1.5.0) rugged (0.27.0) - sass (3.5.6) + sass (3.5.7) sass-listen (~> 4.0.0) sass-listen (4.0.0) rb-fsevent (~> 0.9, >= 0.9.4) @@ -267,7 +267,7 @@ PLATFORMS ruby DEPENDENCIES - bootstrap (~> 4.0.0.beta) + bootstrap byebug colorize commander! @@ -308,4 +308,4 @@ RUBY VERSION ruby 2.4.1p111 BUNDLED WITH - 1.16.1 + 1.16.4