Class: BuildSpecRunner::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/build_spec_runner/runner.rb

Overview

Module for running projects on a local docker container.

It is expected that you have a SourceProvider object that can yield a path containing a project suitable for AWS Codebuild. The project should have a buildspec file in its root directory. This module lets you use the default Ruby CodeBuild image or specify your own. See Runner.run and Runner.run_default.

Constant Summary collapse

DEFAULT_BUILD_SPEC_PATH =

The default path of the buildspec file in a project.

'buildspec.yml'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.run(image, source_provider, opts = {}) ⇒ Integer

Run a project on the specified image.

Run a project on the specified image, with the source pointed to by the specified source provider. If the buildspec filename is not buildspec.yml or is not located in the project root, specify the option :build_spec_path to choose a different relative path (including filename).



64
65
66
67
68
# File 'lib/build_spec_runner/runner.rb', line 64

def self.run image, source_provider, opts = {}
  runner = Runner.new image, source_provider, opts
  Runner.configure_docker
  runner.execute
end

.run_default(path, opts = {}) ⇒ Integer

Run the project at the specified directory on the default AWS CodeBuild Ruby 2.3.1 image.



34
35
36
37
38
39
40
# File 'lib/build_spec_runner/runner.rb', line 34

def self.run_default path, opts={}
  Runner.run(
    BuildSpecRunner::DefaultImages.build_image,
    BuildSpecRunner::SourceProvider::FolderSourceProvider.new(path),
    opts
  )
end

Instance Method Details

#executeObject

Run the project

Parse the build_spec, create the environment from the build_spec and any configured credentials, and build a container. Then execute the build spec’s commands on the container.

This method will close and remove any containers it creates.



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/build_spec_runner/runner.rb', line 77

def execute
  build_spec = Runner.make_build_spec(@source_provider, @build_spec_path)
  env = make_env(build_spec)

  container = nil
  begin
    container = Runner.make_container(@image, @source_provider, env)
    run_commands_on_container(container, build_spec)
  ensure
    unless container.nil?
      container.stop
      container.remove
    end
  end
end