Skip to content

Commit

Permalink
adds support for extensions in OCILayoutPackage
Browse files Browse the repository at this point in the history
Signed-off-by: Darshan Kumar <[email protected]>
  • Loading branch information
itsdarshankumar committed May 11, 2023
1 parent 20d94a2 commit 84142bf
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 13 deletions.
2 changes: 0 additions & 2 deletions pkg/buildpack/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ func (c *buildpackDownloader) Download(ctx context.Context, moduleURI string, op
return nil, nil, err
}
}

var mainBP BuildModule
var depBPs []BuildModule
switch locatorType {
Expand Down Expand Up @@ -205,6 +204,5 @@ func extractPackaged(ctx context.Context, kind string, pkgImageRef string, fetch
if err != nil {
return nil, nil, errors.Wrapf(err, "extracting %ss from %s", kind, style.Symbol(pkgImageRef))
}

return mainModule, depModules, nil
}
1 change: 0 additions & 1 deletion pkg/buildpack/locator_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ func parseNakedLocator(locator, relativeBaseDir string, buildpacksFromBuilder []
// 2. Does it match a buildpack ID in the builder
// 3. Does it look like a Buildpack Registry ID
// 4. Does it look like a Docker ref

if isLocalFile(locator, relativeBaseDir) {
return URILocator
}
Expand Down
32 changes: 24 additions & 8 deletions pkg/buildpack/oci_layout_package.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"archive/tar"
"compress/gzip"
"encoding/json"
"fmt"
"io"
"path"
"strings"
Expand Down Expand Up @@ -41,7 +42,7 @@ func IsOCILayoutBlob(blob blob2.Blob) (bool, error) {

// BuildpacksFromOCILayoutBlob constructs buildpacks from a blob in OCI layout format.
func BuildpacksFromOCILayoutBlob(blob Blob) (mainBP BuildModule, dependencies []BuildModule, err error) {
layoutPackage, err := newOCILayoutPackage(blob)
layoutPackage, err := newOCILayoutPackage(blob, KindBuildpack)
if err != nil {
return nil, nil, err
}
Expand All @@ -51,11 +52,16 @@ func BuildpacksFromOCILayoutBlob(blob Blob) (mainBP BuildModule, dependencies []

// ExtensionsFromOCILayoutBlob constructs extensions from a blob in OCI layout format.
func ExtensionsFromOCILayoutBlob(blob Blob) (mainExt BuildModule, err error) {
return nil, nil // TODO: add extractExtensions when `pack extension package` is supported in https://github.com/buildpacks/pack/issues/1489
layoutPackage, err := newOCILayoutPackage(blob, KindExtension)
if err != nil {
return nil, err
}

return extractExtensions(layoutPackage)
}

func ConfigFromOCILayoutBlob(blob Blob) (config v1.ImageConfig, err error) {
layoutPackage, err := newOCILayoutPackage(blob)
layoutPackage, err := newOCILayoutPackage(blob, KindBuildpack)
if err != nil {
return v1.ImageConfig{}, err
}
Expand All @@ -68,7 +74,7 @@ type ociLayoutPackage struct {
blob Blob
}

func newOCILayoutPackage(blob Blob) (*ociLayoutPackage, error) {
func newOCILayoutPackage(blob Blob, kind string) (*ociLayoutPackage, error) {
index := &v1.Index{}

if err := unmarshalJSONFromBlob(blob, "/index.json", index); err != nil {
Expand Down Expand Up @@ -96,10 +102,20 @@ func newOCILayoutPackage(blob Blob) (*ociLayoutPackage, error) {
if err := unmarshalJSONFromBlob(blob, pathFromDescriptor(manifest.Config), imageInfo); err != nil {
return nil, err
}

layersLabel := imageInfo.Config.Labels[dist.BuildpackLayersLabel]
if layersLabel == "" {
return nil, errors.Errorf("label %s not found", style.Symbol(dist.BuildpackLayersLabel))
var layersLabel string
switch kind {
case KindBuildpack:
layersLabel = imageInfo.Config.Labels[dist.BuildpackLayersLabel]
if layersLabel == "" {
return nil, errors.Errorf("label %s not found", style.Symbol(dist.BuildpackLayersLabel))
}
case KindExtension:
layersLabel = imageInfo.Config.Labels[dist.ExtensionLayersLabel]
if layersLabel == "" {
return nil, errors.Errorf("label %s not found", style.Symbol(dist.ExtensionLayersLabel))
}
default:
return nil, fmt.Errorf("unknown module kind: %s", kind)
}

bpLayers := dist.ModuleLayers{}
Expand Down
2 changes: 1 addition & 1 deletion pkg/buildpack/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func extractExtensions(pkg Package) (mainExt BuildModule, err error) {
if !ok {
return nil, errors.Errorf(
"could not find label %s",
style.Symbol(dist.ExtensionLayersLabel),
style.Symbol(dist.ExtensionLayersLabel),
)
}
for extID, v := range pkgLayers {
Expand Down
1 change: 0 additions & 1 deletion pkg/client/create_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ func (c *Client) addConfig(ctx context.Context, kind string, config pubbldr.Modu
if err != nil {
return errors.Wrapf(err, "downloading %s", kind)
}

err = validateModule(kind, mainBP, config.URI, config.ID, config.Version)
if err != nil {
return errors.Wrapf(err, "invalid %s", kind)
Expand Down

0 comments on commit 84142bf

Please sign in to comment.