Skip to content

Commit

Permalink
Validate the URI and variable name change
Browse files Browse the repository at this point in the history
Signed-off-by: Rashad Sirajudeen <[email protected]>
  • Loading branch information
rashadism committed Apr 19, 2024
1 parent ef6d2c9 commit 80af078
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions pkg/client/create_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/Masterminds/semver"
"github.com/buildpacks/imgutil"
"github.com/google/go-containerregistry/pkg/name"
"github.com/pkg/errors"
"golang.org/x/text/cases"
"golang.org/x/text/language"
Expand All @@ -25,8 +26,6 @@ import (
"github.com/buildpacks/pack/pkg/image"
)

const fromDockerPrefix = "docker:/"

// CreateBuilderOptions is a configuration object used to change the behavior of
// CreateBuilder.
type CreateBuilderOptions struct {
Expand Down Expand Up @@ -208,7 +207,7 @@ func (c *Client) createBaseBuilder(ctx context.Context, opts CreateBuilderOption
return bldr, nil
}

func (c *Client) fetchLifecycle(ctx context.Context, config pubbldr.LifecycleConfig, relativeBaseDir, o string, architecture string) (builder.Lifecycle, error) {
func (c *Client) fetchLifecycle(ctx context.Context, config pubbldr.LifecycleConfig, relativeBaseDir, platform string, architecture string) (builder.Lifecycle, error) {
if config.Version != "" && config.URI != "" {
return nil, errors.Errorf(
"%s can only declare %s or %s, not both",
Expand All @@ -220,16 +219,22 @@ func (c *Client) fetchLifecycle(ctx context.Context, config pubbldr.LifecycleCon
var err error
switch {
case buildpack.HasDockerLocator(config.URI):
if _, err := name.ParseReference(config.URI); err != nil {
return nil, err
}
var lifecycleImage imgutil.Image
var blob blob.Blob
imageName := buildpack.ParsePackageLocator(config.URI)
c.logger.Debugf("Downloading lifecycle image: %s", style.Symbol(imageName))

// TODO: get the fetchoptions
lifecycleImage, err = c.imageFetcher.Fetch(ctx, imageName, image.FetchOptions{Daemon: false})
if err != nil {
return nil, err
}

// Good till this point

lifecycleImageTar := filepath.Join(relativeBaseDir, "lifecycle-image.tar")
lifecycleImageReader, err := c.docker.ImageSave(context.Background(), []string{lifecycleImage.Name()})
if err != nil {
Expand Down Expand Up @@ -280,14 +285,14 @@ func (c *Client) fetchLifecycle(ctx context.Context, config pubbldr.LifecycleCon
return nil, errors.Wrapf(err, "%s must be a valid semver", style.Symbol("lifecycle.version"))
}

uri = uriFromLifecycleVersion(*v, o, architecture)
uri = uriFromLifecycleVersion(*v, platform, architecture)
case config.URI != "":
uri, err = paths.FilePathToURI(config.URI, relativeBaseDir)
if err != nil {
return nil, err
}
default:
uri = uriFromLifecycleVersion(*semver.MustParse(builder.DefaultLifecycleVersion), o, architecture)
uri = uriFromLifecycleVersion(*semver.MustParse(builder.DefaultLifecycleVersion), platform, architecture)
}

blob, err := c.downloader.Download(ctx, uri)
Expand Down

0 comments on commit 80af078

Please sign in to comment.