class Replr::Stack::REPLMaker
Abstract class to do many things common when creating a REPL across stacks
Attributes
bootstrap_file_name[R]
filter_matching_lines_for_install[R]
filter_not_matching_lines_for_install[R]
libraries[R]
library_file_name[R]
process_runner[R]
stack[R]
template_dir[R]
work_dir[R]
Public Class Methods
load(stack:, libraries:)
click to toggle source
# File lib/replr/stack/repl_maker.rb, line 15 def self.load(stack:, libraries:) stack_name, _stack_version = stack.split(':') require_relative "#{stack_name}/repl_maker" repl_maker_class_name = "Replr::Stack::#{stack_name.capitalize}::REPLMaker" repl_maker = Object.const_get(repl_maker_class_name).new( stack: stack, libraries: libraries ) repl_maker.create end
new(stack:, libraries:)
click to toggle source
# File lib/replr/stack/repl_maker.rb, line 27 def initialize(stack:, libraries:) @process_runner = Replr::ProcessRunner.new @stack = stack @libraries = libraries @work_dir = Dir.mktmpdir end
Public Instance Methods
create()
click to toggle source
# File lib/replr/stack/repl_maker.rb, line 35 def create set_template_dir set_library_file_name set_bootstrap_file_name set_filter_lines_for_install copy_library_file copy_initialization_files initialize_docker_repl end
Private Instance Methods
copy_initialization_files()
click to toggle source
# File lib/replr/stack/repl_maker.rb, line 75 def copy_initialization_files create_docker_file if bootstrap_file_name bootstrap_file = File.join(template_dir, bootstrap_file_name) FileUtils.cp(bootstrap_file, work_dir) end end
copy_library_file()
click to toggle source
# File lib/replr/stack/repl_maker.rb, line 67 def copy_library_file Dir.chdir(work_dir) do File.open(library_file_name, 'w') do |f| f.write(library_file_with(libraries)) end end end
create_docker_file()
click to toggle source
# File lib/replr/stack/repl_maker.rb, line 83 def create_docker_file _stack, version = stack.split(':') docker_file_template = File.join(template_dir, "Dockerfile.template") docker_file_contents = File.read(docker_file_template) docker_file_contents.gsub!('%%VERSION%%', version ? "#{version}-" : '') File.open(File.join(work_dir, 'Dockerfile'), 'w') do |file| file.puts docker_file_contents end end
docker_image_tag()
click to toggle source
# File lib/replr/stack/repl_maker.rb, line 107 def docker_image_tag normalized_library_string = libraries.map do |library| library.gsub(':', '-v') end.join('-') normalized_stack_string = stack.gsub(':', '-v') if normalized_library_string.empty? "replr/#{normalized_stack_string}" else "replr/#{normalized_stack_string}-#{normalized_library_string}" end end
initialize_docker_repl()
click to toggle source
# File lib/replr/stack/repl_maker.rb, line 93 def initialize_docker_repl Dir.chdir(work_dir) do build_command = "docker build -t #{docker_image_tag} ." run_command = "docker run --rm -it #{docker_image_tag}" matching = Regexp.union([/upgrading/i, /installing/i] + filter_matching_lines_for_install) not_matching = Regexp.union([/step/i] + filter_not_matching_lines_for_install) process_runner.execute_filtered_process(build_command, matching, not_matching) do |stderr, process_thread| process_runner.execute_command_if_not_stderr(run_command, stderr, process_thread) end end end
library_file_with(libraries)
click to toggle source
# File lib/replr/stack/repl_maker.rb, line 63 def library_file_with(libraries) raise NotImplementedError, 'This needs to be implemented by a subclass' end
set_bootstrap_file_name()
click to toggle source
It's optional to set a bootstrap file
# File lib/replr/stack/repl_maker.rb, line 57 def set_bootstrap_file_name; end
set_filter_lines_for_install()
click to toggle source
# File lib/replr/stack/repl_maker.rb, line 59 def set_filter_lines_for_install raise NotImplementedError, 'This needs to be implemented by a subclass' end
set_library_file_name()
click to toggle source
# File lib/replr/stack/repl_maker.rb, line 52 def set_library_file_name raise NotImplementedError, 'This needs to be implemented by a subclass' end
set_template_dir()
click to toggle source
# File lib/replr/stack/repl_maker.rb, line 48 def set_template_dir raise NotImplementedError, 'This needs to be implemented by a subclass' end