class Docker::Template::CLI::Build

Public Class Methods

new(args, opts) click to toggle source
# File lib/docker/template/cli/build.rb, line 9
def initialize(args, opts)
  @opts = Meta.new(opts || {})
  @repos = Parser.new(args, opts || {}).parse
  @args = args
end

Public Instance Methods

changed!() click to toggle source

– rubocop:disable Metrics/AbcSize –

# File lib/docker/template/cli/build.rb, line 41
def changed!
  Template._require "rugged" do |loaded|
    return true unless loaded

    git = Rugged::Repository.new(Template.root.to_s)
    dir = Template.root.join(@opts.repos_dir)

    repos = git.last_commit.diff.each_delta.each_with_object(Set.new) do |delta, set|
      next unless Pathutil.new(delta.new_file[:path]).expand_path(Template.root).in_path?(dir)
      set.merge(delta.new_file[:path].split("/").values_at(
        1
      ))
    end

    @repos = @repos.select do |repo|
      repos.include?(
        repo.name
      )
    end
  end
end
exclude!() click to toggle source

# File lib/docker/template/cli/build.rb, line 29
def exclude!
  Parser.new(@opts[:exclude].map { |v| v.split(/,\s*/) }.flatten.compact).parse.each do |repo|
    @repos.delete_if do |v|
      v.name == repo.name && v.tag == repo.tag
    end
  end
end
start() click to toggle source

# File lib/docker/template/cli/build.rb, line 17
def start
  _profile do
    changed! if @opts.diff?
    exclude! if @opts.exclude?
    @repos.tap { |o| o.map(&:build) }.uniq(&:name).map(
      &:clean
    )
  end
end

Private Instance Methods

_profile() { || ... } click to toggle source

– rubocop:enable Metrics/AbcSize –

# File lib/docker/template/cli/build.rb, line 68
def _profile
  return yield unless @opts.profile?
  Template._require "memory_profiler" do
    profiler = MemoryProfiler.report(:top => 10_240) { yield }
    profiler.pretty_print({
      :to_file => "profile.txt"
    })
  end
end