Class: Dash::Dockerfile::Rules::InlineEnvBlob

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

Overview

A wall of inline assignments in front of a command means editing any one value invalidates the layer — and makes the instruction unreadable in the bargain.

Constant Summary collapse

ASSIGNMENT =
/\A[A-Za-z_]\w*=(?:"[^"]*"|'[^']*'|\\.|\S)*\s+/
THRESHOLD =
20
SUGGESTION =
"read them from an env file at runtime, or set the build-time ones in one ENV block, so the command line stops changing"

Instance Method Summary collapse

Instance Method Details

#findings ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/dash/dockerfile/rules/inline_env_blob.rb', line 8

def findings
  document.instructions.filter_map do |instruction|
    next unless instruction.name == "RUN"
    next unless (count = leading_assignments(instruction.shell_command.dup)) > THRESHOLD

    note at(instruction), "#{count} inline environment assignments precede the command", SUGGESTION
  end
end