gobuild

package module
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2022 License: Apache-2.0 Imports: 17 Imported by: 0

README

Go Build Cloud Native Buildpack

The Go Build CNB executes the go build compilation process for Go programs. The buildpack builds the source code in the application directory into an executable and sets it as the start command for the image.

Integration

The Go Build CNB does not provide any dependencies. However, in order to execute the go build compilation process, the buildpack requires the go dependency that can be provided by a buildpack like the Go Distribution CNB.

Usage

To package this buildpack for consumption:

$ ./scripts/package.sh

This builds the buildpack's Go source using GOOS=linux by default. You can supply another value as the first argument to package.sh.

Go Build Configuration

Please set the following environment variables at build time either directly (ex. pack build my-app --env BP_ENVIRONMENT_VARIABLE=some-value) or through a project.toml file

BP_GO_BUILD_LDFLAGS

The BP_GO_BUILD_LDFLAGS variable allows you to set a value for the -ldflags build flag when compiling your program.

BP_GO_BUILD_LDFLAGS= -X main.variable=some-value
BP_GO_TARGETS

The BP_GO_TARGETS variable allows you to specify multiple programs to be compiled. The first target will be used as the start command for the image.

BP_GO_TARGETS=./cmd/web-server:./cmd/debug-server
BP_GO_BUILD_FLAGS

The BP_GO_BUILD_FLAGS variable allows you to override the default build flags when compiling your program.

BP_GO_BUILD_FLAGS= -buildmode=default -tags=paketo -ldflags="-X main.variable=some-value"
BP_GO_BUILD_IMPORT_PATH

The BP_GO_BUILD_IMPORT_PATH allows you to specify an import path for your application. This is necessary if you are building a $GOPATH application that imports its own sub-packages.

BP_GO_BUILD_IMPORT_PATH= example.com/some-app
BP_KEEP_FILES

The BP_KEEP_FILES variable allows to you to specity a path list of files (including file globs) that you would like to appear in the workspace of the final image. This will allow you to perserve static assests.

BP_KEEP_FILES=assets/*:public/*

Documentation

Index

Constants

View Source
const (
	TargetsLayerName = "targets"
	GoCacheLayerName = "gocache"
	WorkspaceSHAKey  = "workspace_sha"
)

Variables

This section is empty.

Functions

func Build

func Build(
	parser ConfigurationParser,
	buildProcess BuildProcess,
	pathManager PathManager,
	clock chronos.Clock,
	logs scribe.Emitter,
	sourceRemover SourceRemover,
	sbomGenerator SBOMGenerator,
) packit.BuildFunc

func Detect

func Detect(parser ConfigurationParser) packit.DetectFunc

Types

type BuildConfiguration added in v0.0.23

type BuildConfiguration struct {
	Targets    []string
	Flags      []string
	ImportPath string
}

type BuildConfigurationParser added in v0.0.5

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

func NewBuildConfigurationParser added in v0.0.5

func NewBuildConfigurationParser(targetManager TargetManager) BuildConfigurationParser

func (BuildConfigurationParser) Parse added in v0.0.5

func (p BuildConfigurationParser) Parse(buildpackVersion, workingDir string) (BuildConfiguration, error)

type BuildProcess

type BuildProcess interface {
	Execute(config GoBuildConfiguration) (binaries []string, err error)
}

type ConfigurationParser added in v0.0.5

type ConfigurationParser interface {
	Parse(buildpackVersion, workingDir string) (BuildConfiguration, error)
}

type Executable

type Executable interface {
	Execute(pexec.Execution) (err error)
}

type GoBuildConfiguration added in v0.0.5

type GoBuildConfiguration struct {
	Workspace string
	Output    string
	GoPath    string
	GoCache   string
	Targets   []string
	Flags     []string
}

type GoBuildProcess

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

func NewGoBuildProcess

func NewGoBuildProcess(executable Executable, logs scribe.Emitter, clock chronos.Clock) GoBuildProcess

func (GoBuildProcess) Execute

func (p GoBuildProcess) Execute(config GoBuildConfiguration) ([]string, error)

type GoPathManager

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

func NewGoPathManager

func NewGoPathManager(tempDir string) GoPathManager

func (GoPathManager) Setup

func (m GoPathManager) Setup(workspace, importPath string) (string, string, error)

func (GoPathManager) Teardown

func (m GoPathManager) Teardown(path string) error

type GoTargetManager added in v0.1.0

type GoTargetManager struct{}

func NewGoTargetManager added in v0.1.0

func NewGoTargetManager() GoTargetManager

func (GoTargetManager) CleanAndValidate added in v0.1.0

func (tm GoTargetManager) CleanAndValidate(inputTargets []string, workingDir string) ([]string, error)

func (GoTargetManager) GenerateDefaults added in v0.1.0

func (tm GoTargetManager) GenerateDefaults(workingDir string) ([]string, error)

type PathManager

type PathManager interface {
	Setup(workspace, importPath string) (goPath, path string, err error)
	Teardown(goPath string) error
}

type SBOMGenerator added in v1.0.0

type SBOMGenerator interface {
	Generate(dir string) (sbom.SBOM, error)
}

type SourceDeleter

type SourceDeleter struct{}

func NewSourceDeleter

func NewSourceDeleter() SourceDeleter

func (SourceDeleter) Clear

func (d SourceDeleter) Clear(path string) error

type SourceRemover

type SourceRemover interface {
	Clear(path string) error
}

type TargetManager added in v0.1.0

type TargetManager interface {
	CleanAndValidate(targets []string, workingDir string) ([]string, error)
	GenerateDefaults(workingDir string) ([]string, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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