Skip to content

Commit

Permalink
Bug fix if image has no created_by key
Browse files Browse the repository at this point in the history
Currently, if you run Tern on a squashed Docker image, Tern fails to
execute because there is no created_by key to assign as the instruction.
This because the Docker squash feature removes the created_by key. This
error would also be seen on non-squashed images that for whatever reason
don't have a created_by key associated with a certain layer.

This commit makes a change in the get_commands_from_history() function
to set the instruction line as a blank string if no created_by key is
available.

Resolves #636

Signed-off-by: Rose Judge <[email protected]>
  • Loading branch information
rnjudge authored and Nisha K committed May 13, 2020
1 parent 59a6b60 commit 161c512
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion tern/analyze/docker/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,12 @@ def get_commands_from_history(image_layer):
image_layer.origins.add_notice_to_origins(origin_layer, Notice(
formats.dockerfile_line.format(dockerfile_instruction=instruction),
'info'))
command_line = instruction.split(' ', 1)[1]
else:
instruction = ''
image_layer.origins.add_notice_to_origins(origin_layer, Notice(
formats.no_created_by, 'warning'))
command_line = instruction.split(' ', 1)[1]
command_line = instruction
# Image layers are created with the directives RUN, ADD and COPY
# For ADD and COPY instructions, there is no information about the
# packages added
Expand Down

0 comments on commit 161c512

Please sign in to comment.