Skip to content

Commit

Permalink
Merge branch 'main' into runext/pack-build-1620
Browse files Browse the repository at this point in the history
  • Loading branch information
natalieparellano committed Apr 13, 2023
2 parents 15e52db + 28d211d commit 92d0380
Show file tree
Hide file tree
Showing 42 changed files with 753 additions and 337 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@ Detection Order:
│ └ simple/nested-level-2@nested-l2-version
└ read/env@read-env-version (optional)

Extensions:
(none)

Detection Order (Extensions):
(none)

LOCAL:

Created By:
Expand Down Expand Up @@ -97,9 +91,3 @@ Detection Order:
│ └ Group #1:
│ └ simple/nested-level-2@nested-l2-version
└ read/env@read-env-version (optional)

Extensions:
(none)

Detection Order (Extensions):
(none)
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,6 @@ Detection Order:
│ └ simple/layers@simple-layers-version
└ read/env@read-env-version (optional)

Extensions:
(none)

Detection Order (Extensions):
(none)

LOCAL:

Created By:
Expand Down Expand Up @@ -101,9 +95,3 @@ Detection Order:
│ └ Group #1:
│ └ simple/layers@simple-layers-version
└ read/env@read-env-version (optional)

Extensions:
(none)

Detection Order (Extensions):
(none)
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@
}
]
}
],
"extensions": null,
"order_extensions": null
]
},
"local_info": {
"created_by": {
Expand Down Expand Up @@ -196,8 +194,6 @@
}
]
}
],
"extensions": null,
"order_extensions": null
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ remote_info:
- id: read/env
version: read-env-version
optional: true
extensions: []
order_extensions: []
local_info:
created_by:
name: Pack CLI
Expand Down Expand Up @@ -116,5 +114,3 @@ local_info:
- id: read/env
version: read-env-version
optional: true
extensions: []
order_extensions: []
12 changes: 0 additions & 12 deletions acceptance/testdata/pack_fixtures/inspect_builder_output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,6 @@ Detection Order:
├ simple/layers
└ read/env@read-env-version (optional)

Extensions:
(none)

Detection Order (Extensions):
(none)

LOCAL:

Created By:
Expand Down Expand Up @@ -89,9 +83,3 @@ Detection Order:
└ Group #1:
├ simple/layers
└ read/env@read-env-version (optional)

Extensions:
(none)

