Skip to content

Commit

Permalink
uriFromLifecycleImage
Browse files Browse the repository at this point in the history
Signed-off-by: Rashad Sirajudeen <rashad.20@cse.mrt.ac.lk>
  • Loading branch information
rashadism committed May 17, 2024
1 parent df82754 commit 1e3c3a3
Showing 1 changed file with 41 additions and 34 deletions.
75 changes: 41 additions & 34 deletions pkg/client/create_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,41 +217,9 @@ func (c *Client) fetchLifecycle(ctx context.Context, config pubbldr.LifecycleCon
var err error
switch {
case buildpack.HasDockerLocator(config.URI):
var lifecycleImage imgutil.Image
imageName := buildpack.ParsePackageLocator(config.URI)
c.logger.Debugf("Downloading lifecycle image: %s", style.Symbol(imageName))

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

lifecyclePath := filepath.Join(relativeBaseDir, "lifecycle.tar")
layers, err := lifecycleImage.UnderlyingImage().Layers()
if err != nil {
return nil, err
}

// Assume the last layer has the lifecycle
lifecycleLayer := layers[len(layers)-1]

layerReader, err := lifecycleLayer.Uncompressed()
uri, err = c.uriFromLifecycleImage(ctx, relativeBaseDir, config)
if err != nil {
return nil, err
}
defer layerReader.Close()

file, err := stripTopDirAndWrite(layerReader, lifecyclePath)
if err != nil {
return nil, err
}

defer file.Close()
Remove this comment

uri, err = paths.FilePathToURI(lifecyclePath, "")
if err != nil {
return nil, err
return nil, errors.Wrap(err, "Could not parse uri from lifecycle image")
}
case config.Version != "":
v, err := semver.NewVersion(config.Version)
Expand Down Expand Up @@ -438,3 +406,42 @@ func stripTopDirAndWrite(layerReader io.ReadCloser, outputPath string) (*OS.File

return file, nil
}

func (c *Client) uriFromLifecycleImage(ctx context.Context, basePath string, config pubbldr.LifecycleConfig) (uri string, err error) {
var lifecycleImage imgutil.Image
imageName := buildpack.ParsePackageLocator(config.URI)
c.logger.Debugf("Downloading lifecycle image: %s", style.Symbol(imageName))

lifecycleImage, err = c.imageFetcher.Fetch(ctx, imageName, image.FetchOptions{Daemon: false})
if err != nil {
return "", nil
}

lifecyclePath := filepath.Join(basePath, "lifecycle.tar")
layers, err := lifecycleImage.UnderlyingImage().Layers()
if err != nil {
return "", err
}

// Assume the last layer has the lifecycle
lifecycleLayer := layers[len(layers)-1]

layerReader, err := lifecycleLayer.Uncompressed()
if err != nil {
return "", err
}
defer layerReader.Close()

file, err := stripTopDirAndWrite(layerReader, lifecyclePath)
if err != nil {
return "", err
}

defer file.Close()

uri, err = paths.FilePathToURI(lifecyclePath, "")
if err != nil {
return "", err
}
return uri, err
}

0 comments on commit 1e3c3a3

Please sign in to comment.