Skip to content

Commit

Permalink
Merge upstream/main to branch
Browse files Browse the repository at this point in the history
Signed-off-by: Ozzy Osborne <bardweller@gmail.com>
  • Loading branch information
BarDweller committed May 2, 2024
2 parents 29192dd + 32563a6 commit e90aa83
Show file tree
Hide file tree
Showing 33 changed files with 587 additions and 491 deletions.
28 changes: 13 additions & 15 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/buildpacks/pack
require (
github.com/BurntSushi/toml v1.3.2
github.com/Masterminds/semver v1.5.0
github.com/Microsoft/go-winio v0.6.1
github.com/Microsoft/go-winio v0.6.2
github.com/apex/log v1.9.0
github.com/buildpacks/imgutil v0.0.0-20240206215312-f8d38e1de03d
github.com/buildpacks/lifecycle v0.19.3
Expand All @@ -12,15 +12,15 @@ require (
github.com/docker/go-connections v0.5.0
github.com/dustin/go-humanize v1.0.1
github.com/gdamore/tcell/v2 v2.7.4
github.com/go-git/go-git/v5 v5.11.0
github.com/go-git/go-git/v5 v5.12.0
github.com/golang/mock v1.6.0
github.com/google/go-cmp v0.6.0
github.com/google/go-containerregistry v0.19.1
github.com/google/go-github/v30 v30.1.0
github.com/hectane/go-acl v0.0.0-20190604041725-da78bae5fc95
github.com/heroku/color v0.0.6
github.com/mitchellh/ioprogress v0.0.0-20180201004757-6a23b12fa88e
github.com/onsi/gomega v1.32.0
github.com/onsi/gomega v1.33.0
github.com/opencontainers/go-digest v1.0.0
github.com/opencontainers/image-spec v1.1.0
github.com/pelletier/go-toml v1.9.5
Expand All @@ -29,12 +29,12 @@ require (
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06
github.com/sclevine/spec v1.4.0
github.com/spf13/cobra v1.8.0
golang.org/x/crypto v0.21.0
golang.org/x/mod v0.16.0
golang.org/x/oauth2 v0.18.0
golang.org/x/sync v0.6.0
golang.org/x/sys v0.18.0
golang.org/x/term v0.18.0
golang.org/x/crypto v0.22.0
golang.org/x/mod v0.17.0
golang.org/x/oauth2 v0.19.0
golang.org/x/sync v0.7.0
golang.org/x/sys v0.19.0
golang.org/x/term v0.19.0
golang.org/x/text v0.14.0
gopkg.in/yaml.v3 v3.0.1
)
Expand All @@ -51,7 +51,7 @@ require (
github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect
github.com/Azure/go-autorest/logger v0.2.1 // indirect
github.com/Azure/go-autorest/tracing v0.6.0 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 // indirect
github.com/ProtonMail/go-crypto v1.0.0 // indirect
github.com/agext/levenshtein v1.2.3 // indirect
github.com/aws/aws-sdk-go-v2 v1.25.2 // indirect
github.com/aws/aws-sdk-go-v2/config v1.27.4 // indirect
Expand Down Expand Up @@ -122,19 +122,17 @@ require (
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/rivo/uniseg v0.4.3 // indirect
github.com/sergi/go-diff v1.2.0 // indirect
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/skeema/knownhosts v1.2.1 // indirect
github.com/skeema/knownhosts v1.2.2 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/vbatts/tar-split v0.11.5 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.48.0 // indirect
go.opentelemetry.io/otel v1.23.0 // indirect
go.opentelemetry.io/otel/metric v1.23.0 // indirect
go.opentelemetry.io/otel/trace v1.23.0 // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/tools v0.17.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
golang.org/x/net v0.23.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
)
Expand Down
69 changes: 32 additions & 37 deletions go.sum

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions internal/builder/image_fetcher_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ type ImageFetcher interface {
// If daemon is true, it will look return a `local.Image`. Pull, applicable only when daemon is true, will
// attempt to pull a remote image first.
Fetch(ctx context.Context, name string, options image.FetchOptions) (imgutil.Image, error)

// CheckReadAccess verifies if an image is accessible with read permissions
// When FetchOptions.Daemon is true and the image doesn't exist in the daemon,
// the behavior is dictated by the pull policy, which can have the following behavior
// - PullNever: returns false
// - PullAlways Or PullIfNotPresent: it will check read access for the remote image.
// When FetchOptions.Daemon is false it will check read access for the remote image.
CheckReadAccess(repo string, options image.FetchOptions) bool
}

type ImageFetcherWrapper struct {
Expand All @@ -32,3 +40,7 @@ func (w *ImageFetcherWrapper) Fetch(
) (Inspectable, error) {
return w.fetcher.Fetch(ctx, name, options)
}

func (w *ImageFetcherWrapper) CheckReadAccessValidator(repo string, options image.FetchOptions) bool {
return w.fetcher.CheckReadAccess(repo, options)
}
29 changes: 16 additions & 13 deletions internal/commands/buildpack_new_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,14 @@ func testBuildpackNewCommand(t *testing.T, when spec.G, it spec.S) {
Arch: "arm",
ArchVariant: "v6",
Distributions: []dist.Distribution{{
Name: "ubuntu",
Versions: []string{"14.04", "16.04"},
Name: "ubuntu",
Version: "14.04",
}},
}},
}).Return(nil).MaxTimes(1)

path := filepath.Join(tmpDir, "targets")
command.SetArgs([]string{"--path", path, "example/targets", "--targets", "linux/arm/v6:ubuntu@14.04@16.04"})
command.SetArgs([]string{"--path", path, "example/targets", "--targets", "linux/arm/v6:ubuntu@14.04"})

err := command.Execute()
h.AssertNil(t, err)
Expand All @@ -120,8 +120,11 @@ func testBuildpackNewCommand(t *testing.T, when spec.G, it spec.S) {
Arch: "arm",
ArchVariant: "v6",
Distributions: []dist.Distribution{{
Name: "ubuntu",
Versions: []string{"14.04", "16.04"},
Name: "ubuntu",
Version: "14.04",
}, {
Name: "ubuntu",
Version: "16.04",
}},
}},
}).Return(nil).MaxTimes(1)
Expand All @@ -133,7 +136,7 @@ func testBuildpackNewCommand(t *testing.T, when spec.G, it spec.S) {
h.AssertNotNil(t, err)
})
when("it should", func() {
it("support format [os][/arch][/variant]:[name@version@version2];[some-name@version@version2]", func() {
it("support format [os][/arch][/variant]:[name@version];[some-name@version]", func() {
mockClient.EXPECT().NewBuildpack(gomock.Any(), client.NewBuildpackOptions{
API: "0.8",
ID: "example/targets",
Expand All @@ -146,12 +149,12 @@ func testBuildpackNewCommand(t *testing.T, when spec.G, it spec.S) {
ArchVariant: "v6",
Distributions: []dist.Distribution{
{
Name: "ubuntu",
Versions: []string{"14.04", "16.04"},
Name: "ubuntu",
Version: "14.04",
},
{
Name: "debian",
Versions: []string{"8.10", "10.9"},
Name: "debian",
Version: "8.10",
},
},
},
Expand All @@ -160,16 +163,16 @@ func testBuildpackNewCommand(t *testing.T, when spec.G, it spec.S) {
Arch: "amd64",
Distributions: []dist.Distribution{
{
Name: "windows-nano",
Versions: []string{"10.0.19041.1415"},
Name: "windows-nano",
Version: "10.0.19041.1415",
},
},
},
},
}).Return(nil).MaxTimes(1)

path := filepath.Join(tmpDir, "targets")
command.SetArgs([]string{"--path", path, "example/targets", "--targets", "linux/arm/v6:ubuntu@14.04@16.04;debian@8.10@10.9", "-t", "windows/amd64:windows-nano@10.0.19041.1415"})
command.SetArgs([]string{"--path", path, "example/targets", "--targets", "linux/arm/v6:ubuntu@14.04;debian@8.10", "-t", "windows/amd64:windows-nano@10.0.19041.1415"})

err := command.Execute()
h.AssertNil(t, err)
Expand Down
19 changes: 0 additions & 19 deletions internal/fakes/fake_access_checker.go

This file was deleted.

4 changes: 4 additions & 0 deletions internal/fakes/fake_image_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ func (f *FakeImageFetcher) Fetch(ctx context.Context, name string, options image
return ri, nil
}

func (f *FakeImageFetcher) CheckReadAccess(_ string, _ image.FetchOptions) bool {
return true
}

func shouldPull(localFound, remoteFound bool, policy image.PullPolicy) bool {
if remoteFound && !localFound && policy == image.PullIfNotPresent {
return true
Expand Down
2 changes: 1 addition & 1 deletion internal/layer/writer_factory_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package layer_test

import (
"archive/tar"
"archive/tar" //nolint
"testing"

ilayer "github.com/buildpacks/imgutil/layer"
Expand Down
11 changes: 8 additions & 3 deletions internal/target/parse.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package target

import (
"fmt"
"strings"

"github.com/pkg/errors"
Expand Down Expand Up @@ -66,11 +67,15 @@ func ParseDistro(distroString string, logger logging.Logger) (distro dist.Distri
if d[0] == "" || len(d) == 0 {
return distro, errors.Errorf("distro's versions %s cannot be specified without distro's name", style.Symbol("@"+strings.Join(d[1:], "@")))
}
if len(d) <= 2 && (strings.Contains(strings.Join(d[1:], ""), "") || d[1] == "") {
distro.Name = d[0]
if len(d) < 2 {
logger.Warnf("distro with name %s has no specific version!", style.Symbol(d[0]))
return distro, err
}
distro.Name = d[0]
distro.Versions = d[1:]
if len(d) > 2 {
return distro, fmt.Errorf("invalid distro: %s", distroString)
}
distro.Version = d[1]
return distro, err
}

Expand Down
48 changes: 34 additions & 14 deletions internal/target/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,14 @@ func testParseTargets(t *testing.T, when spec.G, it spec.S) {
h.AssertNotEq(t, outBuf.String(), "")
})
})

when("target#ParseTargets", func() {
it("should throw an error when atleast one target throws error", func() {
_, err := target.ParseTargets([]string{"linux/arm/v6", ":distro@version"}, logging.NewLogWithWriters(&outBuf, &outBuf))
h.AssertNotNil(t, err)
})
it("should parse targets as expected", func() {
output, err := target.ParseTargets([]string{"linux/arm/v6", "linux/amd64:ubuntu@22.04;debian@8.10@10.06"}, logging.NewLogWithWriters(&outBuf, &outBuf))
output, err := target.ParseTargets([]string{"linux/arm/v6", "linux/amd64:ubuntu@22.04;debian@8.10;debian@10.06"}, logging.NewLogWithWriters(&outBuf, &outBuf))
h.AssertNil(t, err)
h.AssertEq(t, output, []dist.Target{
{
Expand All @@ -80,47 +81,66 @@ func testParseTargets(t *testing.T, when spec.G, it spec.S) {
Arch: "amd64",
Distributions: []dist.Distribution{
{
Name: "ubuntu",
Versions: []string{"22.04"},
Name: "ubuntu",
Version: "22.04",
},
{
Name: "debian",
Version: "8.10",
},
{
Name: "debian",
Versions: []string{"8.10", "10.06"},
Name: "debian",
Version: "10.06",
},
},
},
})
})
})

when("target#ParseDistro", func() {
it("should parse distro as expected", func() {
output, err := target.ParseDistro("ubuntu@22.04@20.08", logging.NewLogWithWriters(&outBuf, &outBuf))
output, err := target.ParseDistro("ubuntu@22.04", logging.NewLogWithWriters(&outBuf, &outBuf))
h.AssertEq(t, output, dist.Distribution{
Name: "ubuntu",
Versions: []string{"22.04", "20.08"},
Name: "ubuntu",
Version: "22.04",
})
h.AssertNil(t, err)
})
it("should return an error", func() {
it("should return an error when name is missing", func() {
_, err := target.ParseDistro("@22.04@20.08", logging.NewLogWithWriters(&outBuf, &outBuf))
h.AssertNotNil(t, err)
})
it("should return an error when there are two versions", func() {
_, err := target.ParseDistro("some-distro@22.04@20.08", logging.NewLogWithWriters(&outBuf, &outBuf))
h.AssertNotNil(t, err)
h.AssertError(t, err, "invalid distro")
})
it("should warn when distro version is not specified", func() {
target.ParseDistro("ubuntu", logging.NewLogWithWriters(&outBuf, &outBuf))
h.AssertNotEq(t, outBuf.String(), "")
})
})

when("target#ParseDistros", func() {
it("should parse distros as expected", func() {
output, err := target.ParseDistros("ubuntu@22.04@20.08;debian@8.10@10.06", logging.NewLogWithWriters(&outBuf, &outBuf))
output, err := target.ParseDistros("ubuntu@22.04;ubuntu@20.08;debian@8.10;debian@10.06", logging.NewLogWithWriters(&outBuf, &outBuf))
h.AssertEq(t, output, []dist.Distribution{
{
Name: "ubuntu",
Versions: []string{"22.04", "20.08"},
Name: "ubuntu",
Version: "22.04",
},
{
Name: "ubuntu",
Version: "20.08",
},
{
Name: "debian",
Version: "8.10",
},
{
Name: "debian",
Versions: []string{"8.10", "10.06"},
Name: "debian",
Version: "10.06",
},
})
h.AssertNil(t, err)
Expand Down
Loading

0 comments on commit e90aa83

Please sign in to comment.