Skip to content

Commit

Permalink
Merge branch 'master' into cnb-bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
scothis authored May 6, 2020
2 parents b01248a + 019fd44 commit de67384
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docs/custombuilders.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ spec:
sources:
- image: gcr.io/cf-build-service-public/node-engine-buildpackage@sha256:95ff756f0ef0e026440a8523f4bab02fd8b45dc1a8a3a7ba063cefdba5cb9493
- image: gcr.io/cf-build-service-public/npm-buildpackage@sha256:5058ceb9a562ec647ea5a41008b0d11e32a56e13e8c9ec20c4db63d220373e33
- image: gcr.io/paketo-buildpacks/build:base
- image: gcr.io/paketo-buildpacks/builder:base
```
* `sources`: List of builder images or buildpackage images to make available in the store. Each image is an object with the key image.
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,6 @@ This tutorial will walk through creating a kpack [image](image.md) resource to b
1. kpack rebuilds with buildpack updates

The next time the `gcr.io/paketo-buildpacks/build:base` is updated, kpack will detect if it contains buildpack updates to any of the buildpacks used by the tutorial image.
The next time the `gcr.io/paketo-buildpacks/builder:base` is updated, kpack will detect if it contains buildpack updates to any of the buildpacks used by the tutorial image.
If there is a buildpack update, kpack will automatically create a new build to rebuild your image.

7 changes: 7 additions & 0 deletions pkg/apis/experimental/v1alpha1/buildpackage_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package v1alpha1

// +k8s:openapi-gen=true
type BuildpackageInfo struct {
Id string `json:"id,omitempty"`
Version string `json:"version,omitempty"`
}
9 changes: 5 additions & 4 deletions pkg/apis/experimental/v1alpha1/store_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ type StoreStatus struct {
// +k8s:openapi-gen=true
type StoreBuildpack struct {
BuildpackInfo `json:",inline"`
StoreImage StoreImage `json:"storeImage,omitempty"`
DiffId string `json:"diffId,omitempty"`
Digest string `json:"digest,omitempty"`
Size int64 `json:"size,omitempty"`
Buildpackage BuildpackageInfo `json:"buildpackage,omitempty"`
StoreImage StoreImage `json:"storeImage,omitempty"`
DiffId string `json:"diffId,omitempty"`
Digest string `json:"digest,omitempty"`
Size int64 `json:"size,omitempty"`

API string `json:"api,omitempty"`
Homepage string `json:"homepage,omitempty"`
Expand Down
10 changes: 10 additions & 0 deletions pkg/cnb/buildpackage_metadata.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package cnb

const (
buildpackageMetadataLabel = "io.buildpacks.buildpackage.metadata"
)

type BuildpackageMetadata struct {
Id string `json:"id"`
Version string `json:"version"`
}
23 changes: 20 additions & 3 deletions pkg/cnb/remote_store_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,23 @@ func (r *RemoteStoreReader) Read(storeImages []v1alpha1.StoreImage) ([]v1alpha1.

c := make(chan v1alpha1.StoreBuildpack)
for _, storeImage := range storeImages {
storeImage := storeImage
storeImageCopy := storeImage
g.Go(func() error {
image, _, err := r.RegistryClient.Fetch(r.Keychain, storeImage.Image)
image, _, err := r.RegistryClient.Fetch(r.Keychain, storeImageCopy.Image)
if err != nil {
return err
}

bpMetadata := BuildpackageMetadata{}
if ok, err := imagehelpers.HasLabel(image, buildpackageMetadataLabel); err != nil {
return err
} else if ok {
err := imagehelpers.GetLabel(image, buildpackageMetadataLabel, &bpMetadata)
if err != nil {
return err
}
}

layerMetadata := BuildpackLayerMetadata{}
err = imagehelpers.GetLabel(image, buildpackLayersLabel, &layerMetadata)
if err != nil {
Expand All @@ -37,6 +47,11 @@ func (r *RemoteStoreReader) Read(storeImages []v1alpha1.StoreImage) ([]v1alpha1.

for id := range layerMetadata {
for version, metadata := range layerMetadata[id] {
packageInfo := v1alpha1.BuildpackageInfo{
Id: bpMetadata.Id,
Version: bpMetadata.Version,
}

info := v1alpha1.BuildpackInfo{
Id: id,
Version: version,
Expand All @@ -46,6 +61,7 @@ func (r *RemoteStoreReader) Read(storeImages []v1alpha1.StoreImage) ([]v1alpha1.
if err != nil {
return errors.Wrapf(err, "unable to parse layer diffId for %s", info)
}

layer, err := image.LayerByDiffID(diffId)
if err != nil {
return errors.Wrapf(err, "unable to get layer %s", info)
Expand All @@ -63,7 +79,8 @@ func (r *RemoteStoreReader) Read(storeImages []v1alpha1.StoreImage) ([]v1alpha1.

c <- v1alpha1.StoreBuildpack{
BuildpackInfo: info,
StoreImage: storeImage,
Buildpackage: packageInfo,
StoreImage: storeImageCopy,
Digest: digest.String(),
DiffId: metadata.LayerDiffID,
Size: size,
Expand Down
57 changes: 56 additions & 1 deletion pkg/cnb/remote_store_reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,19 @@ func testRemoteStoreReader(t *testing.T, when spec.G, it spec.S) {
}
}
`,
"io.buildpacks.buildpackage.metadata": //language=json
`{
"id": "org.buildpack.meta",
"version": "0.0.2",
"stacks": [
{
"id": "org.some.stack"
},
{
"id": "org.multi.only.stack"
}
]
}`,
})
require.NoError(t, err)

