Class: Dockerspec::Builder

Inherits:
Object
  • Object
show all
Includes:
ConfigHelpers, Helper::CI, Helper::MultipleSourcesDescription
Defined in:
lib/dockerspec/builder.rb,
lib/dockerspec/builder/logger.rb,
lib/dockerspec/builder/image_gc.rb,
lib/dockerspec/builder/matchers.rb,
lib/dockerspec/builder/logger/ci.rb,
lib/dockerspec/builder/logger/info.rb,
lib/dockerspec/builder/logger/debug.rb,
lib/dockerspec/builder/logger/silent.rb,
lib/dockerspec/builder/config_helpers.rb,
lib/dockerspec/builder/matchers/helpers.rb

Overview

A class to build a container image.

Defined Under Namespace

Modules: ConfigHelpers, Matchers Classes: ImageGC, Logger

Instance Method Summary collapse

Methods included from Helper::MultipleSourcesDescription

#description

Methods included from Helper::CI

#ci?, #circle_ci?, #travis_ci?

Methods included from ConfigHelpers

#architecture, #cmd, #entrypoint, #envs, #expose, #exposes, #image_config, #label, #labels, #maintainer, #onbuild, #onbuilds, #os, #size, #stopsignal, #user, #volume, #volumes, #workdir

Constructor Details

#initialize(*opts) ⇒ Builder

Constructs a Docker image builder class.

Examples:

Build an Image From CWD or DOCKERFILE_PATH

Dockerspec::Builder.new #=> #<Dockerspec::Builder:0x0123>

Build an Image from a Directory

Dockerspec::Builder.new('imagedir') #=> #<Dockerspec::Builder:0x0124>

Do Not Remove the Image

Dockerspec::Builder.new('../', rm: false)
  #=> #<Dockerspec::Builder:0x0125>

Passing Multiple Params

Dockerspec::Builder.new(path: '../', tag: 'myapp', rm: false)
  #=> #<Dockerspec::Builder:0x0125>

Parameters:

  • opts (String, Hash)

    The :path or a list of options.

Options Hash (*opts):

  • :path (String) — default: '.'

    The directory or file that contains the Dockerfile. By default tries to read it from the DOCKERFILE_PATH environment variable and uses '.' if it is not set.

  • :string (String)

    Use this string as Dockerfile instead of :path. Not set by default.

  • :string_build_path (String)

    Used to specify the path that is used for the docker build of a string Dockerfile. This enables ADD statements in the Dockerfile to access files that are outside of . Not set by default and overrides the default '.'

  • :template (String)

    Use this Erubis template file as Dockerfile.

  • :id (String)

    Use this Docker image ID instead of a Dockerfile.

  • :rm (Boolean)

    Whether to remove the generated docker images after running the tests. By default only removes them if it is running on a CI machine.

  • :context (Hash, Erubis::Context) — default: {}

    Template context used when the :template source is used.

  • :tag (String)

    Repository tag to be applied to the resulting image.

  • :log_level (Integer, Symbol)

    Sets the docker library verbosity level. Possible values: :silent or 0 (no output), :ci or 1 (enables some outputs recommended for CI environments), :info or 2 (gives information about main build steps), :debug or 3 (outputs all the provided information in its raw original form).

See Also:



95
96
97
98
# File 'lib/dockerspec/builder.rb', line 95

def initialize(*opts)
  @image = nil
  @options = parse_options(opts)
end

Instance Method Details

#buildString

Builds the docker image.

Examples:

Build an Image From a Path

d = Dockerspec::Builder.new(path: 'dockerfile_dir')
d.build #=> #<Dockerspec::Builder:0x0125>

Returns:

  • (String)

    Docker image ID.

Raises:



129
130
131
132
# File 'lib/dockerspec/builder.rb', line 129

def build
  send("build_from_#{source}", @options[source])
  self
end

#idString

Returns Docker image ID.

Examples:

Get the Image ID After Building the Image

d = Dockerspec::Builder.new
d.build
d.id #=> "9f8866b49bfb[...]"

Returns:

  • (String)

    Docker image ID.



112
113
114
# File 'lib/dockerspec/builder.rb', line 112

def id
  @image.id
end

#to_sString

Gets a descriptions of the object.

Examples:

d = Dockerspec::Builder.new('.')
d.to_s #=> "Docker Build from path: ."

Returns:

  • (String)

    The object description.



145
146
147
# File 'lib/dockerspec/builder.rb', line 145

def to_s
  description('Docker Build from')
end