Detection Order (Extensions):
(none)
1 change: 0 additions & 1 deletion cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ func NewPackCommand(logger ConfigurableLogger) (*cobra.Command, error) {
rootCmd.AddCommand(commands.ListTrustedBuilders(logger, cfg))
rootCmd.AddCommand(commands.CreateBuilder(logger, cfg, packClient))
rootCmd.AddCommand(commands.PackageBuildpack(logger, cfg, packClient, buildpackage.NewConfigReader()))
rootCmd.AddCommand(commands.SuggestStacks(logger))

if cfg.Experimental {
rootCmd.AddCommand(commands.AddBuildpackRegistry(logger, cfg, cfgPath))
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ require (
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06
github.com/sclevine/spec v1.4.0
github.com/spf13/cobra v1.7.0
golang.org/x/crypto v0.7.0
golang.org/x/crypto v0.8.0
golang.org/x/mod v0.10.0
golang.org/x/oauth2 v0.6.0
golang.org/x/oauth2 v0.7.0
golang.org/x/sync v0.1.0
golang.org/x/term v0.7.0
golang.org/x/text v0.9.0
Expand Down Expand Up @@ -113,7 +113,7 @@ require (
github.com/spf13/pflag v1.0.5 // indirect
github.com/vbatts/tar-split v0.11.2 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/net v0.9.0 // indirect
golang.org/x/sys v0.7.0 // indirect
golang.org/x/tools v0.7.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,8 @@ golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0
golang.org/x/crypto v0.0.0-20220826181053-bd7e27e6170d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw=
golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58=
golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A=
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
golang.org/x/crypto v0.8.0 h1:pd9TJtTueMTVQXzk8E2XESSMQDj/U7OUu0PqJqPXQjQ=
golang.org/x/crypto v0.8.0/go.mod h1:mRqEX+O9/h5TFCrQhkgjo2yKi0yYA+9ecGkdQoHrywE=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
Expand All @@ -385,11 +385,11 @@ golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b/go.mod h1:YDH+HFinaLZZlnHAfS
golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ=
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
golang.org/x/net v0.9.0 h1:aWJ/m6xSmxWBx+V0XRHTlrYrPG56jKsLdTFmsSsCzOM=
golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.6.0 h1:Lh8GPgSKBfWSwFvtuWOfeI3aAAnbXTSutYxJiOJFgIw=
golang.org/x/oauth2 v0.6.0/go.mod h1:ycmewcwgD4Rpr3eZJLSB4Kyyljb3qDh40vJ8STE5HKw=
golang.org/x/oauth2 v0.7.0 h1:qe6s0zUXlPX80/dITx3440hWZ7GwMwgDDyrSGTPJG/g=
golang.org/x/oauth2 v0.7.0/go.mod h1:hPLQkd9LyjfXTiRohC/41GhcFqxisoUQ99sCUOHO9x4=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down
60 changes: 47 additions & 13 deletions internal/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import (
"github.com/buildpacks/pack/pkg/buildpack"
"github.com/buildpacks/pack/pkg/dist"
"github.com/buildpacks/pack/pkg/logging"

lifecycleplatform "github.com/buildpacks/lifecycle/platform"
)

const (
Expand Down Expand Up @@ -234,9 +236,16 @@ func (b *Builder) Stack() StackMetadata {
return b.metadata.Stack
}

// RunImages returns the run image metadata
// RunImages returns all run image metadata
func (b *Builder) RunImages() []RunImageMetadata {
return b.metadata.RunImages
return append(b.metadata.RunImages, b.Stack().RunImage)
}

// DefaultRunImage returns the default run image metadata
func (b *Builder) DefaultRunImage() RunImageMetadata {
// run.images are ensured in builder.ValidateConfig()
// per the spec, we use the first one as the default
return b.RunImages()[0]
}

// Mixins returns the mixins of the builder
Expand Down Expand Up @@ -360,7 +369,7 @@ func (b *Builder) Save(logger logging.Logger, creatorMetadata CreatorMetadata) e
}
}

if err := validateBuildpacks(b.StackID, b.Mixins(), b.LifecycleDescriptor(), b.Buildpacks(), b.additionalBuildpacks); err != nil {
if err := b.validateBuildpacks(); err != nil {
return errors.Wrap(err, "validating buildpacks")
}

Expand Down Expand Up @@ -633,24 +642,20 @@ func hasElementWithVersion(moduleList []dist.ModuleInfo, version string) bool {
return false
}

func validateBuildpacks(stackID string, mixins []string, lifecycleDescriptor LifecycleDescriptor, allBuildpacks []dist.ModuleInfo, bpsToValidate []buildpack.BuildModule) error {
func (b *Builder) validateBuildpacks() error {
bpLookup := map[string]interface{}{}

for _, bp := range allBuildpacks {
for _, bp := range b.Buildpacks() {
bpLookup[bp.FullName()] = nil
}

for _, bp := range bpsToValidate {
for _, bp := range b.additionalBuildpacks {
bpd := bp.Descriptor()
if err := validateLifecycleCompat(bpd, lifecycleDescriptor); err != nil {
if err := validateLifecycleCompat(bpd, b.LifecycleDescriptor()); err != nil {
return err
}

if len(bpd.Stacks()) >= 1 { // standard buildpack
if err := bpd.EnsureStackSupport(stackID, mixins, false); err != nil {
return err
}
} else { // order buildpack
if len(bpd.Order()) > 0 { // order buildpack
for _, g := range bpd.Order() {
for _, r := range g.Group {
if _, ok := bpLookup[r.FullName()]; !ok {
Expand All @@ -661,6 +666,30 @@ func validateBuildpacks(stackID string, mixins []string, lifecycleDescriptor Lif
}
}
}
} else if err := bpd.EnsureStackSupport(b.StackID, b.Mixins(), false); err != nil {
return err
} else {
buildOS, err := b.Image().OS()
if err != nil {
return err
}
buildArch, err := b.Image().Architecture()
if err != nil {
return err
}
buildDistroName, err := b.Image().Label(lifecycleplatform.OSDistributionNameLabel)
if err != nil {
return err
}
buildDistroVersion, err := b.Image().Label(lifecycleplatform.OSDistributionVersionLabel)
if err != nil {
return err
}
if err := bpd.EnsureTargetSupport(buildOS, buildArch, buildDistroName, buildDistroVersion); err != nil {
return err
}

// TODO ensure at least one run-image
}
}

Expand Down Expand Up @@ -903,7 +932,12 @@ func orderFileContents(order dist.Order, orderExt dist.Order) (string, error) {

func (b *Builder) stackLayer(dest string) (string, error) {
buf := &bytes.Buffer{}
err := toml.NewEncoder(buf).Encode(b.metadata.Stack)
var err error
if b.metadata.Stack.RunImage.Image != "" {
err = toml.NewEncoder(buf).Encode(b.metadata.Stack)
} else if len(b.metadata.RunImages) > 0 {
err = toml.NewEncoder(buf).Encode(b.metadata.RunImages[0])
}
if err != nil {
return "", errors.Wrapf(err, "failed to marshal stack.toml")
}
Expand Down
25 changes: 21 additions & 4 deletions internal/builder/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -766,10 +766,10 @@ func testBuilder(t *testing.T, when spec.G, it spec.S) {
// - 1 from stackLayer
// - 1 from runImageLayer
h.AssertEq(t, baseImage.NumberOfAddedLayers(), 6)
oldSha256 := "4dc0072c61fc2bd7118bbc93a432eae0012082de094455cf0a9fed20e3c44789"
newSha256 := "29cb2bce4c2350f0e86f3dd30fa3810beb409b910126a18651de750f457fedfb"
oldSha256 := "2ba2e8563f7f43533ba26047a44f3e8bb7dd009043bd73a0e6aadb02c084955c"
newSha256 := "719faea06424d01bb5788ce63c1167e8d382b2d9df8fcf3a0a54ea9b2e3b4045"
if runtime.GOOS == "windows" {
newSha256 = "eaed4a1617bba5738ae5672f6aefda8add7abb2f8630c75dc97a6232879d4ae4"
newSha256 = "d99d31efba72ebf98e8101ada9e89464566e943c05367c561b116c2cb86837c9"
}

h.AssertContains(t, outBuf.String(), fmt.Sprintf(`buildpack 'buildpack-1-id@buildpack-1-version-1' was previously defined with different contents and will be overwritten
Expand All @@ -794,7 +794,7 @@ func testBuilder(t *testing.T, when spec.G, it spec.S) {
when("adding buildpack that already exists on the image", func() {
it("skips adding buildpack that already exists", func() {
logger := logging.NewLogWithWriters(&outBuf, &outBuf, logging.WithVerbose())
diffID := "4dc0072c61fc2bd7118bbc93a432eae0012082de094455cf0a9fed20e3c44789"
diffID := "2ba2e8563f7f43533ba26047a44f3e8bb7dd009043bd73a0e6aadb02c084955c"
bpLayer := dist.ModuleLayers{
"buildpack-1-id": map[string]dist.ModuleLayerInfo{
"buildpack-1-version-1": {
Expand Down Expand Up @@ -1618,6 +1618,23 @@ func testBuilder(t *testing.T, when spec.G, it spec.S) {
)
})
})

when("#DefaultRunImage", func() {
it.Before(func() {
subject.SetRunImage(pubbldr.RunConfig{Images: []pubbldr.RunImageConfig{{
Image: "some/run",
Mirrors: []string{"some/mirror", "other/mirror"},
}}})
h.AssertNil(t, subject.Save(logger, builder.CreatorMetadata{}))
h.AssertEq(t, baseImage.IsSaved(), true)
})

it("adds the run.toml to the image", func() {
actual := subject.DefaultRunImage()
h.AssertEq(t, actual.Image, "some/run")
h.AssertEq(t, actual.Mirrors, []string{"some/mirror", "other/mirror"})
})
})
})

when("builder exists", func() {
Expand Down
28 changes: 23 additions & 5 deletions internal/builder/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ type Info struct {
Description string
StackID string
Mixins []string
RunImage string
RunImageMirrors []string
RunImages []pubbldr.RunImageConfig
Buildpacks []dist.ModuleInfo
Order pubbldr.DetectionOrder
BuildpackLayers dist.ModuleLayers
Expand Down Expand Up @@ -80,7 +79,7 @@ func (i *Inspector) Inspect(name string, daemon bool, orderDetectionDepth int) (

stackID, err := labelManager.StackID()
if err != nil {
return Info{}, fmt.Errorf("reading image stack id: %w", err)
// TODO log warn
}

mixins, err := labelManager.Mixins()
Expand Down Expand Up @@ -126,12 +125,31 @@ func (i *Inspector) Inspect(name string, daemon bool, orderDetectionDepth int) (
APIs: metadata.Lifecycle.APIs,
})

var runImages []pubbldr.RunImageConfig
for _, ri := range metadata.RunImages {
runImages = append(runImages, pubbldr.RunImageConfig{
Image: ri.Image,
Mirrors: ri.Mirrors,
})
}
addStackRunImage := true
for _, ri := range runImages {
if ri.Image == metadata.Stack.RunImage.Image {
addStackRunImage = false
}
}
if addStackRunImage && metadata.Stack.RunImage.Image != "" {
runImages = append(runImages, pubbldr.RunImageConfig{
Image: metadata.Stack.RunImage.Image,
Mirrors: metadata.Stack.RunImage.Mirrors,
})
}

return Info{
Description: metadata.Description,
StackID: stackID,
Mixins: append(commonMixins, buildMixins...),
RunImage: metadata.Stack.RunImage.Image,
RunImageMirrors: metadata.Stack.RunImage.Mirrors,
RunImages: runImages,
Buildpacks: sortBuildPacksByID(uniqueBuildpacks(metadata.Buildpacks)),
Order: detectionOrder,
BuildpackLayers: layers,
Expand Down
Loading

0 comments on commit 92d0380

Please sign in to comment.