Expand Down Expand Up @@ -171,6 +184,19 @@ func testRemoteStoreReader(t *testing.T, when spec.G, it spec.S) {
}
}
`,
"io.buildpacks.buildpackage.metadata": //language=json
`{
"id": "org.buildpack.simple",
"version": "0.0.1",
"stacks": [
{
"id": "org.some.stack"
},
{
"id": "org.simple.only.stack"
}
]
}`,
})
require.NoError(t, err)

Expand All @@ -194,6 +220,10 @@ func testRemoteStoreReader(t *testing.T, when spec.G, it spec.S) {
Id: "org.buildpack.multi",
Version: "0.0.1",
},
Buildpackage: v1alpha1.BuildpackageInfo{
Id: "org.buildpack.meta",
Version: "0.0.2",
},
StoreImage: v1alpha1.StoreImage{
Image: buildpackageA,
},
Expand All @@ -217,6 +247,10 @@ func testRemoteStoreReader(t *testing.T, when spec.G, it spec.S) {
Id: "org.buildpack.multi",
Version: "0.0.2",
},
Buildpackage: v1alpha1.BuildpackageInfo{
Id: "org.buildpack.meta",
Version: "0.0.2",
},
StoreImage: v1alpha1.StoreImage{
Image: buildpackageA,
},
Expand All @@ -242,6 +276,10 @@ func testRemoteStoreReader(t *testing.T, when spec.G, it spec.S) {
Id: "org.buildpack.meta",
Version: "0.0.2",
},
Buildpackage: v1alpha1.BuildpackageInfo{
Id: "org.buildpack.meta",
Version: "0.0.2",
},
StoreImage: v1alpha1.StoreImage{
Image: buildpackageA,
},
Expand Down Expand Up @@ -288,6 +326,10 @@ func testRemoteStoreReader(t *testing.T, when spec.G, it spec.S) {
Id: "org.buildpack.simple",
Version: "0.0.1",
},
Buildpackage: v1alpha1.BuildpackageInfo{
Id: "org.buildpack.simple",
Version: "0.0.1",
},
DiffId: "sha256:1fe2cf74b742ec16c76b9e996c247c78aa41905fe86b744db998094b4bcaf38a",
Digest: "sha256:6aa3691a73805f608e5fce69fb6bc89aec8362f58a6b4be2682515e9cfa3cc1a",
Size: 40,
Expand Down Expand Up @@ -353,7 +395,7 @@ func testRemoteStoreReader(t *testing.T, when spec.G, it spec.S) {
"0.0.1": {
"layerDiffID": "sha256:1fe2cf74b742ec16c76b9e996c247c78aa41905fe86b744db998094b4bcaf38a",
"api": "0.2",
"homepage": "builpack.simple.com",
"homepage": "buildpack.simple.com",
"stacks": [
{
"id": "org.some.stack",
Expand All @@ -369,6 +411,19 @@ func testRemoteStoreReader(t *testing.T, when spec.G, it spec.S) {
}
}
`,
"io.buildpacks.buildpackage.metadata": //language=json
`{
"id": "org.buildpack.simple",
"version": "0.0.1",
"stacks": [
{
"id": "org.some.stack"
},
{
"id": "org.simple.only.stack"
}
]
}`,
})
require.NoError(t, err)

Expand Down

0 comments on commit de67384

Please sign in to comment.