Skip to content

Commit

Permalink
Add docs comments
Browse files Browse the repository at this point in the history
Signed-off-by: Natalie Arellano <[email protected]>
  • Loading branch information
natalieparellano committed Feb 5, 2024
1 parent 33de307 commit 7ed58a5
Showing 1 changed file with 29 additions and 12 deletions.
41 changes: 29 additions & 12 deletions layout/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,54 +10,71 @@ import (

type ImageOption func(*imgutil.ImageOptions)

func FromBaseImagePath(name string) func(*imgutil.ImageOptions) {
return func(o *imgutil.ImageOptions) {
o.BaseImageRepoName = name
}
}

// FromBaseImage loads the provided image as the manifest, config, and layers for the working image.
// If the image is not found, it does nothing.
func FromBaseImage(image v1.Image) func(*imgutil.ImageOptions) {
return func(o *imgutil.ImageOptions) {
o.BaseImage = image
}
}

func WithConfig(c *v1.Config) func(*imgutil.ImageOptions) {
// FromBaseImagePath (layout only) loads the image at the provided path as the manifest, config, and layers for the working image.
// If the image is not found, it does nothing.
func FromBaseImagePath(name string) func(*imgutil.ImageOptions) {
return func(o *imgutil.ImageOptions) {
o.Config = c
o.BaseImageRepoName = name
}
}

// 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.CreatedAt = t

Check warning on line 33 in layout/options.go

View check run for this annotation

Codecov / codecov/patch

layout/options.go#L31-L33

Added lines #L31 - L33 were not covered by tests
}
}

// 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.Config = c

Check warning on line 40 in layout/options.go

View check run for this annotation

Codecov / codecov/patch

layout/options.go#L38-L40

Added lines #L38 - L40 were not covered by tests
}
}

// WithDefaultPlatform provides the default Architecture/OS/OSVersion if no base image is provided,
// or if the provided image inputs (base and previous) are manifest lists.
func WithDefaultPlatform(p imgutil.Platform) func(*imgutil.ImageOptions) {
return func(o *imgutil.ImageOptions) {
o.Platform = p
}
}

// WithHistory if provided will configure the image to preserve history when saved
// (including any history from the base image if valid).
func WithHistory() func(*imgutil.ImageOptions) {
return func(o *imgutil.ImageOptions) {
o.PreserveHistory = true
}
}

func WithPreviousImage(name string) func(*imgutil.ImageOptions) {
// WithMediaTypes lets a caller set the desired media types for the manifest and config (including layers referenced in the manifest)
// to be either OCI media types or Docker media types.
func WithMediaTypes(m imgutil.MediaTypes) func(*imgutil.ImageOptions) {
return func(o *imgutil.ImageOptions) {
o.PreviousImageRepoName = name
o.MediaTypes = m
}
}

func WithMediaTypes(m imgutil.MediaTypes) func(*imgutil.ImageOptions) {
// WithPreviousImage loads an existing image as the source for reusable layers.
// Use with ReuseLayer().
// If the image is not found, it does nothing.
func WithPreviousImage(name string) func(*imgutil.ImageOptions) {
return func(o *imgutil.ImageOptions) {
o.MediaTypes = m
o.PreviousImageRepoName = name
}
}

// WithoutLayersWhenSaved (layout only) if provided will cause the image to be written without layers in the `blobs` directory.
func WithoutLayersWhenSaved() func(*imgutil.ImageOptions) {
return func(o *imgutil.ImageOptions) {
o.WithoutLayers = true

Check warning on line 80 in layout/options.go

View check run for this annotation

Codecov / codecov/patch

layout/options.go#L78-L80

Added lines #L78 - L80 were not covered by tests
Expand Down

0 comments on commit 7ed58a5

Please sign in to comment.