This repository has been archived by the owner on May 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Buildpack metadata is added by deplab
* reads from label io.buildpacks.build.metadata * integration tests provided * buildpack metadata and buildpack bom metadata is ordered alphabetically by id and name, respectively. * sha256 of json encoded metadata is calculated; this matches behaviour of dpkg and rpm lists * refactors Digest to common package; removes duplication from dpkg, rpm and cnb * adds integration test for inspect a scratch image * adds a scratch image test asset * created more tests for merge * amends documentation to better explain the revised behaviour of inspect [#170631159] Signed-off-by: Iain Sproat <[email protected]>
- Loading branch information
1 parent
771b0f3
commit ab9af27
Showing
28 changed files
with
885 additions
and
428 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package cnb | ||
|
||
import ( | ||
"encoding/json" | ||
"sort" | ||
|
||
"github.com/pivotal/deplab/pkg/common" | ||
|
||
"github.com/pivotal/deplab/pkg/metadata" | ||
"github.com/pkg/errors" | ||
"golang.org/x/text/collate" | ||
"golang.org/x/text/language" | ||
|
||
"github.com/pivotal/deplab/pkg/image" | ||
) | ||
|
||
func Provider(dli image.Image, _ common.RunParams, md metadata.Metadata) (metadata.Metadata, error) { | ||
dependency, err := buildDependencyMetadata(dli) | ||
if err != nil { | ||
return metadata.Metadata{}, err | ||
} | ||
md.Dependencies = append(md.Dependencies, dependency) | ||
return md, nil | ||
} | ||
|
||
func buildDependencyMetadata(dli image.Image) (metadata.Dependency, error) { | ||
var buildpackMetadataContents string | ||
config, err := dli.GetConfig() | ||
|
||
if err != nil { | ||
return metadata.Dependency{}, err | ||
} | ||
|
||
buildpackMetadataContents = config.Config.Labels["io.buildpacks.build.metadata"] | ||
|
||
if buildpackMetadataContents != "" { | ||
buildpackMetadata, err := parseMetadataJSON(buildpackMetadataContents) | ||
if err != nil { | ||
return metadata.Dependency{}, errors.Wrapf(err, "Could not parse buildpack metadata toml") | ||
} | ||
|
||
version, err := common.Digest(buildpackMetadata) | ||
if err != nil { | ||
return metadata.Dependency{}, errors.Wrapf(err, "Could not get digest for buildpack metadata") | ||
} | ||
|
||
return metadata.Dependency{ | ||
Type: metadata.BuildpackMetadataType, | ||
Source: metadata.Source{ | ||
Type: "inline", | ||
Metadata: buildpackMetadata, | ||
Version: map[string]interface{}{ | ||
"sha256": version, | ||
}, | ||
}, | ||
}, nil | ||
} | ||
|
||
return metadata.Dependency{}, nil | ||
} | ||
|
||
func parseMetadataJSON(buildpackMetadata string) (metadata.BuildpackBOMSourceMetadata, error) { | ||
var bp metadata.BuildpackBOMSourceMetadata | ||
|
||
err := json.Unmarshal([]byte(buildpackMetadata), &bp) | ||
if err != nil { | ||
return metadata.BuildpackBOMSourceMetadata{}, errors.Wrapf(err, "could not decode json") | ||
} | ||
|
||
collator := collate.New(language.BritishEnglish) | ||
sort.Slice(bp.Buildpacks, func(i, j int) bool { | ||
return collator.CompareString(bp.Buildpacks[i].ID, bp.Buildpacks[j].ID) < 0 | ||
}) | ||
|
||
sort.Slice(bp.BillOfMaterials, func(i, j int) bool { | ||
return collator.CompareString(bp.BillOfMaterials[i].Name, bp.BillOfMaterials[j].Name) < 0 | ||
}) | ||
|
||
return bp, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package common_test | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestCommon(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Common Suite") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
package common_test | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
. "github.com/pivotal/deplab/pkg/common" | ||
"github.com/pivotal/deplab/pkg/metadata" | ||
) | ||
|
||
var _ = Describe("Digest", func() { | ||
It("generate a sha256 of the input", func() { | ||
out, err := Digest(metadata.DebianPackageListSourceMetadata{ | ||
AptSources: []string{"deb example.com bionic main universe"}, | ||
Packages: []metadata.DpkgPackage{ | ||
{ | ||
Package: "foo", | ||
Source: metadata.PackageSource{ | ||
Version: "4.2", | ||
}, | ||
}, | ||
}, | ||
}) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
Expect(out).To(Equal("7ecf7aa2c71ee01ec2b90f37a3b8e944158e9aea6b8cee0290a7cb187884cf4c")) | ||
}) | ||
|
||
It("generates the same digest for 2 different input instances with the same content", func() { | ||
input1 := metadata.DebianPackageListSourceMetadata{ | ||
AptSources: []string{"deb example.com bionic main universe"}, | ||
Packages: []metadata.DpkgPackage{ | ||
{ | ||
Package: "foo", | ||
Source: metadata.PackageSource{ | ||
Version: "4.2", | ||
}, | ||
}, | ||
}, | ||
} | ||
input2 := metadata.DebianPackageListSourceMetadata{ | ||
AptSources: []string{"deb example.com bionic main universe"}, | ||
Packages: []metadata.DpkgPackage{ | ||
{ | ||
Package: "foo", | ||
Source: metadata.PackageSource{ | ||
Version: "4.2", | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
out1, err := Digest(input1) | ||
Expect(err).ToNot(HaveOccurred()) | ||
out2, err := Digest(input2) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
Expect(&input1 != &input2).To(BeTrue()) | ||
Expect(out2).To(Equal(out1)) | ||
}) | ||
|
||
It("generates a different digest for 2 different input instances with the same content in different order", func() { | ||
input1 := metadata.DebianPackageListSourceMetadata{ | ||
AptSources: []string{"deb example.com bionic main universe"}, | ||
Packages: []metadata.DpkgPackage{ | ||
{ | ||
Package: "foo", | ||
Source: metadata.PackageSource{ | ||
Version: "4.2", | ||
}, | ||
}, | ||
{ | ||
Package: "bar", | ||
Source: metadata.PackageSource{ | ||
Version: "1.0", | ||
}, | ||
}, | ||
}, | ||
} | ||
input2 := metadata.DebianPackageListSourceMetadata{ | ||
AptSources: []string{"deb example.com bionic main universe"}, | ||
Packages: []metadata.DpkgPackage{ | ||
{ | ||
Package: "bar", | ||
Source: metadata.PackageSource{ | ||
Version: "1.0", | ||
}, | ||
}, | ||
{ | ||
Package: "foo", | ||
Source: metadata.PackageSource{ | ||
Version: "4.2", | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
out1, err := Digest(input1) | ||
Expect(err).ToNot(HaveOccurred()) | ||
out2, err := Digest(input2) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
Expect(&input1 != &input2).To(BeTrue()) | ||
Expect(out2).ToNot(Equal(out1)) | ||
}) | ||
|
||
It("generates different digest for 2 different inputs", func() { | ||
input1 := metadata.DebianPackageListSourceMetadata{ | ||
AptSources: []string{"deb example.com bionic main universe"}, | ||
Packages: []metadata.DpkgPackage{ | ||
{ | ||
Package: "bar", | ||
Source: metadata.PackageSource{ | ||
Version: "4.2", | ||
}, | ||
}, | ||
}, | ||
} | ||
input2 := metadata.DebianPackageListSourceMetadata{ | ||
AptSources: []string{"deb example.com bionic main universe"}, | ||
Packages: []metadata.DpkgPackage{ | ||
{ | ||
Package: "foo", | ||
Source: metadata.PackageSource{ | ||
Version: "4.2", | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
out1, err := Digest(input1) | ||
Expect(err).ToNot(HaveOccurred()) | ||
out2, err := Digest(input2) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
Expect(out2).ToNot(Equal(out1)) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.