dependencies

package
v1.210.0-rc.0 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildToolchainPATH

func BuildToolchainPATH(atmosConfig *schema.AtmosConfiguration, dependencies map[string]string) (string, error)

BuildToolchainPATH constructs a PATH string with toolchain binaries prepended. This function does NOT modify the global environment - it returns the PATH string which should be added to ComponentEnvList for subprocess execution.

func ExtractDependenciesFromConfig

func ExtractDependenciesFromConfig(config map[string]any) map[string]string

ExtractDependenciesFromConfig extracts dependencies.tools from a config map.

func LoadToolVersionsDependencies added in v1.204.0

func LoadToolVersionsDependencies(atmosConfig *schema.AtmosConfiguration) (map[string]string, error)

LoadToolVersionsDependencies loads tools from .tool-versions as a dependency map. Returns an empty map if the file doesn't exist (no error). The first version listed for each tool is used as the default.

func MergeDependencies

func MergeDependencies(parent map[string]string, child map[string]string) (map[string]string, error)

MergeDependencies merges child dependencies into parent with constraint validation. Child values override parent values, but must satisfy parent constraints.

func UpdatePathForTools

func UpdatePathForTools(atmosConfig *schema.AtmosConfiguration, dependencies map[string]string) error

UpdatePathForTools updates PATH environment variable to include tool binaries. Deprecated: Use BuildToolchainPATH() instead and add to ComponentEnvList. This function is kept for backwards compatibility but should not be used.

func ValidateConstraint

func ValidateConstraint(version string, constraint string) error

ValidateConstraint validates that a specific version satisfies a constraint.

Types

type BatchInstallFunc added in v1.204.0

type BatchInstallFunc func(toolSpecs []string, reinstallFlag bool) error

BatchInstallFunc is the function signature for batch installing multiple tools. Shows status messages scrolling up with a single progress bar at bottom.

type BinaryPathFinder added in v1.204.0

type BinaryPathFinder interface {
	FindBinaryPath(owner, repo, version string, binaryName ...string) (string, error)
}

BinaryPathFinder finds installed tool binaries. This interface allows testing without the full toolchain installer.

type InstallFunc

type InstallFunc func(toolSpec string, setAsDefault, reinstallFlag, showHint, showProgressBar bool) error

InstallFunc is the function signature for installing a tool. The showHint parameter controls whether to show the PATH export hint message. The showProgressBar parameter controls whether to show spinner and success messages.

type InstalledVersionLister

type InstalledVersionLister interface {
	ListInstalledVersions(owner, repo string) ([]string, error)
}

InstalledVersionLister lists locally installed versions for a tool. Used to check if an installed version already satisfies a constraint before making a network call to resolve it.

type Installer

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

Installer handles automatic tool installation.

func NewInstaller

func NewInstaller(atmosConfig *schema.AtmosConfiguration, opts ...InstallerOption) *Installer

NewInstaller creates a new tool installer.

func (*Installer) EnsureTools

func (i *Installer) EnsureTools(dependencies map[string]string) error

EnsureTools ensures all required tools are installed. Installs missing tools automatically using batch install with progress bar. Version constraints (e.g., "^1.10.0", "~> 1.5") are resolved to concrete versions before installation. The dependency map is updated in-place with resolved versions so downstream callers (PATH building, binary lookup) use concrete version strings.

func (*Installer) ResolveExecutablePath

func (i *Installer) ResolveExecutablePath(deps map[string]string, executable string) string

ResolveExecutablePath resolves a bare executable name (e.g., "tofu") to its absolute path using the toolchain dependency map. This is needed when the executable is installed via `atmos toolchain install` and is not on the system PATH.

Resolution order:

  1. For each dependency, check if the toolchain-installed binary matches the executable name.
  2. Fall back to exec.LookPath to check the system PATH.
  3. If nothing found, return the original name (let the caller fail with a clear error).

type InstallerOption

type InstallerOption func(*Installer)

InstallerOption is a functional option for configuring Installer.

func WithBatchInstallFunc added in v1.204.0

func WithBatchInstallFunc(fn BatchInstallFunc) InstallerOption

WithBatchInstallFunc sets a custom batch install function (for testing).

func WithBinaryPathFinder added in v1.204.0

func WithBinaryPathFinder(finder BinaryPathFinder) InstallerOption

WithBinaryPathFinder sets a custom binary path finder (for testing).

func WithFileExistsFunc

func WithFileExistsFunc(fn func(path string) bool) InstallerOption

WithFileExistsFunc sets a custom file exists function (for testing).

func WithInstallFunc

func WithInstallFunc(fn InstallFunc) InstallerOption

WithInstallFunc sets a custom install function (for testing).

func WithInstalledVersionLister

func WithInstalledVersionLister(lister InstalledVersionLister) InstallerOption

WithInstalledVersionLister sets a custom installed version lister (for testing).

func WithResolver

func WithResolver(resolver toolchain.ToolResolver) InstallerOption

WithResolver sets a custom ToolResolver (for testing).

func WithVersionLister

func WithVersionLister(lister VersionLister) InstallerOption

WithVersionLister sets a custom version lister (for testing).

