parameters: (output,
                   identifier,
                   layers,
                   config,
                   tags=None,
                   base=None,
                   legacy_base=None,
                   metadata_id=None,
                   metadata=None,
                   name=None,
                   repository=None)
docstring: Creates a Docker image.
  
    Args:
      output: the name of the docker image file to create.
      identifier: the identifier for this image (sha256 of the metadata).
      layers: the layer content (a sha256 and a tar file).
      config: the configuration file for the image.
      tags: tags that apply to this image.
      base: a base layer (optional) to build on top of.
      legacy_base: a base layer (optional) to build on top of.
      metadata_id: the identifier of the top layer for this image.
      metadata: the json metadata file for the top layer.
      name: symbolic name for this docker image.
      repository: repository name for this docker image.
docstring_summary: Creates a Docker image.
docstring_tokens: Creates a Docker image .
function: def create_image(output,
                   identifier,
                   layers,
                   config,
                   tags=None,
                   base=None,
                   legacy_base=None,
                   metadata_id=None,
                   metadata=None,
                   name=None,
                   repository=None):
    """Creates a Docker image.
  
    Args:
      output: the name of the docker image file to create.
      identifier: the identifier for this image (sha256 of the metadata).
      layers: the layer content (a sha256 and a tar file).
      config: the configuration file for the image.
      tags: tags that apply to this image.
      base: a base layer (optional) to build on top of.
      legacy_base: a base layer (optional) to build on top of.
      metadata_id: the identifier of the top layer for this image.
      metadata: the json metadata file for the top layer.
      name: symbolic name for this docker image.
      repository: repository name for this docker image.
    """
    tar = archive.TarFileWriter(output)
  
    # add the image config referenced by the Config section in the manifest
    # the name can be anything but docker uses the format below
    config_file_name = identifier + '.json'
    tar.add_file(config_file_name, file_content=config)
  
    layer_file_names = []
  
    if metadata_id:
      # Write our id to 'top' as we are now the topmost layer.
      tar.add_file('top', content=metadata_id)
  
      # Each layer is encoded as a directory in the larger tarball of the form:
      #  {id}\
      #    layer.tar
      #    VERSION
      #    json
      # Create the directory for us to now fill in.
      tar.add_file(metadata_id + '/', tarfile.DIRTYPE)
      # VERSION generally seems to contain 1.0, not entirely sure
      # what the point of this is.
      tar.add_file(metadata_id + '/VERSION', content=DATA_FORMAT_VERSION)
      # Add the layer file
      layer_file_name = metadata_id + '/layer.tar'
      layer_file_names.append(layer_file_name)
      tar.add_file(layer_file_name, file_content=layers[0]['layer'])
      # Now the json metadata
      tar.add_file(metadata_id + '/json', file_content=metadata)
  
      # Merge the base if any
      if legacy_base:
        tar.add_tar(legacy_base, name_filter=_base_name_filter)
    else:
      for layer in layers:
        # layers can be called anything, so just name them by their sha256
        layer_file_name = identifier + '/' + layer['name'] + '.tar'
        layer_file_names.append(layer_file_name)
        tar.add_file(layer_file_name, file_content=layer['layer'])
  
    base_layer_file_names = []
    parent = None
    if base:
      latest_item = utils.GetLatestManifestFromTar(base)
      if latest_item:
        base_layer_file_names = latest_item.get('Layers', [])
        config_file = latest_item['Config']
        parent_search = re.search('^(.+)\\.json$', config_file)
        if parent_search:
          parent = parent_search.group(1)
  
    manifest_item = {
        'Config': config_file_name,
        'Layers': base_layer_file_names + layer_file_names,
        'RepoTags': tags or []
    }
    if parent:
      manifest_item['Parent'] = 'sha256:' + parent
  
    manifest = [manifest_item]
  
    manifest_content = json.dumps(manifest, sort_keys=True)
    tar.add_file('manifest.json', content=manifest_content)
  
    # In addition to N layers of the form described above, there is
    # a single file at the top of the image called repositories.
    # This file contains a JSON blob of the form:
    # {
    #   'repo':{
    #     'tag-name': 'top-most layer hex',
    #     ...
    #   },
    #   ...
    # }
    if repository:
      tar.add_file('repositories', content='\n'.join([
          '{',
          '  "%s": {' % repository,
          '    "%s": "%s"' % (name, identifier),
          '  }',
          '}']))
function_tokens: def create_image ( output , identifier , layers , config , tags = None , base = None , legacy_base = None , metadata_id = None , metadata = None , name = None , repository = None ) : tar = archive . TarFileWriter ( output ) # add the image config referenced by the Config section in the manifest # the name can be anything but docker uses the format below config_file_name = identifier + '.json' tar . add_file ( config_file_name , file_content = config ) layer_file_names = [ ] if metadata_id : # Write our id to 'top' as we are now the topmost layer. tar . add_file ( 'top' , content = metadata_id ) # Each layer is encoded as a directory in the larger tarball of the form: #  {id}\ #    layer.tar #    VERSION #    json # Create the directory for us to now fill in. tar . add_file ( metadata_id + '/' , tarfile . DIRTYPE ) # VERSION generally seems to contain 1.0, not entirely sure # what the point of this is. tar . add_file ( metadata_id + '/VERSION' , content = DATA_FORMAT_VERSION ) # Add the layer file layer_file_name = metadata_id + '/layer.tar' layer_file_names . append ( layer_file_name ) tar . add_file ( layer_file_name , file_content = layers [ 0 ] [ 'layer' ] ) # Now the json metadata tar . add_file ( metadata_id + '/json' , file_content = metadata ) # Merge the base if any if legacy_base : tar . add_tar ( legacy_base , name_filter = _base_name_filter ) else : for layer in layers : # layers can be called anything, so just name them by their sha256 layer_file_name = identifier + '/' + layer [ 'name' ] + '.tar' layer_file_names . append ( layer_file_name ) tar . add_file ( layer_file_name , file_content = layer [ 'layer' ] ) base_layer_file_names = [ ] parent = None if base : latest_item = utils . GetLatestManifestFromTar ( base ) if latest_item : base_layer_file_names = latest_item . get ( 'Layers' , [ ] ) config_file = latest_item [ 'Config' ] parent_search = re . search ( '^(.+)\\.json$' , config_file ) if parent_search : parent = parent_search . group ( 1 ) manifest_item = { 'Config' : config_file_name , 'Layers' : base_layer_file_names + layer_file_names , 'RepoTags' : tags or [ ] } if parent : manifest_item [ 'Parent' ] = 'sha256:' + parent manifest = [ manifest_item ] manifest_content = json . dumps ( manifest , sort_keys = True ) tar . add_file ( 'manifest.json' , content = manifest_content ) # In addition to N layers of the form described above, there is # a single file at the top of the image called repositories. # This file contains a JSON blob of the form: # { #   'repo':{ #     'tag-name': 'top-most layer hex', #     ... #   }, #   ... # } if repository : tar . add_file ( 'repositories' , content = '\n' . join ( [ '{' , '  "%s": {' % repository , '    "%s": "%s"' % ( name , identifier ) , '  }' , '}' ] ) )