github.com/YousefHaggyHeroku/pack@v1.5.5/internal/dist/dist.go (about)

     1  package dist
     2  
     3  import "github.com/buildpacks/lifecycle/api"
     4  
     5  const BuildpackLayersLabel = "io.buildpacks.buildpack.layers"
     6  
     7  type BuildpackURI struct {
     8  	URI string `toml:"uri"`
     9  }
    10  
    11  type ImageRef struct {
    12  	ImageName string `toml:"image"`
    13  }
    14  
    15  type ImageOrURI struct {
    16  	BuildpackURI
    17  	ImageRef
    18  }
    19  
    20  type Platform struct {
    21  	OS string `toml:"os"`
    22  }
    23  
    24  type Order []OrderEntry
    25  
    26  type OrderEntry struct {
    27  	Group []BuildpackRef `toml:"group" json:"group"`
    28  }
    29  
    30  type BuildpackRef struct {
    31  	BuildpackInfo `yaml:"buildpackinfo,inline"`
    32  	Optional      bool `toml:"optional,omitempty" json:"optional,omitempty" yaml:"optional,omitempty"`
    33  }
    34  
    35  type BuildpackLayers map[string]map[string]BuildpackLayerInfo
    36  
    37  type BuildpackLayerInfo struct {
    38  	API         *api.Version `json:"api"`
    39  	Stacks      []Stack      `json:"stacks,omitempty"`
    40  	Order       Order        `json:"order,omitempty"`
    41  	LayerDiffID string       `json:"layerDiffID"`
    42  	Homepage    string       `json:"homepage,omitempty"`
    43  }
    44  
    45  func (b BuildpackLayers) Get(id, version string) (BuildpackLayerInfo, bool) {
    46  	buildpackLayerEntries, ok := b[id]
    47  	if !ok {
    48  		return BuildpackLayerInfo{}, false
    49  	}
    50  	if len(buildpackLayerEntries) == 1 && version == "" {
    51  		for key := range buildpackLayerEntries {
    52  			version = key
    53  		}
    54  	}
    55  
    56  	result, ok := buildpackLayerEntries[version]
    57  	return result, ok
    58  }
    59  
    60  func AddBuildpackToLayersMD(layerMD BuildpackLayers, descriptor BuildpackDescriptor, diffID string) {
    61  	bpInfo := descriptor.Info
    62  	if _, ok := layerMD[bpInfo.ID]; !ok {
    63  		layerMD[bpInfo.ID] = map[string]BuildpackLayerInfo{}
    64  	}
    65  	layerMD[bpInfo.ID][bpInfo.Version] = BuildpackLayerInfo{
    66  		API:         descriptor.API,
    67  		Stacks:      descriptor.Stacks,
    68  		Order:       descriptor.Order,
    69  		LayerDiffID: diffID,
    70  		Homepage:    bpInfo.Homepage,
    71  	}
    72  }