Sha256: fcb66387352cef6b430652d791c17b09ce8b74f48d4c0659a18157bc5bd23dec

Contents?: true

Size: 1.43 KB

Versions: 23

Compression:

Stored size: 1.43 KB

Contents

class KuberKit::Actions::ImageCompiler
  include KuberKit::Import[
    "image_compiler.image_dependency_resolver",
    "image_compiler.build_server_pool_factory",
    "shell.local_shell",
    "tools.logger",
    "ui",
    image_compiler: "image_compiler.action_handler",
  ]

  Contract ArrayOf[Symbol], Hash => Any
  def call(image_names, options)
    build_id = generate_build_id
    build_server_pool = build_server_pool_factory.create()

    image_dependency_resolver.each_with_deps(image_names) do |dep_image_names|
      result = compile_simultaneously(dep_image_names, build_id, build_server_pool)
      abort unless result
    end

    build_server_pool.disconnect_all

    true
  rescue KuberKit::Error => e
    ui.print_error("Error", e.message)

    false
  end

  private
    def compile_simultaneously(image_names, build_id, build_server_pool)
      task_group = ui.create_task_group
      image_names.map do |image_name|

        logger.info("Started compiling: #{image_name.to_s.green}")
        task_group.add("Compiling #{image_name.to_s.yellow}") do |task|
          shell = build_server_pool.get_shell
          
          image_compiler.call(shell, image_name, build_id)

          task.update_title("Compiled #{image_name.to_s.green}")
          logger.info("Finished compiling: #{image_name.to_s.green}")
        end
        
      end
      task_group.wait
    end

    def generate_build_id
      Time.now.strftime("%H%M%S")
    end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
kuber_kit-0.3.11 lib/kuber_kit/actions/image_compiler.rb
kuber_kit-0.3.10 lib/kuber_kit/actions/image_compiler.rb
kuber_kit-0.3.9 lib/kuber_kit/actions/image_compiler.rb
kuber_kit-0.3.8 lib/kuber_kit/actions/image_compiler.rb
kuber_kit-0.3.7 lib/kuber_kit/actions/image_compiler.rb
kuber_kit-0.3.6 lib/kuber_kit/actions/image_compiler.rb
kuber_kit-0.3.5 lib/kuber_kit/actions/image_compiler.rb
kuber_kit-0.3.4 lib/kuber_kit/actions/image_compiler.rb
kuber_kit-0.3.3 lib/kuber_kit/actions/image_compiler.rb
kuber_kit-0.3.2 lib/kuber_kit/actions/image_compiler.rb
kuber_kit-0.3.1 lib/kuber_kit/actions/image_compiler.rb
kuber_kit-0.3.0 lib/kuber_kit/actions/image_compiler.rb
kuber_kit-0.2.9 lib/kuber_kit/actions/image_compiler.rb
kuber_kit-0.2.8 lib/kuber_kit/actions/image_compiler.rb
kuber_kit-0.2.7 lib/kuber_kit/actions/image_compiler.rb
kuber_kit-0.2.6 lib/kuber_kit/actions/image_compiler.rb
kuber_kit-0.2.5 lib/kuber_kit/actions/image_compiler.rb
kuber_kit-0.2.4 lib/kuber_kit/actions/image_compiler.rb
kuber_kit-0.2.3 lib/kuber_kit/actions/image_compiler.rb
kuber_kit-0.2.2 lib/kuber_kit/actions/image_compiler.rb