build

package
v0.17.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 24, 2024 License: Apache-2.0 Imports: 41 Imported by: 13

Documentation

Overview

Package build defines methods for building a v1.Image reference from a Go binary reference.

Index

Constants

View Source
const StrictScheme = "ko://"

StrictScheme is a prefix that can be placed on import paths that users think MUST be supported references.

Variables

This section is empty.

Functions

This section is empty.

Types

type Caching

type Caching struct {
	// contains filtered or unexported fields
}

Caching wraps a builder implementation in a layer that shares build results for the same inputs using a simple "future" implementation. Cached results may be invalidated by calling Invalidate with the same input passed to Build.

func NewCaching

func NewCaching(inner Interface) (*Caching, error)

NewCaching wraps the provided build.Interface in an implementation that shares build results for a given path until the result has been invalidated.

func (*Caching) Build

func (c *Caching) Build(ctx context.Context, ip string) (Result, error)

Build implements Interface

func (*Caching) Invalidate

func (c *Caching) Invalidate(ip string)

Invalidate removes an import path's cached results.

func (*Caching) IsSupportedReference

func (c *Caching) IsSupportedReference(ip string) error

IsSupportedReference implements Interface

func (*Caching) QualifyImport added in v0.9.0

func (c *Caching) QualifyImport(ip string) (string, error)

QualifyImport implements Interface

type Config added in v0.9.0

type Config struct {
	// ID only serves as an identifier internally
	ID string `yaml:",omitempty"`

	// Dir is the directory out of which the build should be triggered
	Dir string `yaml:",omitempty"`

	// Main points to the main package, or the source file with the main
	// function, in which case only the package will be used for the importpath
	Main string `yaml:",omitempty"`

	// Ldflags and Flags will be used for the Go build command line arguments
	Ldflags StringArray `yaml:",omitempty"`
	Flags   FlagArray   `yaml:",omitempty"`

	// Env allows setting environment variables for `go build`
	Env []string `yaml:",omitempty"`

	// extension: Linux capabilities to enable on the executable, applies
	// to Linux targets.
	LinuxCapabilities FlagArray `yaml:"linux_capabilities,omitempty"`
}

Config contains the build configuration section. The name was changed from the original GoReleaser name to match better with the ko naming.

TODO: Introduce support for more fields where possible and where it makes / sense for `ko`, for example ModTimestamp or GoBinary.

type FlagArray added in v0.9.0

type FlagArray []string

FlagArray is a wrapper for an array of strings.

func (*FlagArray) UnmarshalYAML added in v0.9.0

func (a *FlagArray) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML is a custom unmarshaler that wraps strings in arrays.

type GetBase

type GetBase func(context.Context, string) (name.Reference, Result, error)

GetBase takes an importpath and returns a base image reference and base image (or index).

type Interface

type Interface interface {
	// QualifyImport turns relative importpath references into complete importpaths.
	// It also adds the ko scheme prefix if necessary.
	// E.g., "github.com/ko-build/ko/test" => "ko://github.com/ko-build/ko/test"
	// and "./test" => "ko://github.com/ko-build/ko/test"
	QualifyImport(string) (string, error)

	// IsSupportedReference determines whether the given reference is to an
	// importpath reference that Ko supports building, returning an error
	// if it is not.
	// TODO(mattmoor): Verify that some base repo: foo.io/bar can be suffixed with this reference and parsed.
	IsSupportedReference(string) error

	// Build turns the given importpath reference into a v1.Image containing the Go binary
	// (or a set of images as a v1.ImageIndex).
	Build(context.Context, string) (Result, error)
}

Interface abstracts different methods for turning a supported importpath reference into a v1.Image.

func NewGo

func NewGo(ctx context.Context, dir string, options ...Option) (Interface, error)

NewGo returns a build.Interface implementation that:

  1. builds go binaries named by importpath,
  2. containerizes the binary on a suitable base.

The `dir` argument is the working directory for executing the `go` tool. If `dir` is empty, the function uses the current process working directory.

func NewGobuilds added in v0.10.0

func NewGobuilds(ctx context.Context, workingDirectory string, buildConfigs map[string]Config, opts ...Option) (Interface, error)

NewGobuilds returns a build.Interface that can dispatch to builders based on matching the import path to a build config in .ko.yaml.

type Limiter

type Limiter struct {
	Builder Interface
	// contains filtered or unexported fields
}

Limiter composes with another Interface to limit the number of concurrent builds.

func NewLimiter deprecated

func NewLimiter(b Interface, n int) *Limiter

NewLimiter returns a new builder that only allows n concurrent builds of b.

Deprecated: Obsoleted by WithJobs option.

func (*Limiter) Build

func (l *Limiter) Build(ctx context.Context, ip string) (Result, error)

