def print_dockerfile_base(): '''For the purpose of tracking the lines in the dockerfile that produce packages, return a string containing the lines in the dockerfile that pertain to the base image''' base_instr = '' for instr in df.get_base_instructions(docker_commands): base_instr = base_instr + instr[0] + ' ' + instr[1] + '\n' return base_instr
def get_dockerfile_base(): '''Check if the dockerfile's FROM has the 'latest' tag and if so report a message''' base_image_tag = df.get_base_image_tag( df.get_base_instructions(docker_commands)) if base_image_tag[1] == 'latest': new_image_tag = (base_image_tag[0], cmds.get_latest_tag(base_image_tag[0])) return (new_image_tag, dockerfile_using_latest) else: return (base_image_tag, '')
def get_dockerfile_base(): '''Get the base image object from the dockerfile base instructions 1. get the instructions around FROM 2. get the base image and tag 3. Make notes based on what the image and tag rules are 4. Return an image object and the base instructions string''' try: base_instructions = dockerfile.get_base_instructions(docker_commands) base_image_tag = dockerfile.get_base_image_tag(base_instructions) dockerfile_lines = print_dockerfile_base(base_instructions) # check for scratch if base_image_tag[0] == 'scratch': # there is no base image - return no image object return None # there should be some image object here repotag = base_image_tag[0] + dockerfile.tag_separator + \ base_image_tag[1] from_line = 'FROM ' + repotag base_image = DockerImage(repotag) base_image.origins.add_notice_origin(dockerfile_lines) base_image.name = base_image_tag[0] # check if there is a tag if not base_image_tag[1]: message_string = errors.dockerfile_no_tag.format( dockerfile_line=from_line) base_image.origins.add_notice_to_origins( dockerfile_lines, Notice(message_string, 'warning')) base_image.tag = 'latest' else: base_image.tag = base_image_tag[1] # check if the tag is 'latest' if base_image_tag[1] == 'latest': message_string = errors.dockerfile_using_latest.format( dockerfile_line=from_line) base_image.origins.add_notice_to_origins( dockerfile_lines, Notice(message_string, 'warning')) return base_image, dockerfile_lines except ValueError as e: logger.warning( errors.cannot_parse_base_image.format(dockerfile=dockerfile_global, error_msg=e)) return None