Class: Serialbench::Runners::DockerRunner

Inherits:
Base
  • Object
show all
Defined in:
lib/serialbench/runners/docker_runner.rb

Overview

Handles Docker-based benchmark execution

Defined Under Namespace

Classes: DockerError

Instance Method Summary collapse

Methods inherited from Base

#benchmark

Constructor Details

#initialize(environment_config, environment_config_path) ⇒ DockerRunner

Returns a new instance of DockerRunner.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/serialbench/runners/docker_runner.rb', line 14

def initialize(environment_config, environment_config_path)
  super

  @docker_image = @environment_config.docker&.image
  raise 'docker.image is required' unless @docker_image

  # Handle dockerfile path relative to environment file
  dockerfile_path = @environment_config.docker&.dockerfile
  raise 'docker.dockerfile path is required' unless dockerfile_path

  @dockerfile = Pathname.new(environment_config_path).dirname.join(dockerfile_path).to_s
  raise "path '#{@dockerfile}' specified in docker.dockerfile is not found" unless File.exist?(@dockerfile)

  validate_docker_available
end

Instance Method Details

#base_image_stringObject



54
55
56
# File 'lib/serialbench/runners/docker_runner.rb', line 54

def base_image_string
  @environment_config.docker.image
end

#docker_image_stringObject



58
59
60
# File 'lib/serialbench/runners/docker_runner.rb', line 58

def docker_image_string
  "serialbench:#{@environment_config.ruby_build_tag}"
end

#prepareObject

Build Docker image for this environment

Raises:



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/serialbench/runners/docker_runner.rb', line 31

def prepare
  puts "🐳 Preparing Docker image for #{@name}..."

  puts "   🐍 Using Docker image: #{base_image_string}"
  puts "   🔨 Building Docker image: #{docker_image_string}"

  cmd = [
    'docker', 'build',
    '--build-arg', "BASE_IMAGE=#{base_image_string}",
    '-t', docker_image_string,
    '-f', @dockerfile,
    '.'
  ]

  # Show command being run
  puts "   🔧 Running command: #{cmd.join(' ')}"
  success = system(*cmd)

  raise DockerError, "Failed to build Docker image '#{docker_image_string}'" unless success

  puts "✅ Docker image prepared successfully for #{docker_image_string}"
end

#run_benchmark(benchmark_config, benchmark_config_path, result_dir) ⇒ Object

Run benchmark for this environment



63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/serialbench/runners/docker_runner.rb', line 63

def run_benchmark(benchmark_config, benchmark_config_path, result_dir)
  puts "🚀 Running benchmark at #{@environment_config_path}..."

  FileUtils.mkdir_p(result_dir)

  # Build image if not already built
  prepare unless image_exists?

  # Run the benchmark
  run_benchmark_in_container(benchmark_config, benchmark_config_path, result_dir)

  puts "✅ Benchmark completed for #{@environment_config_path}"
end