Skip to content

Commit

Permalink
Merge pull request #256 from buildpacks/fix/locallayout
Browse files Browse the repository at this point in the history
Fix locallayout package, make it suitable to replace the local package
  • Loading branch information
natalieparellano authored Apr 5, 2024
2 parents f8d38e1 + 1848278 commit 43aaba5
Show file tree
Hide file tree
Showing 16 changed files with 454 additions and 3,715 deletions.
17 changes: 11 additions & 6 deletions cnb_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
// Specific implementations may choose to override certain methods, and will need to supply the methods that are omitted,
// such as Identifier() and Found().
// The working image could be any v1.Image,
// but in practice will start off as a pointer to a locallayout.v1ImageFacade (or similar).
// but in practice will start off as a pointer to a local.v1ImageFacade (or similar).
type CNBImageCore struct {
// required
v1.Image // the working image
Expand Down Expand Up @@ -305,17 +305,22 @@ func (i *CNBImageCore) AddLayerWithDiffID(path, _ string) error {
}

func (i *CNBImageCore) AddLayerWithDiffIDAndHistory(path, _ string, history v1.History) error {
layer, err := tarball.LayerFromFile(path)
if err != nil {
return err
}
return i.AddLayerWithHistory(layer, history)
}

func (i *CNBImageCore) AddLayerWithHistory(layer v1.Layer, history v1.History) error {
var err error
// ensure existing history
if err := i.MutateConfigFile(func(c *v1.ConfigFile) {
if err = i.MutateConfigFile(func(c *v1.ConfigFile) {
c.History = NormalizedHistory(c.History, len(c.RootFS.DiffIDs))
}); err != nil {
return err
}

layer, err := tarball.LayerFromFile(path)
if err != nil {
return err
}
if !i.preserveHistory {
history = emptyHistory
}
Expand Down
2 changes: 1 addition & 1 deletion image.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type Image interface {
History() ([]v1.History, error)
Identifier() (Identifier, error)
// Kind exposes the type of image that backs the imgutil.Image implementation.
// It could be `local`, `locallayout`, `remote`, or `layout`.
// It could be `local`, `remote`, or `layout`.
Kind() string
Label(string) (string, error)
Labels() (map[string]string, error)
Expand Down
4 changes: 2 additions & 2 deletions layout/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func NewImage(path string, ops ...ImageOption) (*Image, error) {
op(options)
}

options.Platform = processDefaultPlatformOption(options.Platform)
options.Platform = processPlatformOption(options.Platform)

var err error

Expand Down Expand Up @@ -58,7 +58,7 @@ func NewImage(path string, ops ...ImageOption) (*Image, error) {
}, nil
}

func processDefaultPlatformOption(requestedPlatform imgutil.Platform) imgutil.Platform {
func processPlatformOption(requestedPlatform imgutil.Platform) imgutil.Platform {
var emptyPlatform imgutil.Platform
if requestedPlatform != emptyPlatform {
return requestedPlatform
Expand Down
14 changes: 7 additions & 7 deletions layout/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ func FromBaseImagePath(name string) func(*imgutil.ImageOptions) {
}
}

// WithCreatedAt lets a caller set the "created at" timestamp for the working image when saved.
// If not provided, the default is imgutil.NormalizedDateTime.
func WithCreatedAt(t time.Time) func(*imgutil.ImageOptions) {
// WithConfig lets a caller provided a `config` object for the working image.
func WithConfig(c *v1.Config) func(*imgutil.ImageOptions) {
return func(o *imgutil.ImageOptions) {
o.CreatedAt = t
o.Config = c
}
}

// WithConfig lets a caller provided a `config` object for the working image.
func WithConfig(c *v1.Config) func(*imgutil.ImageOptions) {
// WithCreatedAt lets a caller set the "created at" timestamp for the working image when saved.
// If not provided, the default is imgutil.NormalizedDateTime.
func WithCreatedAt(t time.Time) func(*imgutil.ImageOptions) {
return func(o *imgutil.ImageOptions) {
o.Config = c
o.CreatedAt = t
}
}

Expand Down
Loading

0 comments on commit 43aaba5

Please sign in to comment.