How to use the tern.utils.rootfs function in tern

To help you get started, we’ve selected a few tern examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vmware / tern / tern / report / report.py View on Github external
# load dockerfile if present
    if dockerfile:
        dhelper.load_docker_commands(dockerfile)
    # check if the docker image is present
    if image_tag_string:
        if not container.check_image(image_tag_string):
            # if no docker image is present, try to pull it
            if not container.pull_image(image_tag_string):
                logger.fatal("%s", errors.cannot_find_image.format(
                    imagetag=image_tag_string))
                sys.exit()
    # create temporary working directory
    if not os.path.exists(constants.temp_folder):
        os.mkdir(constants.temp_folder)
    # set up folders for rootfs operations
    rootfs.set_up()
github vmware / tern / tern / report / report.py View on Github external
def clean_image_tars(image_obj):
    '''Clean up untar directories'''
    for layer in image_obj.layers:
        fspath = rootfs.get_untar_dir(layer.tar_file)
        if os.path.exists(fspath):
            rootfs.root_command(rootfs.remove, fspath)
github vmware / tern / tern / analyze / docker / container.py View on Github external
'''Run docker save and extract the files in a temporary directory'''
    temp_path = rootfs.get_working_dir()
    placeholder = os.path.join(general.get_top_dir(), temp_tarfile)
    try:
        if common.check_tar(image_tag_string) is True:
            # image_tag_string is the path to the tar file for raw images
            rootfs.extract_tarfile(image_tag_string, temp_path)
        else:
            image = client.images.get(image_tag_string)
            result = image.save(chunk_size=2097152, named=True)
            # write all of the tar byte stream into temporary tar file
            with open(placeholder, 'wb') as f:
                for chunk in result:
                    f.write(chunk)
            # extract tarfile into folder
            rootfs.extract_tarfile(placeholder, temp_path)
            # remove temporary tar file
            os.remove(placeholder)
        if not os.listdir(temp_path):
            raise IOError('Unable to untar Docker image')
    except docker.errors.APIError:  # pylint: disable=try-except-raise
        raise