Skip to content

Commit

Permalink
todo: Remove top level dir and good to go
Browse files Browse the repository at this point in the history
  • Loading branch information
rashadism committed Apr 19, 2024
1 parent 0c730b9 commit a50d15c
Showing 1 changed file with 39 additions and 58 deletions.
97 changes: 39 additions & 58 deletions pkg/client/create_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ func (c *Client) fetchLifecycle(ctx context.Context, config pubbldr.LifecycleCon
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))

Expand All @@ -238,71 +237,53 @@ func (c *Client) fetchLifecycle(ctx context.Context, config pubbldr.LifecycleCon
return nil, err
}

for _, layer := range layers {
diffID, err := layer.DiffID()
if err != nil {
return nil, err
// Assume the last layer has the lifecycle
diffID, err := layers[len(layers)-1].DiffID()
if err != nil {
return nil, err
}

fmt.Printf("diffID: %s\n", diffID)

layerContent, err := lifecycleImage.GetLayer(diffID.String())
if err != nil {
return nil, err
}

///////////////////
tr := tar.NewReader(layerContent)
tr.Next()
defer layerContent.Close() // Close the ReadCloser when done

// Iterate over the contents of the tar file
for {
header, err := tr.Next()
if err == io.EOF {
break // End of tar archive
}
layerContent, err := lifecycleImage.GetLayer(diffID.String())
if err != nil {
panic(err)
}
defer layerContent.Close()

// Extract the layer tarball
tarReader := tar.NewReader(layerContent)
fmt.Println("--------------------------")
fmt.Print(diffID)
fmt.Println("--------------------------")

for {
header, err := tarReader.Next()
if err == io.EOF {
break // End of archive
}
if err != nil {
panic(err)
}

if header.Name == "cnb" && header.Typeflag == tar.TypeDir {
fmt.Println(header.Name)
}
}
fmt.Println("--------------------------")
// Print information about the current entry
fmt.Println(header.Name)

}
/////////////////

defer layerContent.Close()

lifecycleLayerTar := filepath.Join(relativeBaseDir, "lifecycle-layer.tar")
lifecycleLayerWriter, err := os.OpenFile(lifecycleLayerTar, os.O_CREATE|os.O_RDWR, 0666)
if err != nil {
return nil, err
}
defer lifecycleLayerWriter.Close()
if _, err = io.Copy(lifecycleLayerWriter, layerContent); err != nil {
return nil, err
}

// lifecycleImageTar := filepath.Join(relativeBaseDir, "lifecycle-image.tar")
// lifecycleImageReader, err := c.docker.ImageSave(context.Background(), []string{lifecycleImage.Name()})
// if err != nil {
// return nil, err
// }
// defer lifecycleImageReader.Close()
// lifecycleImageWriter, err := os.Create(lifecycleImageTar)
// if err != nil {
// return nil, err
// }
// defer lifecycleImageWriter.Close()
// if _, err = io.Copy(lifecycleImageWriter, lifecycleImageReader); err != nil {
// return nil, err
// }
// lifecycleLayerName, err := LifecycleLayerName(lifecycleImageTar)
// if err != nil {
// return nil, err
// }
// if lifecycleLayerName == "" {
// return nil, errors.New("failed to find lifecycle layer")
// }

// lifecycleLayerTar, err := LifecycleLayerTar(lifecycleImageTar, lifecycleLayerName)
// if err != nil {
// return nil, err
// }

// uri, err = stripTopLevelDir(lifecycleLayerTar)
// if err != nil {
// return nil, err
// }
uri = lifecycleLayerTar

case config.Version != "":
v, err := semver.NewVersion(config.Version)
Expand Down

0 comments on commit a50d15c

Please sign in to comment.