build

package
v0.28.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: AGPL-3.0 Imports: 37 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (

	// Win11OfflineEnv disables every attempt to reach Microsoft (CI build jobs).
	Win11OfflineEnv = "SAILWRIGHT_WIN11_ISO_OFFLINE"
)

Variables

View Source
var ErrInterrupted = errors.New("interrupted")

ErrInterrupted is the cancellation cause of a build context after an interrupt signal (Ctrl+C, SIGTERM or SIGHUP).

View Source
var ErrMicrosoftRefused = errors.New("microsoft refused the Windows 11 download request")

ErrMicrosoftRefused signals that Microsoft rejected or challenged the request (e.g. datacenter IP). It is a neutral outcome, not a code defect.

Functions

func AvailableVirtualMachineConfigsForCurrentHostOSByVirtualizationEngine added in v0.4.0

func AvailableVirtualMachineConfigsForCurrentHostOSByVirtualizationEngine() map[VirtualizationEngine][]VirtualMachineConfig

func BuildArtifactsExist added in v0.4.0

func BuildArtifactsExist(config VirtualMachineConfig) (bool, error)

func BuildArtifactsExistQuiet added in v0.4.0

func BuildArtifactsExistQuiet(config VirtualMachineConfig) (bool, error)

func CreationResourceWarnings added in v0.27.0

func CreationResourceWarnings(vm VirtualMachineConfig, storageDir string) []string

CreationResourceWarnings is advisory: missing telemetry never blocks create.

func DefaultAppDataDirForOS added in v0.27.0

func DefaultAppDataDirForOS(goos string, getenv func(string) string, userHomeDir, userConfigDir func() (string, error)) (string, error)

DefaultAppDataDirForOS exposes the app-data contract so sailwright-gateway tests can verify that the gateway's shared-state resolution mirrors it.

func DependencyReconciliation

func DependencyReconciliation(ctx context.Context, vmconfig VirtualMachineConfig) error

DependencyReconciliation downloads the missing web file dependencies of vmconfig. Cancelling ctx (e.g. Ctrl+C) aborts the running download.

func DisplayVirtualizationEngine added in v0.8.0

func DisplayVirtualizationEngine(engine VirtualizationEngine) string

func DownloadWin11ISO added in v0.20.0

func DownloadWin11ISO(url, dst, expectedSHA256 string) error

DownloadWin11ISO downloads the ISO to dst (go-getter, progress, checksum retry) and verifies sha256 when given.

func FetchLatestWin11Release added in v0.20.0

func FetchLatestWin11Release() (string, error)

FetchLatestWin11Release queries the public release notes for the newest Windows 11 release.

func GenerateVirtualMachineSlug

func GenerateVirtualMachineSlug(config *VirtualMachineConfig) string

func GetVirtualMachineNameWithType

func GetVirtualMachineNameWithType(config VirtualMachineConfig) string

func GetVmCpuCount added in v0.3.0

func GetVmCpuCount(config VirtualMachineConfig) int

GetVmCpuCount returns the resolved CPU count for the given VM config.

func GetVmMemoryMB added in v0.3.0

func GetVmMemoryMB(config VirtualMachineConfig) int

GetVmMemoryMB returns the resolved memory allocation in megabytes for the given VM config.

func GroupVirtualMachineConfigsByVirtualizationEngine added in v0.4.0

func GroupVirtualMachineConfigsByVirtualizationEngine(configs []VirtualMachineConfig) map[VirtualizationEngine][]VirtualMachineConfig

func HandleInterrupts added in v0.27.0

func HandleInterrupts(parent context.Context) (context.Context, func())

HandleInterrupts installs the signal handling for builds. The returned context is cancelled with ErrInterrupted on the first interrupt. A second Ctrl+C also cancels post-processing, a third one kills all child process groups and exits with code 130. The returned stop function restores the default signal behaviour.

func HasLinuxCloneIdentity added in v0.27.0

func HasLinuxCloneIdentity(artifact string) bool

HasLinuxCloneIdentity reports whether a matching completed local build was prepared for independent first-boot DHCP identities. Legacy/pulled images do not make this guarantee, even when they are otherwise usable.

func HashFile added in v0.20.0

func HashFile(file string) (string, int64, error)

HashFile returns the sha256 hex digest and size of a file.

func InstanceHostname added in v0.27.0

func InstanceHostname(vm VirtualMachineConfig) string

InstanceHostname obeys Windows' 15-character computer-name limit. Unix guests use the full provider name, which fits the DNS label limit.

func InstanceKey added in v0.27.0

func InstanceKey(vm VirtualMachineConfig) string

InstanceKey is the logical address, independent of provider and image cache.

func InstanceName added in v0.27.0

func InstanceName(vm VirtualMachineConfig) string

InstanceName derives provider identity while preserving every legacy default. A future OS version belongs after OS, before type; image slugs exclude Name.

func Interrupted added in v0.27.0

func Interrupted(ctx context.Context) bool

Interrupted reports whether ctx was cancelled because of an interrupt signal.

func IsVirtualizationEngineUnstable added in v0.8.0

func IsVirtualizationEngineUnstable(engine VirtualizationEngine) bool

func MarkBuildArtifactsComplete added in v0.27.0

func MarkBuildArtifactsComplete(artifacts []string) error

MarkBuildArtifactsComplete writes the completion markers of artifacts that reached their final path, e.g. after a successful build or OCI pull.

func MarkBuildArtifactsPending added in v0.27.0

func MarkBuildArtifactsPending(artifacts []string) (restore func() error, err error)

MarkBuildArtifactsPending marks all artifacts of a set as incomplete before a build or pull replaces any of them. If the replacement stops partway, the set stays incomplete instead of mixing new and old artifacts without markers, which would count as unverified and usable. MarkBuildArtifactsComplete replaces the markers once the whole set is in place. restore puts the previous markers back, for a replacement that left every artifact as it was.

func OSHasTypes added in v0.27.0

func OSHasTypes(osName string) bool

OSHasTypes reports whether osName has typed targets (such as ubuntu server and desktop). It is derived from the VM configurations, so commands, locks and the gateway agree on which targets carry a type.

func ParseWin11Build added in v0.20.0

func ParseWin11Build(sourceName string) string

ParseWin11Build extracts the build (e.g. "26300.9457") from Microsoft's ISO file name; "" if unknown.

func ParseWin11Release added in v0.20.0

func ParseWin11Release(sourceName string) string

ParseWin11Release extracts the release (e.g. "25H2") from Microsoft's ISO file name; "" if unknown.

func ProbeWin11ISO added in v0.20.0

func ProbeWin11ISO(url string) (int64, error)

ProbeWin11ISO returns the size of the ISO behind url without downloading it. It tries HEAD first and falls back to a one-byte ranged GET, because signed CDN URLs sometimes reject HEAD or omit Content-Length.

func RemoveBuildArtifactCompletionMarkers added in v0.27.0

func RemoveBuildArtifactCompletionMarkers(artifacts []string) error

RemoveBuildArtifactCompletionMarkers removes the completion markers of artifacts, e.g. together with the artifacts.

func RemoveBuildArtifacts

func RemoveBuildArtifacts(artifacts []string) error

func RemoveBuildArtifactsForConfig

func RemoveBuildArtifactsForConfig(config VirtualMachineConfig)

func RunBashScript

func RunBashScript(config RunProcessConfig) error

func RunBuildScript

func RunBuildScript(ctx context.Context, config VirtualMachineConfig, executable string, args []string, extraEnv ...string) (err error)

RunBuildScript runs a build script with the managed environment plus extraEnv. Cancelling ctx stops dependency downloads and the build's whole process group; the staged artifact is then discarded, so the final artifact path never holds a partial build.

func RunCliCommand added in v0.2.0

func RunCliCommand(workdir string, command string, args []string) ([]byte, error)

func RunCliCommandWithEnv added in v0.12.0

func RunCliCommandWithEnv(workdir string, command string, args []string, env []string) ([]byte, error)

func RunExternalProcess

func RunExternalProcess(config RunProcessConfig) (context.Context, error)

RunExternalProcess runs a helper process in a process group of its own. Cancelling config.Context terminates the group; without interrupt handling in config.Context, Ctrl+C is handled for the duration of the call.

func RunExternalProcessWithRetries

func RunExternalProcessWithRetries(config RunProcessConfig) context.Context

func RunFfmpegVideoGenerationProcess

func RunFfmpegVideoGenerationProcess(vm_config VirtualMachineConfig, ctx context.Context, process_config RunProcessConfig, recording_config *VncRecordingConfig) context.Context

func RunHypervUbuntuBuildOnWindows added in v0.3.0

func RunHypervUbuntuBuildOnWindows(ctx context.Context, config VirtualMachineConfig) error

RunHypervUbuntuBuildOnWindows builds an Ubuntu VM using Hyper-V on Windows.

func RunHypervWindowsBuildOnWindows added in v0.2.0

func RunHypervWindowsBuildOnWindows(ctx context.Context, config VirtualMachineConfig) error

RunHypervWindowsBuildOnWindows builds a Windows 11 VM using Hyper-V on Windows. It retries early failures to handle the transient "No ip address" race condition in the Packer HyperV plugin: StepRun calls GetHostAdapterIpAddressForSwitch with no retry, and attaching a new VM to the Default Switch can briefly disrupt the host adapter's IPv4 address. This failure always occurs within the first ~30 seconds; real build failures take 30+ minutes. Retries are skipped for long-running failures to avoid wasting CI time on genuine errors.

func RunPowerShellScript added in v0.2.0

func RunPowerShellScript(config RunProcessConfig) error

func RunQemuUbuntuBuildOnLinux added in v0.12.0

func RunQemuUbuntuBuildOnLinux(ctx context.Context, config VirtualMachineConfig) error

func RunQemuUbuntuBuildOnMacOS

func RunQemuUbuntuBuildOnMacOS(ctx context.Context, config VirtualMachineConfig) error

func RunQemuWindowsBuildOnLinux added in v0.14.0

func RunQemuWindowsBuildOnLinux(ctx context.Context, config VirtualMachineConfig) error

func RunQemuWindowsBuildOnMacOS

func RunQemuWindowsBuildOnMacOS(ctx context.Context, config VirtualMachineConfig) error

func RunVirtualBoxWindowsBuildOnWindows added in v0.2.0

func RunVirtualBoxWindowsBuildOnWindows(ctx context.Context, config VirtualMachineConfig) error

RunVirtualBoxWindowsBuildOnWindows builds a Windows 11 VM using VirtualBox on Windows.

func RunVncSnapshotProcess

func RunVncSnapshotProcess(vm_config VirtualMachineConfig, ctx context.Context, process_config RunProcessConfig, recording_config *VncRecordingConfig) context.Context

func TargetType added in v0.27.0

func TargetType(osName, requested string) string

TargetType returns the type a command uses for osName: requested for OSes with typed targets and empty for all others, including "all" and "local".

func UtmVMDirectory added in v0.27.0

func UtmVMDirectory() (string, error)

UtmVMDirectory resolves the destination shared by all UTM lifecycle commands. The legacy default directory is retained for existing VMs.

func UtmVirtualMachinePath added in v0.27.0

func UtmVirtualMachinePath(config VirtualMachineConfig) (string, error)

UtmVirtualMachinePath identifies the bundle created for config.

func ValidateInstance added in v0.27.0

func ValidateInstance(vm VirtualMachineConfig) error

ValidateInstance checks selectors before any provider command is executed.

func ValidateInstanceName added in v0.27.0

func ValidateInstanceName(name string) error

ValidateInstanceName accepts an empty name for the legacy default instance.

func VncSnapshotDir added in v0.19.0

func VncSnapshotDir(cacheDir string, vm_config VirtualMachineConfig) string

VncSnapshotDir is where the VNC snapshot process stores console frames for a VM. sailwright-gateway mirrors this layout without importing this package; a test in internal/gateway keeps both in sync.

func Win11ISOOffline added in v0.20.0

func Win11ISOOffline() bool

Win11ISOOffline reports whether Microsoft access is disabled (CI build jobs).

func Win11ObjectName added in v0.20.0

func Win11ObjectName(sourceName, arch string, firstSeen time.Time) string

Win11ObjectName builds the immutable remote object name from Microsoft's file name and the first-seen date. Unexpected source names use the requested architecture (amd64 or arm64) in the fallback.

func Win11RefreshDue added in v0.20.0

func Win11RefreshDue(m *Win11Manifest, now time.Time, latestRelease string, force bool) (bool, string)

Win11RefreshDue decides offline whether contacting Microsoft is worthwhile. latestRelease is the newest release announced by the release notes ("" if unknown). A newer announcement triggers one check only: announcements without general ISO media (e.g. device-specific releases) would otherwise contact Microsoft on every run. After that check, the age rule picks up media that Microsoft publishes later.

func Win11SourceNameFromURL added in v0.20.0

func Win11SourceNameFromURL(rawURL string) string

Win11SourceNameFromURL returns Microsoft's file name (the URL path basename, ignoring the query string).

Types

type ArtifactState added in v0.27.0

type ArtifactState string

ArtifactState describes whether a build artifact in the cache can be used.

const (
	// ArtifactStateExists means the artifact was completed by a successful build or pull.
	ArtifactStateExists ArtifactState = "exists"
	// ArtifactStateUnverified means the artifact has no completion marker, e.g. because
	// an older sailwright version produced it. It is still used, see legacyArtifactState.
	ArtifactStateUnverified ArtifactState = "unverified"
	// ArtifactStateIncomplete means a build or pull did not finish: the completion marker
	// does not match the artifact, or only staging/backup files of an interrupted build
	// are left.
	ArtifactStateIncomplete ArtifactState = "incomplete"
	// ArtifactStateMissing means there is no artifact.
	ArtifactStateMissing ArtifactState = "missing"
)

func BuildArtifactState added in v0.27.0

func BuildArtifactState(config VirtualMachineConfig) (ArtifactState, error)

BuildArtifactState returns the combined state of the build artifacts of config.

func (ArtifactState) Usable added in v0.27.0

func (s ArtifactState) Usable() bool

Usable reports whether builds may skip the artifact and VM commands may use it.

type Directories

type Directories struct {
	WorkingDir     string
	ProjectDir     string
	AppDataDir     string
	ConfigDir      string
	CacheDir       string
	VagrantDir     string
	PackerCacheDir string
}

func GetDirectoriesInstance

func GetDirectoriesInstance() *Directories

func UserSettingsDirectories added in v0.27.0

func UserSettingsDirectories() (Directories, error)

UserSettingsDirectories resolves CLI settings and cache paths without creating a project or unpacking runtime assets. It shares the managed directory policy.

func (*Directories) CachePath added in v0.8.0

func (u *Directories) CachePath(paths ...string) string

func (*Directories) ConfigPath added in v0.16.1

func (u *Directories) ConfigPath(paths ...string) string

func (*Directories) GetDirectories

func (u *Directories) GetDirectories() Directories

func (*Directories) ManagedEnv added in v0.8.0

func (u *Directories) ManagedEnv() []string

func (*Directories) PackerCachePath added in v0.8.0

func (u *Directories) PackerCachePath(paths ...string) string

func (*Directories) VagrantPath added in v0.8.0

func (u *Directories) VagrantPath(paths ...string) string

type HostOsType added in v0.2.0

type HostOsType string
const (
	HostOsLinux   HostOsType = "debian"
	HostOsWindows HostOsType = "windows"
	HostOsDarwin  HostOsType = "darwin"
)

func GetCurrentHostOs added in v0.2.0

func GetCurrentHostOs() HostOsType

type ProgressBarListener

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

ProgressBarListener implements getter.ProgressListener using an mpb container so that concurrent downloads render their bars cleanly on separate lines.

func (*ProgressBarListener) TrackProgress

func (p *ProgressBarListener) TrackProgress(src string, current, total int64, r io.ReadCloser) io.ReadCloser

type RunProcessConfig

type RunProcessConfig struct {
	ExecutablePath     string
	Args               []string
	Env                []string
	WorkingDir         string
	Timeout            time.Duration
	DelayBeforeStart   time.Duration
	Context            context.Context
	FailOnError        bool
	Retries            int
	RetryInterval      time.Duration
	InterruptRetryChan chan bool
	Silent             *atomic.Bool
}

type VirtualMachineConfig

type VirtualMachineConfig struct {
	// Name selects an independent instance; empty preserves the legacy default.
	Name                   string
	OS                     string
	Arch                   string
	UbuntuType             string
	VncPort                int
	Slug                   string
	ExpectedBuildArtifacts []string
	StagedBuildArtifacts   []string
	NoCache                bool
	HostOs                 HostOsType
	VirtualizationEngine   VirtualizationEngine
	Cpus                   int
	// MemoryMB is the desired VM memory in megabytes.
	// When 0 (the default), memory is calculated automatically:
	// max(4096, totalSystemMemoryMB - 4096).
	MemoryMB int
	Headless bool
	Verbose  bool
	// DetachedFromTerminal runs the build without access to the terminal, e.g. while
	// several builds run in parallel: Ctrl+C then reaches sailwright, and a prompt in
	// the build fails instead of stopping it.
	DetachedFromTerminal bool
}

func AvailableVirtualMachineConfigs

func AvailableVirtualMachineConfigs() []VirtualMachineConfig

func AvailableVirtualMachineConfigsForCurrentHostOS added in v0.2.0

func AvailableVirtualMachineConfigsForCurrentHostOS() []VirtualMachineConfig

func AvailableVirtualMachineConfigsForHostOS added in v0.4.0

func AvailableVirtualMachineConfigsForHostOS(hostOs HostOsType) []VirtualMachineConfig

func ParseInstanceName added in v0.27.0

func ParseInstanceName(providerName string, base VirtualMachineConfig) (VirtualMachineConfig, bool)

ParseInstanceName recognizes provider names without depending on local metadata.

type VirtualizationEngine added in v0.2.0

