Skip to content

Commit

Permalink
wip: internal compat changes
Browse files Browse the repository at this point in the history
Signed-off-by: Javier Romero <rjavier@vmware.com>
  • Loading branch information
jromero committed Aug 10, 2020
1 parent 3a3bf28 commit 2e33ea0
Show file tree
Hide file tree
Showing 65 changed files with 501 additions and 626 deletions.
10 changes: 0 additions & 10 deletions acceptance/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -775,8 +775,6 @@ func testAcceptance(
"base_image_top_layer": h.TopLayerDiffID(t, runImageMirror),
"run_image_local_mirror": localRunImageMirror,
"run_image_mirror": runImageMirror,
"show_reference": lifecycle.ShouldShowReference(),
"show_processes": lifecycle.ShouldShowProcesses(),
},
)

Expand Down Expand Up @@ -973,12 +971,6 @@ func testAcceptance(

when("--default-process", func() {
it("sets the default process from those in the process list", func() {
h.SkipUnless(t, pack.Supports("build --default-process"), "--default-process flag is not supported")
h.SkipUnless(t,
lifecycle.SupportsFeature(config.DefaultProcess),
"skipping default process. Lifecycle does not support it",
)

pack.RunSuccessfully(
"build", repoName,
"--default-process", "hello",
Expand Down Expand Up @@ -1360,8 +1352,6 @@ func testAcceptance(
"base_image_ref": strings.Join([]string{runImageMirror, h.Digest(t, runImageMirror)}, "@"),
"base_image_top_layer": h.TopLayerDiffID(t, runImageMirror),
"run_image_mirror": runImageMirror,
"show_reference": lifecycle.ShouldShowReference(),
"show_processes": lifecycle.ShouldShowReference(),
},
)

Expand Down
3 changes: 2 additions & 1 deletion acceptance/config/asset_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import (
"regexp"
"testing"

"github.com/buildpacks/lifecycle/api"

acceptanceOS "github.com/buildpacks/pack/acceptance/os"
"github.com/buildpacks/pack/internal/api"
"github.com/buildpacks/pack/internal/blob"
"github.com/buildpacks/pack/internal/builder"
"github.com/buildpacks/pack/internal/style"
Expand Down
22 changes: 1 addition & 21 deletions acceptance/config/lifecycle_asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,42 +58,22 @@ func (l *LifecycleAsset) ShouldShowReference() bool {
return !l.SemVer().LessThan(semver.MustParse("0.5.0"))
}

func (l *LifecycleAsset) ShouldShowProcesses() bool {
return !l.pre060()
}

type LifecycleFeature int

const (
DefaultProcess LifecycleFeature = iota
CreatorInLifecycle
DetailedCacheLogging
CreatorInLifecycle LifecycleFeature = iota
)

var lifecycleFeatureTests = map[LifecycleFeature]func(l *LifecycleAsset) bool{
DefaultProcess: func(l *LifecycleAsset) bool {
return l.atLeast070()
},
CreatorInLifecycle: func(l *LifecycleAsset) bool {
return l.atLeast074()
},
DetailedCacheLogging: func(l *LifecycleAsset) bool {
return !l.pre060()
},
}

func (l *LifecycleAsset) SupportsFeature(f LifecycleFeature) bool {
return lifecycleFeatureTests[f](l)
}

func (l *LifecycleAsset) pre060() bool {
return l.SemVer().LessThan(semver.MustParse("0.6.0"))
}

func (l *LifecycleAsset) atLeast070() bool {
return !l.SemVer().LessThan(semver.MustParse("0.7.0"))
}

func (l *LifecycleAsset) atLeast074() bool {
return !l.SemVer().LessThan(semver.MustParse("0.7.4"))
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ LOCAL:
Stack: pack.test.stack

Base Image:
{{- if .show_reference}}
Reference: {{.base_image_id}}
{{- end }}
Top Layer: {{.base_image_top_layer}}

Run Images:
Expand All @@ -21,11 +19,9 @@ Run Images:
Buildpacks:
ID VERSION
simple/layers simple-layers-version
{{- if .show_processes}}

Processes:
TYPE SHELL COMMAND ARGS
web (default) bash ./run 8080
hello echo hello world
{{- end }}

Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ REMOTE:
Stack: pack.test.stack

Base Image:
{{- if .show_reference}}
Reference: {{.base_image_ref}}
{{- end }}
Top Layer: {{.base_image_top_layer}}

Run Images:
Expand All @@ -17,23 +15,19 @@ Run Images:
Buildpacks:
ID VERSION
simple/layers simple-layers-version
{{- if .show_processes}}

Processes:
TYPE SHELL COMMAND ARGS
web (default) bash ./run 8080
hello echo hello world
{{- end }}


LOCAL:

Stack: pack.test.stack

Base Image:
{{- if .show_reference}}
Reference: {{.base_image_ref}}
{{- end }}
Top Layer: {{.base_image_top_layer}}

Run Images:
Expand All @@ -43,11 +37,9 @@ Run Images:
Buildpacks:
ID VERSION
simple/layers simple-layers-version
{{- if .show_processes}}

Processes:
TYPE SHELL COMMAND ARGS
web (default) bash ./run 8080
hello echo hello world
{{- end }}

34 changes: 22 additions & 12 deletions build.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"github.com/google/go-containerregistry/pkg/name"
"github.com/pkg/errors"

"github.com/buildpacks/pack/internal/api"
"github.com/buildpacks/pack/internal/archive"
"github.com/buildpacks/pack/internal/build"
"github.com/buildpacks/pack/internal/builder"
Expand Down Expand Up @@ -127,17 +126,14 @@ func (c *Client) Build(ctx context.Context, opts BuildOptions) error {
}
defer c.docker.ImageRemove(context.Background(), ephemeralBuilder.Name(), types.ImageRemoveOptions{Force: true})

lcPlatformAPIVersion := ephemeralBuilder.LifecycleDescriptor().API.PlatformVersion
supportsPlatform := false
for _, v := range build.SupportedPlatformAPIVersions {
if api.MustParse(v).SupportsVersion(lcPlatformAPIVersion) {
supportsPlatform = true
break
}
}
if !supportsPlatform {
c.logger.Debugf("pack %s supports Platform API version(s): %s", Version, strings.Join(build.SupportedPlatformAPIVersions, ", "))
c.logger.Debugf("Builder %s has Platform API version: %s", style.Symbol(opts.Builder), lcPlatformAPIVersion)
builderPlatformAPIs := append(
ephemeralBuilder.LifecycleDescriptor().APIs.Platform.Deprecated,
ephemeralBuilder.LifecycleDescriptor().APIs.Platform.Supported...,
)

if !supportsPlatformAPI(builderPlatformAPIs) {
c.logger.Debugf("pack %s supports Platform API(s): %s", Version, strings.Join(build.SupportedPlatformAPIVersions.AsStrings(), ", "))
c.logger.Debugf("Builder %s supports Platform API(s): %s", style.Symbol(opts.Builder), strings.Join(builderPlatformAPIs.AsStrings(), ", "))
return errors.Errorf("Builder %s is incompatible with this version of pack", style.Symbol(opts.Builder))
}

Expand Down Expand Up @@ -208,6 +204,20 @@ func (c *Client) Build(ctx context.Context, opts BuildOptions) error {
return nil
}

// supportsPlatformAPI determines whether pack can build using the builder based on the builder's supported Platform API versions.
func supportsPlatformAPI(builderPlatformAPIs builder.APISet) bool {
for _, packSupportedAPI := range build.SupportedPlatformAPIVersions {
for _, builderSupportedAPI := range builderPlatformAPIs {
supportsPlatform := packSupportedAPI.Compare(builderSupportedAPI) == 0
if supportsPlatform {
return true
}
}
}

return false
}

func (c *Client) processBuilderName(builderName string) (name.Reference, error) {
if builderName == "" {
return nil, errors.New("builder is a required parameter if the client has no default builder")
Expand Down
34 changes: 23 additions & 11 deletions build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ import (

"github.com/Masterminds/semver"
"github.com/buildpacks/imgutil/fakes"
"github.com/buildpacks/lifecycle/api"
"github.com/docker/docker/client"
"github.com/heroku/color"
"github.com/onsi/gomega/ghttp"
"github.com/sclevine/spec"
"github.com/sclevine/spec/report"

"github.com/buildpacks/pack/internal/api"
"github.com/buildpacks/pack/internal/blob"
"github.com/buildpacks/pack/internal/build"
"github.com/buildpacks/pack/internal/builder"
Expand Down Expand Up @@ -330,9 +330,13 @@ func testBuild(t *testing.T, when spec.G, it spec.S) {
Version: *semver.MustParse(builder.DefaultLifecycleVersion),
},
},
API: builder.LifecycleAPI{
BuildpackVersion: api.MustParse("0.3"),
PlatformVersion: api.MustParse("0.2"),
APIs: &builder.LifecycleAPIs{
Buildpack: builder.APIVersions{
Supported: builder.APISet{api.MustParse("0.2"), api.MustParse("0.3"), api.MustParse("0.4")},
},
Platform: builder.APIVersions{
Supported: builder.APISet{api.MustParse("0.3"), api.MustParse("0.4")},
},
},
},
},
Expand Down Expand Up @@ -1596,7 +1600,7 @@ func testBuild(t *testing.T, when spec.G, it spec.S) {

when("Lifecycle option", func() {
when("Platform API", func() {
for _, supportedPlatformAPI := range []string{"0.2", "0.3"} {
for _, supportedPlatformAPI := range []string{"0.3", "0.4"} {
var (
supportedPlatformAPI = supportedPlatformAPI
compatibleBuilder *fakes.Image
Expand Down Expand Up @@ -1626,9 +1630,13 @@ func testBuild(t *testing.T, when spec.G, it spec.S) {
Version: *semver.MustParse(builder.DefaultLifecycleVersion),
},
},
API: builder.LifecycleAPI{
BuildpackVersion: api.MustParse("0.3"),
PlatformVersion: api.MustParse(supportedPlatformAPI),
APIs: &builder.LifecycleAPIs{
Buildpack: builder.APIVersions{
Supported: builder.APISet{api.MustParse("0.2"), api.MustParse("0.3"), api.MustParse("0.4")},
},
Platform: builder.APIVersions{
Supported: builder.APISet{api.MustParse(supportedPlatformAPI)},
},
},
},
},
Expand Down Expand Up @@ -1889,9 +1897,13 @@ func newFakeBuilderImage(t *testing.T, tmpDir, builderName, defaultBuilderStackI
Version: *semver.MustParse(lifecycleVersion),
},
},
API: builder.LifecycleAPI{
BuildpackVersion: api.MustParse("0.3"),
PlatformVersion: api.MustParse("0.2"),
APIs: &builder.LifecycleAPIs{
Buildpack: builder.APIVersions{
Supported: builder.APISet{api.MustParse("0.2"), api.MustParse("0.3"), api.MustParse("0.4")},
},
Platform: builder.APIVersions{
Supported: builder.APISet{api.MustParse("0.3"), api.MustParse("0.4")},
},
},
},
},
Expand Down
Loading

0 comments on commit 2e33ea0

Please sign in to comment.