type Resolver

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

Resolver resolves tool dependencies with inheritance and validation.

func NewResolver

func NewResolver(atmosConfig *schema.AtmosConfiguration) *Resolver

NewResolver creates a new dependency resolver.

func (*Resolver) ResolveCommandDependencies

func (r *Resolver) ResolveCommandDependencies(command *schema.Command) (map[string]string, error)

ResolveCommandDependencies resolves tool dependencies for a custom command.

func (*Resolver) ResolveComponentDependencies

func (r *Resolver) ResolveComponentDependencies(
	componentType string,
	stackConfig map[string]any,
	componentConfig map[string]any,
) (map[string]string, error)

ResolveComponentDependencies resolves tool dependencies for a component. Merges 3 scopes from stack configuration (lowest to highest priority):

  1. Global scope: top-level dependencies
  2. Component type scope: terraform.dependencies / helmfile.dependencies / packer.dependencies
  3. Component instance scope: components.terraform.vpc.dependencies

Parameters:

  • componentType: "terraform", "helmfile", or "packer"
  • stackConfig: Full merged stack configuration (includes all scopes)
  • componentConfig: Merged component configuration

func (*Resolver) ResolveWorkflowDependencies

func (r *Resolver) ResolveWorkflowDependencies(workflowDef *schema.WorkflowDefinition) (map[string]string, error)

ResolveWorkflowDependencies resolves tool dependencies for a workflow.

type ToolProvisioner

type ToolProvisioner interface {
	// EnsureTools installs any missing tools for the given dependency map.
	EnsureTools(deps map[string]string) error
	// ResolveToolName maps a tool name to its owner/repo pair.
	ResolveToolName(tool string) (owner, repo string, err error)
	// FindBinaryPath locates the installed binary for a given owner/repo/version.
	FindBinaryPath(owner, repo, version string, binaryName ...string) (string, error)
	// BuildPATH constructs the augmented PATH containing toolchain bin dirs.
	BuildPATH(atmosConfig *schema.AtmosConfiguration, deps map[string]string) (string, error)
}

ToolProvisioner abstracts tool installation and resolution for testing. Production code uses the concrete Installer; tests inject a mock generated by mockgen.

type ToolchainEnvironment

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

ToolchainEnvironment holds resolved executable paths and a subprocess PATH for a set of toolchain dependencies. Create one per command invocation using ForComponent, ForSections, or ForWorkflow, then use Resolve() and EnvVars() to configure subprocess execution.

func ForComponent

func ForComponent(
	atmosConfig *schema.AtmosConfiguration,
	componentType string,
	stackSection map[string]any,
	componentSection map[string]any,
) (*ToolchainEnvironment, error)

ForComponent creates a ToolchainEnvironment by resolving dependencies from component stack configuration. The componentType is "terraform", "helmfile", or "packer". Pass nil for stackSection/componentSection when no component context is available (e.g. version commands).

func ForSections

func ForSections(atmosConfig *schema.AtmosConfiguration, sections map[string]any) (*ToolchainEnvironment, error)

ForSections creates a ToolchainEnvironment from pre-loaded configuration sections (e.g. from DescribeComponent). Dependencies are extracted from the sections using ExtractDependenciesFromConfig.

func ForWorkflow

func ForWorkflow(atmosConfig *schema.AtmosConfiguration, workflowDef *schema.WorkflowDefinition, opts ...envOption) (*ToolchainEnvironment, error)

ForWorkflow creates a ToolchainEnvironment for workflow execution. Merges .tool-versions with workflow-specific dependencies.

func (*ToolchainEnvironment) EnvVars

func (e *ToolchainEnvironment) EnvVars() []string

EnvVars returns a slice containing "PATH=<toolchain-augmented-path>" ready to append to a subprocess environment. Returns nil if no toolchain dependencies were resolved (no-op — does not override the system PATH).

func (*ToolchainEnvironment) PATH

func (e *ToolchainEnvironment) PATH() string

PATH returns the augmented PATH string with toolchain bin dirs prepended, or an empty string if no toolchain dependencies were resolved.

func (*ToolchainEnvironment) PrependToPath

func (e *ToolchainEnvironment) PrependToPath(basePATH string) string

PrependToPath prepends toolchain bin dirs to the given PATH string. If there are no toolchain dirs, returns basePATH unchanged.

func (*ToolchainEnvironment) Resolve

func (e *ToolchainEnvironment) Resolve(command string) string

Resolve returns the absolute path for a command name. If the command was installed via the toolchain, returns the toolchain path. Otherwise falls back to exec.LookPath, then returns the original name unchanged.

func (*ToolchainEnvironment) ToolchainDirs

func (e *ToolchainEnvironment) ToolchainDirs() []string

ToolchainDirs returns only the toolchain bin directories without the system PATH. Use this to prepend toolchain paths to an existing PATH without losing other entries.

type VersionLister

type VersionLister interface {
	GetAvailableVersions(owner, repo string) ([]string, error)
}

VersionLister fetches available versions for a tool from its release source. This interface decouples constraint resolution from the concrete registry implementation.

Jump to

Keyboard shortcuts

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