parameters: (data, options)
return_statement: return output
docstring: Create an image config possibly based on an existing one.
  
    Args:
      data: A dict of Docker image config to base on top of.
      options: Options specific to this image which will be merged with any
               existing data
  
    Returns:
      Image config for the new image
docstring_summary: Create an image config possibly based on an existing one.
docstring_tokens: Create an image config possibly based on an existing one .
function: def CreateImageConfig(data, options):
    """Create an image config possibly based on an existing one.
  
    Args:
      data: A dict of Docker image config to base on top of.
      options: Options specific to this image which will be merged with any
               existing data
  
    Returns:
      Image config for the new image
    """
    defaults = DeepCopySkipNull(data)
  
    # dont propagate non-spec keys
    output = dict()
    output['created'] = '0001-01-01T00:00:00Z'
    output['author'] = 'Bazel'
    output['architecture'] = _PROCESSOR_ARCHITECTURE
    output['os'] = _OPERATING_SYSTEM
  
    output['config'] = defaults.get('config', {})
  
    if options.entrypoint:
      output['config']['Entrypoint'] = options.entrypoint
    if options.cmd:
      output['config']['Cmd'] = options.cmd
    if options.user:
      output['config']['User'] = options.user
  
    def Dict2ConfigValue(d):
      return ['%s=%s' % (k, d[k]) for k in sorted(d.keys())]
  
    if options.env:
      # Build a dictionary of existing environment variables (used by Resolve).
      environ_dict = KeyValueToDict(output['config'].get('Env', []))
      # Merge in new environment variables, resolving references.
      for k, v in options.env.iteritems():
        # Resolve handles scenarios like "PATH=$PATH:...".
        environ_dict[k] = Resolve(v, environ_dict)
      output['config']['Env'] = Dict2ConfigValue(environ_dict)
  
    # TODO(babel-team) Label is currently docker specific
    if options.labels:
      label_dict = KeyValueToDict(output['config'].get('Label', []))
      for k, v in options.labels.iteritems():
        label_dict[k] = v
      output['config']['Label'] = Dict2ConfigValue(label_dict)
  
    if options.ports:
      if 'ExposedPorts' not in output['config']:
        output['config']['ExposedPorts'] = {}
      for p in options.ports:
        if '/' in p:
          # The port spec has the form 80/tcp, 1234/udp
          # so we simply use it as the key.
          output['config']['ExposedPorts'][p] = {}
        else:
          # Assume tcp
          output['config']['ExposedPorts'][p + '/tcp'] = {}
  
    if options.volumes:
      if 'Volumes' not in output['config']:
        output['config']['Volumes'] = {}
      for p in options.volumes:
        output['config']['Volumes'][p] = {}
  
    if options.workdir:
      output['config']['WorkingDir'] = options.workdir
  
    # diff_ids are ordered from bottom-most to top-most
    diff_ids = defaults.get('rootfs', {}).get('diff_ids', [])
    layers = options.layers if options.layers else []
    diff_ids += ['sha256:%s' % l for l in layers]
    output['rootfs'] = {
        'type': 'layers',
        'diff_ids': diff_ids,
    }
  
    # history is ordered from bottom-most layer to top-most layer
    history = defaults.get('history', [])
    # docker only allows the child to have one more history entry than the parent
    history += [{
        'created': '0001-01-01T00:00:00Z',
        'created_by': 'bazel build ...',
        'author': 'Bazel'}]
    output['history'] = history
  
    return output
function_tokens: def CreateImageConfig ( data , options ) : defaults = DeepCopySkipNull ( data ) # dont propagate non-spec keys output = dict ( ) output [ 'created' ] = '0001-01-01T00:00:00Z' output [ 'author' ] = 'Bazel' output [ 'architecture' ] = _PROCESSOR_ARCHITECTURE output [ 'os' ] = _OPERATING_SYSTEM output [ 'config' ] = defaults . get ( 'config' , { } ) if options . entrypoint : output [ 'config' ] [ 'Entrypoint' ] = options . entrypoint if options . cmd : output [ 'config' ] [ 'Cmd' ] = options . cmd if options . user : output [ 'config' ] [ 'User' ] = options . user def Dict2ConfigValue ( d ) : return [ '%s=%s' % ( k , d [ k ] ) for k in sorted ( d . keys ( ) ) ] if options . env : # Build a dictionary of existing environment variables (used by Resolve). environ_dict = KeyValueToDict ( output [ 'config' ] . get ( 'Env' , [ ] ) ) # Merge in new environment variables, resolving references. for k , v in options . env . iteritems ( ) : # Resolve handles scenarios like "PATH=$PATH:...". environ_dict [ k ] = Resolve ( v , environ_dict ) output [ 'config' ] [ 'Env' ] = Dict2ConfigValue ( environ_dict ) # TODO(babel-team) Label is currently docker specific if options . labels : label_dict = KeyValueToDict ( output [ 'config' ] . get ( 'Label' , [ ] ) ) for k , v in options . labels . iteritems ( ) : label_dict [ k ] = v output [ 'config' ] [ 'Label' ] = Dict2ConfigValue ( label_dict ) if options . ports : if 'ExposedPorts' not in output [ 'config' ] : output [ 'config' ] [ 'ExposedPorts' ] = { } for p in options . ports : if '/' in p : # The port spec has the form 80/tcp, 1234/udp # so we simply use it as the key. output [ 'config' ] [ 'ExposedPorts' ] [ p ] = { } else : # Assume tcp output [ 'config' ] [ 'ExposedPorts' ] [ p + '/tcp' ] = { } if options . volumes : if 'Volumes' not in output [ 'config' ] : output [ 'config' ] [ 'Volumes' ] = { } for p in options . volumes : output [ 'config' ] [ 'Volumes' ] [ p ] = { } if options . workdir : output [ 'config' ] [ 'WorkingDir' ] = options . workdir # diff_ids are ordered from bottom-most to top-most diff_ids = defaults . get ( 'rootfs' , { } ) . get ( 'diff_ids' , [ ] ) layers = options . layers if options . layers else [ ] diff_ids += [ 'sha256:%s' % l for l in layers ] output [ 'rootfs' ] = { 'type' : 'layers' , 'diff_ids' : diff_ids , } # history is ordered from bottom-most layer to top-most layer history = defaults . get ( 'history' , [ ] ) # docker only allows the child to have one more history entry than the parent history += [ { 'created' : '0001-01-01T00:00:00Z' , 'created_by' : 'bazel build ...' , 'author' : 'Bazel' } ] output [ 'history' ] = history return output