Skip to content

Commit

Permalink
Support multiple buildpack apis simultaneously.
Browse files Browse the repository at this point in the history
- Supports multiple buildpack apis from buildpack rfc: https://github.com/buildpacks/rfcs/blob/main/text/0041-api-version-compat.md
- Includes multi-api lifecycle descriptor buildpacks/lifecycle#344
- go mod tidy
  • Loading branch information
matthewmcnew committed Aug 26, 2020
1 parent b1f6db5 commit f2635a1
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 33 deletions.
22 changes: 1 addition & 21 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -231,16 +231,8 @@ github.com/bshuster-repo/logrus-logstash-hook v0.4.1/go.mod h1:zsTqEiSzDgAa/8GZR
github.com/bugsnag/bugsnag-go v0.0.0-20141110184014-b1d153021fcd/go.mod h1:2oa8nejYd4cQ/b0hMIopN0lCRxU0bueqREvZLWFrtK8=
github.com/bugsnag/osext v0.0.0-20130617224835-0dd3f918b21b/go.mod h1:obH5gd0BsqsP2LwDJ9aOkm/6J86V6lyAXCoQWGw3K50=
github.com/bugsnag/panicwrap v0.0.0-20151223152923-e2c28503fcd0/go.mod h1:D/8v3kj0zr8ZAKg1AQ6crr+5VwKN5eIywRkfhyM/+dE=
github.com/buildpacks/imgutil v0.0.0-20200528211046-5c4cfa56bb24 h1:5JJD0uW/I2yfYyFqZZdZ4upgonr6q20WWvR1R53c7ec=
github.com/buildpacks/imgutil v0.0.0-20200528211046-5c4cfa56bb24/go.mod h1:rkRDOGpntpFhgj0gIUhQnEt5DYvi7xUTHkZWSxbWJP0=
github.com/buildpacks/imgutil v0.0.0-20200808231819-bedc3d0cd75a h1:VfNxNjP1Y5nM49gF2UkNTq5CoqELkmxdRUUYn8tZvj4=
github.com/buildpacks/imgutil v0.0.0-20200808231819-bedc3d0cd75a/go.mod h1:uVv0fNwOEBNgyM9ZvwV0g2Dvzk31q5TtSeoC1GGmW+k=
github.com/buildpacks/imgutil v0.0.0-20200814190540-04db0a9bb84f h1:obnRAv2tc0ANz20Muuz1ETaRaXe8f8WR6zNplXum2dc=
github.com/buildpacks/imgutil v0.0.0-20200814190540-04db0a9bb84f/go.mod h1:uVv0fNwOEBNgyM9ZvwV0g2Dvzk31q5TtSeoC1GGmW+k=
github.com/buildpacks/lifecycle v0.8.1 h1:sRyb9281MrrJNfuaQBTI8hu1ERz9iiYtaDmp5xm6VyQ=
github.com/buildpacks/lifecycle v0.8.1/go.mod h1:Spd3VyskOqUNXx76FKMRU3L3PLHxVGQBJ/JqXlFeLh8=
github.com/buildpacks/lifecycle v0.9.0 h1:AV7t614cnjJ6TJGf9H12TI0Ewqj16lQduGLlOt7J/Lo=
github.com/buildpacks/lifecycle v0.9.0/go.mod h1:Vxe/ZCnHhs+DY7eJvrtbNlT8nZyaHYAS+/1D2Q5mM4w=
github.com/buildpacks/lifecycle v0.9.1 h1:u6elaPmjWqBhwWb5sU+a9g84/p+a7AIHHPr33nH37s8=
github.com/buildpacks/lifecycle v0.9.1/go.mod h1:iST+Wdo9UR+TrVQGtTIBToRuh9K7IqqqTw6cB3coC9s=
github.com/bwmarrin/snowflake v0.0.0/go.mod h1:NdZxfVWX+oR6y2K0o6qAYv6gIOP9rjG0/E9WsDpxqwE=
Expand Down Expand Up @@ -535,6 +527,7 @@ github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt
github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
github.com/golang/mock v1.4.3 h1:GV+pQPG/EUUbkh47niozDcADz6go/dUwhVzdUQHIVRw=
github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
github.com/golang/mock v1.4.4 h1:l75CXGRSwbaYNpl/Z2X1XIIAMSCquvXgpVZDhwEIJsc=
github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4=
github.com/golang/protobuf v0.0.0-20161109072736-4bd1920723d7/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
Expand Down Expand Up @@ -835,8 +828,6 @@ github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNx
github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.10 h1:qxFzApOv4WsAL965uUPIsXzAKCZxN2p9UqdhFS4ZW10=
github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84=
github.com/mattn/go-isatty v0.0.11 h1:FxPOTFNqGkuDUGi3H/qkUbQO4ZiBa2brKq5r0l8TGeM=
github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE=
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
Expand Down Expand Up @@ -1386,7 +1377,6 @@ golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190922100055-0a153f010e69/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191010194322-b09406accb47 h1:/XfQ9z7ib8eEJX2hdgFTZJ/ntt0swNk5oYBziWeTCvY=
golang.org/x/sys v0.0.0-20191010194322-b09406accb47/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down Expand Up @@ -1711,8 +1701,6 @@ k8s.io/api v0.17.2/go.mod h1:BS9fjjLc4CMuqfSO8vgbHPKMt5+SF0ET6u/RVDihTo4=
k8s.io/api v0.17.3/go.mod h1:YZ0OTkuw7ipbe305fMpIdf3GLXZKRigjtZaV5gzC2J0=
k8s.io/api v0.17.4 h1:HbwOhDapkguO8lTAE8OX3hdF2qp8GtpC9CW/MQATXXo=
k8s.io/api v0.17.4/go.mod h1:5qxx6vjmwUVG2nHQTKGlLts8Tbok8PzHl4vHtVFuZCA=
k8s.io/api v0.17.5 h1:EkVieIbn1sC8YCDwckLKLpf+LoVofXYW72+LTZWo4aQ=
k8s.io/api v0.17.5/go.mod h1:0zV5/ungglgy2Rlm3QK8fbxkXVs+BSJWpJP/+8gUVLY=
k8s.io/api v0.17.6 h1:S6qZSkjdOU0N/TYBZKoR1o7YVSiWMGFU0XXDoqs2ioA=
k8s.io/api v0.17.6/go.mod h1:1jKVwkj0UZ4huak/yRt3MFfU5wc32+B41SkNN5HhyFg=
k8s.io/apiextensions-apiserver v0.17.2/go.mod h1:4KdMpjkEjjDI2pPfBA15OscyNldHWdBCfsWMDWAmSTs=
Expand All @@ -1725,8 +1713,6 @@ k8s.io/apimachinery v0.17.2/go.mod h1:b9qmWdKlLuU9EBh+06BtLcSf/Mu89rWL33naRxs1uZ
k8s.io/apimachinery v0.17.3/go.mod h1:gxLnyZcGNdZTCLnq3fgzyg2A5BVCHTNDFrw8AmuJ+0g=
k8s.io/apimachinery v0.17.4 h1:UzM+38cPUJnzqSQ+E1PY4YxMHIzQyCg29LOoGfo79Zw=
k8s.io/apimachinery v0.17.4/go.mod h1:gxLnyZcGNdZTCLnq3fgzyg2A5BVCHTNDFrw8AmuJ+0g=
k8s.io/apimachinery v0.17.5 h1:QAjfgeTtSGksdkgyaPrIb4lhU16FWMIzxKejYD5S0gc=
k8s.io/apimachinery v0.17.5/go.mod h1:ioIo1G/a+uONV7Tv+ZmCbMG1/a3kVw5YcDdncd8ugQ0=
k8s.io/apimachinery v0.17.6 h1:P0MNfucrmKLPsOSRbhDuG0Tplrpg7hVY4fJHh5sUIUw=
k8s.io/apimachinery v0.17.6/go.mod h1:Lg8zZ5iC/O8UjCqW6DNhcQG2m4TdjF9kwG3891OWbbA=
k8s.io/apiserver v0.17.0/go.mod h1:ABM+9x/prjINN6iiffRVNCBR2Wk7uY4z+EtEGZD48cg=
Expand All @@ -1735,14 +1721,10 @@ k8s.io/apiserver v0.17.4/go.mod h1:5ZDQ6Xr5MNBxyi3iUZXS84QOhZl+W7Oq2us/29c0j9I=
k8s.io/apiserver v0.17.6/go.mod h1:sAYqm8hUDNA9aj/TzqwsJoExWrxprKv0tqs/z88qym0=
k8s.io/cli-runtime v0.17.2/go.mod h1:aa8t9ziyQdbkuizkNLAw3qe3srSyWh9zlSB7zTqRNPI=
k8s.io/cli-runtime v0.17.3/go.mod h1:X7idckYphH4SZflgNpOOViSxetiMj6xI0viMAjM81TA=
k8s.io/client-go v0.17.5 h1:Sm/9AQ415xPAX42JLKbJZnreXFgD2rVfDUDwOTm0gzA=
k8s.io/client-go v0.17.5/go.mod h1:S8uZpBpjJJdEH/fEyxcqg7Rn0P5jH+ilkgBHjriSmNo=
k8s.io/client-go v0.17.6 h1:W/JkbAcIZUPb9vENRTC75ymjQQO3qEJAZyYhOIEOifM=
k8s.io/client-go v0.17.6/go.mod h1:tX5eAbQR/Kbqv+5R93rzHQoyRnPjjW2mm9i0lXnW218=
k8s.io/cloud-provider v0.17.0/go.mod h1:Ze4c3w2C0bRsjkBUoHpFi+qWe3ob1wI2/7cUn+YQIDE=
k8s.io/cloud-provider v0.17.4/go.mod h1:XEjKDzfD+b9MTLXQFlDGkk6Ho8SGMpaU8Uugx/KNK9U=
k8s.io/code-generator v0.17.5 h1:JKh5hYOFb0cTls9mce3ZC4DWh01/nLEgqj8OSJBpVRw=
k8s.io/code-generator v0.17.5/go.mod h1:qdiSCSTKtS+3WtPelj2h57fylSQcPUlhMVm+TD9Dvqc=
k8s.io/code-generator v0.17.6 h1:2e0zgYsJmkc66HHEq7MoG1HgCEDCYLT08Y4VBcdzTkk=
k8s.io/code-generator v0.17.6/go.mod h1:iiHz51+oTx+Z9D0vB3CH3O4HDDPWrvZyUgUYaIE9h9M=
k8s.io/component-base v0.17.0/go.mod h1:rKuRAokNMY2nn2A6LP/MiwpoaMRHpfRnrPaUJJj1Yoc=
Expand All @@ -1766,8 +1748,6 @@ k8s.io/klog v1.0.0/go.mod h1:4Bi6QPql/J/LkTDqv7R/cd3hPo4k2DG6Ptcz060Ez5I=
k8s.io/kube-openapi v0.0.0-20190228160746-b3a7cee44a30/go.mod h1:BXM9ceUBTj2QnfH2MK1odQs778ajze1RxcmP6S8RVVc=
k8s.io/kube-openapi v0.0.0-20191107075043-30be4d16710a h1:UcxjrRMyNx/i/y8G7kPvLyy7rfbeuf1PYyBf973pgyU=
k8s.io/kube-openapi v0.0.0-20191107075043-30be4d16710a/go.mod h1:1TqjTSzOxsLGIKfj0lK8EeCP7K1iUG65v09OM0/WG5E=
k8s.io/kube-openapi v0.0.0-20200316234421-82d701f24f9d h1:jocF7XFucw2pEiv2wS7wk2FRFCjDFGV1oa4TMs0SAT0=
k8s.io/kube-openapi v0.0.0-20200316234421-82d701f24f9d/go.mod h1:F+5wygcW0wmRTnM3cOgIqGivxkwSWIWT5YdsDbeAOaU=
k8s.io/kube-openapi v0.0.0-20200410145947-bcb3869e6f29 h1:NeQXVJ2XFSkRoPzRo8AId01ZER+j8oV4SZADT4iBOXQ=
k8s.io/kube-openapi v0.0.0-20200410145947-bcb3869e6f29/go.mod h1:F+5wygcW0wmRTnM3cOgIqGivxkwSWIWT5YdsDbeAOaU=
k8s.io/kubectl v0.17.2/go.mod h1:y4rfLV0n6aPmvbRCqZQjvOp3ezxsFgpqL+zF5jH/lxk=
Expand Down
10 changes: 10 additions & 0 deletions hack/lifecycle/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ func main() {
BuildpackVersion: "0.2",
PlatformVersion: "0.3",
},
APIs: cnb.LifecycleAPIs{
Buildpack: cnb.APIVersions{
Deprecated: []string{},
Supported: []string{"0.2", "0.3", "0.4"},
},
Platform: cnb.APIVersions{
Deprecated: []string{},
Supported: []string{"0.3", "0.4"},
},
},
},
)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/cnb/builder_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,11 @@ func (bb *builderBlder) WriteableImage() (v1.Image, error) {
}

