Sha256: 8353959ccc3d9aab4e6524782394f62da2c120e80724c6789dd4582448a2484f

Contents?: true

Size: 1.53 KB

Versions: 1

Compression:

Stored size: 1.53 KB

Contents

module Percheron
  module Container
    module Actions
      class Build

        include Base

        def initialize(container, nocache: false)
          @container = container
          @nocache = nocache
        end

        def execute!
          build!
        end

        private

          attr_reader :container, :nocache

          def build_opts
            {
              'dockerfile'  => container.dockerfile.basename.to_s,
              't'           => container.image_name,
              'forcerm'     => true,
              'nocache'     => nocache
            }
          end

          def build!
            in_working_directory(base_dir) do
              execute_pre_build_scripts!

              $logger.debug "Building '#{container.image_name}'"
              Docker::Image.build_from_dir(base_dir, build_opts) do |out|
                $logger.debug '%s' % [ out.strip ]
              end
            end
          end

          def execute_pre_build_scripts!
            container.pre_build_scripts.each do |script|
              in_working_directory(base_dir) do
                command = '/bin/bash -x %s 2>&1' % Pathname.new(File.expand_path(script))
                $logger.debug "Executing PRE build '#{command}' for '#{container.name}' container"
                Open3.popen2e(command) do |stdin, stdout_err, wait_thr|
                  while line = stdout_err.gets
                    $logger.debug line.strip
                  end
                end
              end
            end
          end

      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
percheron-0.5.0 lib/percheron/container/actions/build.rb