Build implements Interface

func (*Limiter) IsSupportedReference

func (l *Limiter) IsSupportedReference(ip string) error

IsSupportedReference implements Interface

func (*Limiter) QualifyImport added in v0.9.0

func (l *Limiter) QualifyImport(ip string) (string, error)

QualifyImport implements Interface

type Option

type Option func(*gobuildOpener) error

Option is a functional option for NewGo.

func WithAnnotation added in v0.17.0

func WithAnnotation(k, v string) Option

WithAnnotation is a functional option for adding annotations to built manifests

func WithBaseImages

func WithBaseImages(gb GetBase) Option

WithBaseImages is a functional option for overriding the base images that are used for different images.

func WithConfig added in v0.9.0

func WithConfig(buildConfigs map[string]Config) Option

WithConfig is a functional option for providing GoReleaser Build influenced build settings for importpaths.

Set a fully qualified importpath (e.g. github.com/my-user/my-repo/cmd/app) as the mapping key for the respective Config.

func WithCreationTime

func WithCreationTime(t v1.Time) Option

WithCreationTime is a functional option for overriding the creation time given to images.

func WithDebugger added in v0.16.0

func WithDebugger() Option

func WithDefaultEnv added in v0.15.4

func WithDefaultEnv(env []string) Option

WithDefaultEnv is a functional option for providing a default set of environment variables across all builds.

func WithDefaultFlags added in v0.15.4

func WithDefaultFlags(flags []string) Option

WithDefaultFlags is a functional option for providing a default set of flags across all builds.

func WithDefaultLdflags added in v0.15.4

func WithDefaultLdflags(ldflags []string) Option

WithDefaultLdflags is a functional option for providing a default set of ldflags across all builds.

func WithDisabledOptimizations

func WithDisabledOptimizations() Option

WithDisabledOptimizations is a functional option for disabling optimizations when compiling.

func WithDisabledSBOM added in v0.10.0

func WithDisabledSBOM() Option

WithDisabledSBOM is a functional option for disabling SBOM generation.

func WithJobs added in v0.10.0

func WithJobs(jobs int) Option

WithJobs limits the number of concurrent builds.

func WithKoDataCreationTime added in v0.9.0

func WithKoDataCreationTime(t v1.Time) Option

WithKoDataCreationTime is a functional option for overriding the creation time given to the files in the kodata directory.

func WithLabel added in v0.8.2

func WithLabel(k, v string) Option

WithLabel is a functional option for adding labels to built images.

func WithPlatforms added in v0.7.0

func WithPlatforms(platforms ...string) Option

WithPlatforms is a functional option for building certain platforms for multi-platform base images. To build everything from the base, use "all", otherwise use a list of platform specs, i.e.:

platform = <os>[/<arch>[/<variant>]] allowed = "all" | []string{platform[,platform]*}

Note: a string of comma-separated platforms (i.e. "platform[,platform]*") has been deprecated and only exist for backwards compatibility reasons, which will be removed in the future.

func WithSBOMDir added in v0.13.0

func WithSBOMDir(dir string) Option

WithSBOMDir is a functional option for overriding the directory

func WithSPDX added in v0.10.0

func WithSPDX(version string) Option

WithSPDX is a functional option to direct ko to use SPDX for SBOM format.

func WithTrimpath added in v0.10.0

func WithTrimpath(v bool) Option

WithTrimpath is a functional option that controls whether the `-trimpath` flag is added to `go build`.

func WithUser added in v0.17.0

func WithUser(user string) Option

WithUser is a functional option for overriding the user in the image config.

type Recorder

type Recorder struct {
	ImportPaths []string
	Builder     Interface
	// contains filtered or unexported fields
}

Recorder composes with another Interface to record the built import paths.

func (*Recorder) Build

func (r *Recorder) Build(ctx context.Context, ip string) (Result, error)

Build implements Interface

func (*Recorder) IsSupportedReference

func (r *Recorder) IsSupportedReference(ip string) error

IsSupportedReference implements Interface

func (*Recorder) QualifyImport added in v0.9.0

func (r *Recorder) QualifyImport(ip string) (string, error)

QualifyImport implements Interface

type Result added in v0.6.0

type Result interface {
	MediaType() (types.MediaType, error)
	Size() (int64, error)
	Digest() (v1.Hash, error)
	RawManifest() ([]byte, error)
}

Result represents the product of a Build. This is generally one of: - v1.Image (or oci.SignedImage), or - v1.ImageIndex (or oci.SignedImageIndex)

type StringArray added in v0.9.0

type StringArray []string

StringArray is a wrapper for an array of strings.

func (*StringArray) UnmarshalYAML added in v0.9.0

func (a *StringArray) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML is a custom unmarshaler that wraps strings in arrays.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL