Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Builder ¶
type Builder struct {
Compile
CaddyVersion string `json:"caddy_version,omitempty"`
Plugins []Dependency `json:"plugins,omitempty"`
Replacements []Replace `json:"replacements,omitempty"`
TimeoutGet time.Duration `json:"timeout_get,omitempty"`
TimeoutBuild time.Duration `json:"timeout_build,omitempty"`
RaceDetector bool `json:"race_detector,omitempty"`
SkipCleanup bool `json:"skip_cleanup,omitempty"`
SkipBuild bool `json:"skip_build,omitempty"`
Debug bool `json:"debug,omitempty"`
BuildFlags string `json:"build_flags,omitempty"`
ModFlags string `json:"mod_flags,omitempty"`
PgoProfile string `json:"pgo_profile,omitempty"` // Experimental
// Experimental: subject to change
EmbedDirs []struct {
Dir string `json:"dir,omitempty"`
Name string `json:"name,omitempty"`
} `json:"embed_dir,omitempty"`
// OnStep, if set, is called for each build step, making the
// build's progress observable and controllable. The callback
// runs in its own goroutine, concurrently with the step it
// describes, so it can consume the event's Output directly,
// with no extra goroutine of its own:
//
// OnStep: func(e *xcaddy.StepEvent) error {
// scanner := bufio.NewScanner(e.Output)
// for scanner.Scan() {
// showProgress(e.Step, scanner.Text())
// }
// return scanner.Err()
// }
//
// Callbacks never overlap: the next step does not begin until
// the previous step's callback has returned, and Build does
// not return until the final callback has returned. Output
// reaches EOF when the step ends, so a callback that reads
// until EOF returns naturally at the step boundary; one that
// lingers afterward delays the build accordingly.
//
// Returning a non-nil error aborts the build at the end of
// the step: no further steps begin, and the error is returned
// from Build, wrapped with the step name (use errors.Is or
// errors.As to match a custom error). To cancel mid-step,
// cancel the context passed to Build instead. Aborting does
// not skip removal of the temporary build folder. The
// callback must not call back into the Builder.
OnStep func(event *StepEvent) error `json:"-"`
// Env, if non-nil, is used as the entire environment of the
// underlying go commands, in KEY=value form (see os.Environ);
// the process's own environment is not inherited. This
// enables hermetic, credential-free builds: if build logs are
// published (see OnStep), no ambient credential (GOPROXY
// userinfo, git configuration, .netrc, cloud keys, ...) can
// leak into them when the build never had access to any. The
// environment must include everything the go toolchain needs,
// at minimum PATH and HOME (or GOCACHE and GOMODCACHE); GOOS,
// GOARCH, GOARM and CGO_ENABLED are set by the Builder
// itself. If nil, the process environment is inherited, which
// is the historical behavior.
Env []string `json:"-"`
// Secrets lists sensitive values (tokens, passwords, keys)
// that must not appear in step output: every occurrence is
// replaced with "[REDACTED]" before it reaches a StepEvent's
// Output. Matching is exact and line-buffered, so a secret
// cannot slip through by straddling a write boundary; values
// containing newlines cannot be matched. Secrets has no
// effect when OnStep is nil.
Secrets []string `json:"-"`
// RedactCredentials additionally masks common credential
// shapes in step output: userinfo in URLs, well-known token
// formats (GitHub, GitLab, Slack, AWS access key IDs), and
// PEM-encoded private key blocks. It is a best-effort
// backstop for publishable logs, not a guarantee; prefer
// building in a credential-free environment (see Env). It has
// no effect when OnStep is nil.
RedactCredentials bool `json:"-"`
}
Builder can produce a custom Caddy build with the configuration it represents.
type Compile ¶ added in v0.1.2
Compile contains parameters for compilation.
func SupportedPlatforms ¶ added in v0.1.2
SupportedPlatforms runs `go tool dist list` to make a list of possible build targets.
func (Compile) CgoEnabled ¶ added in v0.1.4
CgoEnabled returns "1" if c.Cgo is true, "0" otherwise. This is used for setting the CGO_ENABLED env variable.
type Dependency ¶
type Dependency struct {
// The name (import path) of the Go package. If at a version > 1,
// it should contain semantic import version (i.e. "/v2").
// Used with `go get`.
PackagePath string `json:"module_path,omitempty"`
// The version of the Go module, as used with `go get`.
Version string `json:"version,omitempty"`
}
Dependency pairs a Go module path with a version.
func (Dependency) String ¶ added in v0.4.2
func (d Dependency) String() string
type Platform ¶ added in v0.1.2
type Platform struct {
OS string `json:"os,omitempty"`
Arch string `json:"arch,omitempty"`
ARM string `json:"arm,omitempty"`
}
Platform represents a build target.
type Replace ¶ added in v0.1.1
type Replace struct {
// The import path of the module being replaced.
Old ReplacementPath `json:"old,omitempty"`
// The path to the replacement module.
New ReplacementPath `json:"new,omitempty"`
}
Replace represents a Go module replacement.
func NewReplace ¶ added in v0.1.6
NewReplace creates a new instance of Replace provided old and new Go module paths
type ReplacementPath ¶ added in v0.1.6
type ReplacementPath string
ReplacementPath represents an old or new path component within a Go module replacement directive.
func (ReplacementPath) Param ¶ added in v0.1.6
func (r ReplacementPath) Param() string
Param reformats a go.mod replace directive to be compatible with the `go mod edit` command.
func (ReplacementPath) String ¶ added in v0.1.6
func (r ReplacementPath) String() string
type Step ¶ added in v0.4.7
type Step string
Step identifies a phase of the build process. Steps are reported to a Builder's OnStep callback, if set.
const ( StepCreateEnvironment Step = "create_environment" // set up the temporary build module StepInitializeModule Step = "initialize_module" // go mod init and module replacements StepPinVersions Step = "pin_versions" // go get Caddy and plugins StepWindowsResources Step = "windows_resources" // generate Windows version resources StepTidyModule Step = "tidy_module" // go mod tidy StepCompile Step = "compile" // go build StepCleanup Step = "cleanup" // remove the temporary folder )
The build steps, in the order they occur. StepWindowsResources only occurs when targeting Windows; StepTidyModule and StepCompile do not occur if SkipBuild is enabled; and StepCleanup does not occur if SkipCleanup is enabled.
type StepEvent ¶ added in v0.4.7
type StepEvent struct {
// Step identifies the step that is beginning.
Step Step
// Output reads everything the step produces: xcaddy's own log
// lines (in their usual "[INFO] ..." format) as well as the
// stdout and stderr of the underlying go commands (go mod,
// go get, go build, ...). The Builder buffers this output
// internally, so the build never blocks on a slow reader
// mid-step; output is available to read the moment it is
// produced.
//
// When the step ends, the Builder closes the write side, so
// after any remaining buffered output is drained the reader
// reaches EOF; reading until EOF is the only lifecycle a
// consumer needs. Output that is never read is discarded when
// the step's buffer is released.
Output io.Reader
}
StepEvent describes a build step that is about to begin. It is passed to a Builder's OnStep callback.