Class: Dash::Dockerfile::Rules::AptHygiene

Inherits:
Base
  • Object
show all
Defined in:
lib/dash/dockerfile/rules/apt_hygiene.rb

Overview

apt's recommended packages and its package lists both ship in the layer unless the same RUN gets rid of them. Only worth saying about a stage that ends up in the image.

Constant Summary collapse

NO_RECOMMENDS =
/--no-install-recommends/
LIST_CLEANUP =
%r{rm\s+-rf\s+/var/lib/apt/lists}
APT_OPERATION =
/\bapt-get\s+#{Dash::Dockerfile::Context::APT_OPTIONS.source}(?:update|install|upgrade)\b/
SEGMENT =

One shell command at a time: a later, compliant install must not vouch for an earlier one, and a cleanup only counts after the last thing that refilled the lists. A heredoc body keeps its line breaks, so each of its lines is a command too.

/&&|\|\||;|\n/
SUGGESTION =
"add --no-install-recommends to every install and rm -rf /var/lib/apt/lists/* at the end of the same RUN"

Instance Method Summary collapse

Instance Method Details

#findings ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/dash/dockerfile/rules/apt_hygiene.rb', line 13

def findings
  document.shipped_stages.flat_map { |stage| stage.instructions }.filter_map do |instruction|
    next unless context.apt_install?(instruction)

    problems = problems_in(instruction.shell_command.split(SEGMENT))
    next if problems.empty?

    note at(instruction), "apt-get install #{problems.join(" and ")}", SUGGESTION
  end
end