Skip to content

Commit

Permalink
Analyze multistage dockerfile
Browse files Browse the repository at this point in the history
Add function execute_multistage_dockerfile(args) in
tern\analyze\docker\run.py. This function iterate the stages in the
multistage dockerfile and use execute_dockerfile() for each stage.

Works towards tern-tools#612.

Signed-off-by: WangJL <hazard15020@gmail.com>
  • Loading branch information
ForgetMe17 committed Sep 13, 2020
1 parent 888fb74 commit 60665a4
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tern/analyze/docker/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"""

import logging
import copy
import os

from tern.report import formats
from tern.report import report
Expand Down Expand Up @@ -181,3 +183,20 @@ def execute_dockerfile(args): # noqa C901,R0912
if args.name == 'report':
if not args.keep_wd:
report.clean_working_dir()


def execute_multistage_dockerfile(args):
"""Split the multistage dockerfile, and then analzye on each stage."""
dfobj_multi = dockerfile.get_dockerfile_obj(args.dockerfile)
# split the multistage dockerfile
file_path_list = dockerfile.get_multistage_image_dockerfiles(dfobj_multi)
report_folder_path = os.path.join(os.path.dirname(dfobj_multi.filepath),
'report')
temp_arg = copy.copy(args)
for idx, dfile in enumerate(file_path_list):
temp_arg.dockerfile = dfile
if args.output_file:
temp_arg.output_file = args.output_file + "%d" % idx
else:
temp_arg.output_file = report_folder_path + "%d" % idx
execute_dockerfile(args)

0 comments on commit 60665a4

Please sign in to comment.