func (bb *builderBlder) validateBuilder(sortedBuildpacks []DescriptiveBuildpackInfo) error {
buildpackApi := bb.LifecycleMetadata.API.BuildpackVersion
buildpackApis := append(bb.LifecycleMetadata.APIs.Buildpack.Deprecated, bb.LifecycleMetadata.APIs.Buildpack.Supported...)

for _, bpInfo := range sortedBuildpacks {
bpLayerInfo := bb.buildpackLayers[bpInfo].BuildpackLayerInfo
err := bpLayerInfo.supports(buildpackApi, bb.stackId, bb.mixins)
err := bpLayerInfo.supports(buildpackApis, bb.stackId, bb.mixins)
if err != nil {
return errors.Wrapf(err, "validating buildpack %s", bpInfo)
}
Expand Down
17 changes: 16 additions & 1 deletion pkg/cnb/buildpack_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ type CreatorMetadata struct {

type LifecycleMetadata struct {
LifecycleInfo
API LifecycleAPI `json:"api,omitempty"`

// Deprecated: Use `LifecycleAPIs` instead
API LifecycleAPI `json:"api,omitempty"`
APIs LifecycleAPIs `json:"apis,omitempty"`
}

type LifecycleDescriptor struct {
Expand All @@ -70,6 +73,18 @@ type LifecycleAPI struct {
PlatformVersion string `toml:"platform" json:"platform,omitempty"`
}

type LifecycleAPIs struct {
Buildpack APIVersions `toml:"buildpack" json:"buildpack"`
Platform APIVersions `toml:"platform" json:"platform"`
}

type APIVersions struct {
Deprecated APISet `toml:"deprecated" json:"deprecated"`
Supported APISet `toml:"supported" json:"supported"`
}

type APISet []string

type BuiltImageStack struct {
RunImage string
ID string
Expand Down
6 changes: 3 additions & 3 deletions pkg/cnb/buildpack_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import (
"github.com/pkg/errors"
)

func (bl BuildpackLayerInfo) supports(buildpackApi string, id string, mixins []string) error {
func (bl BuildpackLayerInfo) supports(buildpackApis []string, id string, mixins []string) error {
if len(bl.Order) != 0 {
return nil //ignore meta-buildpacks
}

if bl.API != buildpackApi {
return errors.Errorf("unsupported buildpack api: %s, expecting %s", buildpackApi, bl.API)
if !present(buildpackApis, bl.API) {
return errors.Errorf("unsupported buildpack api: %s, expecting: %s", bl.API, strings.Join(buildpackApis, ", "))
}

for _, s := range bl.Stacks {
Expand Down
32 changes: 26 additions & 6 deletions pkg/cnb/create_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func testCreateBuilder(t *testing.T, when spec.G, it spec.S) {
Homepage: "buildpack.3.com",
},
BuildpackLayerInfo: BuildpackLayerInfo{
API: "0.2",
API: "0.3",
LayerDiffID: buildpack3Layer.diffID,
Stacks: []v1alpha1.BuildpackStack{
{
Expand All @@ -190,7 +190,7 @@ func testCreateBuilder(t *testing.T, when spec.G, it spec.S) {
Homepage: "buildpack.2.com",
},
BuildpackLayerInfo: BuildpackLayerInfo{
API: "0.2",
API: "0.3",
LayerDiffID: buildpack2Layer.diffID,
Order: v1alpha1.Order{
{
Expand Down Expand Up @@ -232,6 +232,16 @@ func testCreateBuilder(t *testing.T, when spec.G, it spec.S) {
BuildpackVersion: "0.2",
PlatformVersion: "0.1",
},
APIs: LifecycleAPIs{
Buildpack: APIVersions{
Deprecated: []string{"0.2"},
Supported: []string{"0.3"},
},
Platform: APIVersions{
Deprecated: []string{"0.1"},
Supported: []string{"0.2"},
},
},
},
})
require.NoError(t, err)
Expand Down Expand Up @@ -402,6 +412,16 @@ func testCreateBuilder(t *testing.T, when spec.G, it spec.S) {
"api": {
"buildpack": "0.2",
"platform": "0.1"
},
"apis": {
"buildpack": {
"deprecated": ["0.2"],
"supported": ["0.3"]
},
"platform": {
"deprecated": ["0.1"],
"supported": ["0.2"]
}
}
},
"createdBy": {
Expand Down Expand Up @@ -445,7 +465,7 @@ func testCreateBuilder(t *testing.T, when spec.G, it spec.S) {
},
"io.buildpack.2": {
"v2": {
"api": "0.2",
"api": "0.3",
"layerDiffID": "sha256:2bf8899667b8d1e6b124f663faca32903b470831e5e4e992644ac5c839ab3462",
"order": [
{
Expand All @@ -461,7 +481,7 @@ func testCreateBuilder(t *testing.T, when spec.G, it spec.S) {
},
"io.buildpack.3": {
"v3": {
"api": "0.2",
"api": "0.3",
"layerDiffID": "sha256:3bf8899667b8d1e6b124f663faca32903b470831e5e4e992644ac5c839ab3462",
"stacks": [
{
Expand Down Expand Up @@ -584,7 +604,7 @@ func testCreateBuilder(t *testing.T, when spec.G, it spec.S) {
Homepage: "buildpack.4.com",
},
BuildpackLayerInfo: BuildpackLayerInfo{
API: "0.3",
API: "0.1",
LayerDiffID: buildpack1Layer.diffID,
Stacks: []v1alpha1.BuildpackStack{
{
Expand All @@ -609,7 +629,7 @@ func testCreateBuilder(t *testing.T, when spec.G, it spec.S) {
}

_, err := subject.CreateBuilder(keychain, buildpackRepository, stack, clusterBuilderSpec)
require.EqualError(t, err, "validating buildpack io.buildpack.unsupported.buildpack.api@v4: unsupported buildpack api: 0.2, expecting 0.3")
require.EqualError(t, err, "validating buildpack io.buildpack.unsupported.buildpack.api@v4: unsupported buildpack api: 0.1, expecting: 0.2, 0.3")
})

})
Expand Down

0 comments on commit f2635a1

Please sign in to comment.