type VirtualizationEngine string
const (
	VirtualizationEngineQemu       VirtualizationEngine = "qemu"
	VirtualizationEngineTart       VirtualizationEngine = "tart"
	VirtualizationEngineUtm        VirtualizationEngine = "utm"
	VirtualizationEngineHyperv     VirtualizationEngine = "hyperv"
	VirtualizationEngineVirtualBox VirtualizationEngine = "virtualbox"
)

func CurrentHostVirtualizationEngines added in v0.4.0

func CurrentHostVirtualizationEngines() []VirtualizationEngine

func VirtualizationEnginesForVirtualMachineConfigs added in v0.4.0

func VirtualizationEnginesForVirtualMachineConfigs(configs []VirtualMachineConfig) []VirtualizationEngine

type VncRecordingConfig

type VncRecordingConfig struct {
	OutputFile      string
	OutputFolder    string
	OutputVideoFile string
	Password        string
	StreamedToVideo bool
}

type WebFileDependency

type WebFileDependency struct {
	LocalPath        string
	Checksum         string
	Source           string
	FallbackSources  []string
	RelatedVmConfigs []VirtualMachineConfig
	// BeforeHook is a function that is called before downloading the dependency. It can be used to modify the Source URL dynamically.
	BeforeHook func(ctx context.Context) (string, error)
	// PrepareHook runs during dependency reconciliation before the existence check, whether or not a
	// download follows. It can migrate or clean up related files in the cache.
	PrepareHook func()
	// FailureHint is appended to the error when every source fails.
	FailureHint string
}

type Win11HistoryEntry added in v0.20.0

type Win11HistoryEntry struct {
	Object      string `json:"object"`
	SHA256      string `json:"sha256"`
	PublishedAt string `json:"published_at"`
}

Win11HistoryEntry describes one published ISO object.

type Win11LinkInfo added in v0.20.0

type Win11LinkInfo struct {
	URL        string `json:"url"`
	SourceName string `json:"source_name"`
	SHA256     string `json:"sha256"`
}

Win11LinkInfo is written by playwright_win11_iso.py next to the URL file.

func ReadWin11LinkInfo added in v0.20.0

func ReadWin11LinkInfo(arch string) (*Win11LinkInfo, error)

ReadWin11LinkInfo reads the link description of the last resolution for an architecture.

func ResolveWindows11Link(arch string) (*Win11LinkInfo, error)

ResolveWindows11Link asks Microsoft (via Playwright) for the current ISO link. It returns ErrMicrosoftRefused when Microsoft blocks the request.

type Win11Manifest added in v0.20.0

type Win11Manifest struct {
	Schema      int    `json:"schema"`
	Arch        string `json:"arch"`
	Object      string `json:"object"`
	SourceName  string `json:"source_name"`
	Release     string `json:"release"`
	SHA256      string `json:"sha256"`
	Size        int64  `json:"size"`
	Build       string `json:"build"`
	PublishedAt string `json:"published_at"`
	CheckedAt   string `json:"checked_at"`
	// AnnouncedRelease is the newest release the release notes announced at the last successful check.
	// The release-notes trigger fires only once per announcement, see Win11RefreshDue.
	AnnouncedRelease string              `json:"announced_release,omitempty"`
	History          []Win11HistoryEntry `json:"history"`
}

Win11Manifest is the pointer file (win11-<arch>.json) to the current ISO object on the remote cache.

func LoadWin11Manifest added in v0.20.0

func LoadWin11Manifest(file string) (*Win11Manifest, error)

LoadWin11Manifest reads a manifest file. A missing file yields (nil, nil).

func (*Win11Manifest) CheckedTime added in v0.20.0

func (m *Win11Manifest) CheckedTime() time.Time

CheckedTime parses CheckedAt; the zero time is returned when unset or invalid.

func (*Win11Manifest) MarkRefreshDue added in v0.20.0

func (m *Win11Manifest) MarkRefreshDue(now time.Time)

MarkRefreshDue backdates CheckedAt so the next scheduled run contacts Microsoft. Unlike the epoch, the result stays well inside the staleness limit, so a refused first run does not fail.

func (*Win11Manifest) Promote added in v0.20.0

func (m *Win11Manifest) Promote(entry Win11HistoryEntry, sourceName string, size int64, now time.Time) []string

Promote makes entry the current ISO and returns the objects that fell out of the retention window. The object the manifest points to is never part of the returned list.

func (*Win11Manifest) Save added in v0.20.0

func (m *Win11Manifest) Save(file string) error

Save writes the manifest as indented JSON.

Jump to

Keyboard shortcuts

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