예제 #1
0
파일: helpers.py 프로젝트: zoek1/tern
def load_docker_commands(dockerfile_path):
    '''Given a dockerfile get a persistent list of docker commands'''
    if not os.path.isfile(dockerfile_path):
        raise IOError('{} does not exist'.format(dockerfile_path))
    global docker_commands
    docker_commands = dockerfile.get_directive_list(
        dockerfile.get_command_list(dockerfile_path))
    global dockerfile_global
    dockerfile_global = dockerfile_path
예제 #2
0
파일: helpers.py 프로젝트: zoek1/tern
def set_imported_layers(docker_image):
    '''Given a Docker image object that was built from a Dockerfile, set the
    layers that were imported using the Dockerfile's FROM command or the ones
    that came before it'''
    dockerfile_lines = dockerfile.get_command_list(dockerfile_global)
    index = -1
    from_line = ''
    for line in dockerfile_lines:
        if 'FROM' in line:
            from_line = line
            break
    for layer in docker_image.layers:
        instr = created_to_instruction(layer.created_by)
        if instr in dockerfile_lines:
            index = docker_image.layers.index(layer)
            break
    if index != -1:
        # index was set so all layers before this index has been imported
        for i in range(0, index):
            docker_image.layers[i].import_str = from_line
예제 #3
0
def set_imported_layers(docker_image):
    '''Given a Docker image object that was built from a Dockerfile, set the
    layers that were imported using the Dockerfile's FROM command or the ones
    that came before it'''
    index = -1
    from_line = ''
    dockerfile_lines = docker_commands
    for cmd in dockerfile_lines:
        if cmd['instruction'] == 'FROM':
            from_line = cmd['content'].rstrip()
            break
    command_list = dockerfile.get_command_list(dockerfile_lines)
    for layer in docker_image.layers:
        instr = created_to_instruction(layer.created_by)
        if instr in command_list:
            index = docker_image.layers.index(layer)
            break
    if index != -1:
        # index was set so all layers before this index has been imported
        for i in range(0, index):
            docker_image.layers[i].import_str = from_line