github.com/buildpacks/pack@v0.33.3-0.20240516162812-884dd1837311/pkg/dist/dist.go (about)

     1  package dist
     2  
     3  import (
     4  	"github.com/buildpacks/lifecycle/api"
     5  )
     6  
     7  const (
     8  	BuildpackLayersLabel   = "io.buildpacks.buildpack.layers"
     9  	ExtensionLayersLabel   = "io.buildpacks.extension.layers"
    10  	ExtensionMetadataLabel = "io.buildpacks.extension.metadata"
    11  	DefaultTargetOSLinux   = "linux"
    12  	DefaultTargetOSWindows = "windows"
    13  	DefaultTargetArch      = "amd64"
    14  )
    15  
    16  type BuildpackURI struct {
    17  	URI string `toml:"uri"`
    18  }
    19  
    20  type ImageRef struct {
    21  	ImageName string `toml:"image"`
    22  }
    23  
    24  type ImageOrURI struct {
    25  	BuildpackURI
    26  	ImageRef
    27  }
    28  
    29  func (c *ImageOrURI) DisplayString() string {
    30  	if c.BuildpackURI.URI != "" {
    31  		return c.BuildpackURI.URI
    32  	}
    33  
    34  	return c.ImageRef.ImageName
    35  }
    36  
    37  type Platform struct {
    38  	OS string `toml:"os"`
    39  }
    40  
    41  type Order []OrderEntry
    42  
    43  type OrderEntry struct {
    44  	Group []ModuleRef `toml:"group" json:"group"`
    45  }
    46  
    47  type ModuleRef struct {
    48  	ModuleInfo `yaml:"buildpackinfo,inline"`
    49  	Optional   bool `toml:"optional,omitempty" json:"optional,omitempty" yaml:"optional,omitempty"`
    50  }
    51  
    52  type ModuleLayers map[string]map[string]ModuleLayerInfo
    53  
    54  type ModuleLayerInfo struct {
    55  	API         *api.Version `json:"api"`
    56  	Stacks      []Stack      `json:"stacks,omitempty"`
    57  	Targets     []Target     `json:"targets,omitempty"`
    58  	Order       Order        `json:"order,omitempty"`
    59  	LayerDiffID string       `json:"layerDiffID"`
    60  	Homepage    string       `json:"homepage,omitempty"`
    61  	Name        string       `json:"name,omitempty"`
    62  }
    63  
    64  func (b ModuleLayers) Get(id, version string) (ModuleLayerInfo, bool) {
    65  	buildpackLayerEntries, ok := b[id]
    66  	if !ok {
    67  		return ModuleLayerInfo{}, false
    68  	}
    69  	if len(buildpackLayerEntries) == 1 && version == "" {
    70  		for key := range buildpackLayerEntries {
    71  			version = key
    72  		}
    73  	}
    74  
    75  	result, ok := buildpackLayerEntries[version]
    76  	return result, ok
    77  }