Documentation
¶
Index ¶
- Constants
- func Clean(atmosConfig *schema.AtmosConfiguration, opts CleanOptions) error
- func CleanAllWorkdirs(atmosConfig *schema.AtmosConfiguration) error
- func CleanExpiredWorkdirs(atmosConfig *schema.AtmosConfiguration, ttl string, dryRun bool) error
- func CleanWorkdir(atmosConfig *schema.AtmosConfiguration, component, stack string) error
- func MetadataPath(workdirPath string) string
- func ProvisionWorkdir(ctx context.Context, atmosConfig *schema.AtmosConfiguration, ...) error
- func UpdateLastAccessed(workdirPath string) error
- func WriteMetadata(workdirPath string, metadata *WorkdirMetadata) error
- type CleanOptions
- type DefaultFileSystem
- func (f *DefaultFileSystem) CopyDir(src, dst string) error
- func (f *DefaultFileSystem) Exists(path string) bool
- func (f *DefaultFileSystem) MkdirAll(path string, perm fs.FileMode) error
- func (f *DefaultFileSystem) ReadFile(path string) ([]byte, error)
- func (f *DefaultFileSystem) RemoveAll(path string) error
- func (f *DefaultFileSystem) Stat(path string) (fs.FileInfo, error)
- func (f *DefaultFileSystem) SyncDir(src, dst string, hasher Hasher) (bool, error)
- func (f *DefaultFileSystem) Walk(root string, fn fs.WalkDirFunc) error
- func (f *DefaultFileSystem) WriteFile(path string, data []byte, perm fs.FileMode) error
- type DefaultHasher
- type DefaultPathFilter
- type ExpiredWorkdirInfo
- type FileSystem
- type Hasher
- type PathFilter
- type Service
- type SourceType
- type WorkdirConfig
- type WorkdirMetadata
Constants ¶
const ( // DirPermissions is the default permission for created directories (rwxr-xr-x). DirPermissions = 0o755 // FilePermissionsSecure is the secure permission for sensitive files (rw-------). FilePermissionsSecure = 0o600 // FilePermissionsStandard is the standard permission for regular files (rw-r--r--). FilePermissionsStandard = 0o644 )
File permission constants.
const ( // ComponentKey is the key used to access component name in configuration. ComponentKey = "component" // WorkdirPathKey is the key used to store/retrieve the workdir path in component configuration. // This is set by the workdir provisioner and checked by terraform execution to override // the component path with the workdir path. WorkdirPathKey = "_workdir_path" )
String literal constants.
const AtmosDir = ".atmos"
AtmosDir is the Atmos-specific directory within each workdir.
const HookEventBeforeTerraformInit = provisioner.HookEvent("before.terraform.init")
HookEventBeforeTerraformInit is the hook event for before terraform init.
const MetadataFile = "metadata.json"
MetadataFile is the name of the metadata file within AtmosDir.
const WorkdirMetadataFile = ".workdir-metadata.json"
WorkdirMetadataFile is the legacy name of the metadata file. Deprecated: Use MetadataPath() instead.
const WorkdirPath = ".workdir"
WorkdirPath returns the standard workdir directory name.
Variables ¶
This section is empty.
Functions ¶
func Clean ¶
func Clean(atmosConfig *schema.AtmosConfiguration, opts CleanOptions) error
Clean performs cleanup based on the provided options.
func CleanAllWorkdirs ¶
func CleanAllWorkdirs(atmosConfig *schema.AtmosConfiguration) error
CleanAllWorkdirs removes all working directories in the project.
func CleanExpiredWorkdirs ¶ added in v1.206.0
func CleanExpiredWorkdirs(atmosConfig *schema.AtmosConfiguration, ttl string, dryRun bool) error
CleanExpiredWorkdirs removes workdirs whose LastAccessed is older than the specified TTL. If dryRun is true, it only reports what would be cleaned without actually deleting.
func CleanWorkdir ¶
func CleanWorkdir(atmosConfig *schema.AtmosConfiguration, component, stack string) error
CleanWorkdir removes the working directory for a specific component in a stack. The workdir name follows the stack-component naming convention (e.g., "dev-vpc").
func MetadataPath ¶ added in v1.206.0
MetadataPath returns the full path to the metadata file within a workdir.
func ProvisionWorkdir ¶
func ProvisionWorkdir( ctx context.Context, atmosConfig *schema.AtmosConfiguration, componentConfig map[string]any, authContext *schema.AuthContext, ) error
ProvisionWorkdir creates an isolated working directory and populates it with component files. This is the main provisioner function registered with the provisioner registry.
Activation rules: - Runs if provision.workdir.enabled: true (explicit opt-in for local components) - Does nothing otherwise (terraform runs in original component directory).
func UpdateLastAccessed ¶ added in v1.206.0
UpdateLastAccessed atomically updates only the last accessed timestamp.
func WriteMetadata ¶ added in v1.206.0
func WriteMetadata(workdirPath string, metadata *WorkdirMetadata) error
WriteMetadata writes metadata atomically with exclusive lock. Creates the .atmos/ directory if it doesn't exist.
Types ¶
type CleanOptions ¶
type CleanOptions struct {
// Component is the specific component to clean (empty for all).
Component string
// Stack is the stack name (required when Component is specified).
Stack string
// All cleans all workdirs in the project.
All bool
// Expired cleans only workdirs whose LastAccessed is older than TTL.
Expired bool
// TTL is the time-to-live duration for expired cleanup (e.g., "7d", "24h", "weekly").
// Required when Expired is true.
TTL string
// DryRun shows what would be cleaned without actually deleting.
DryRun bool
}
CleanOptions configures what to clean.
type DefaultFileSystem ¶
type DefaultFileSystem struct{}
DefaultFileSystem is the default implementation of the FileSystem interface.
func NewDefaultFileSystem ¶
func NewDefaultFileSystem() *DefaultFileSystem
NewDefaultFileSystem creates a new default file system implementation.
func (*DefaultFileSystem) CopyDir ¶
func (f *DefaultFileSystem) CopyDir(src, dst string) error
CopyDir recursively copies a directory from src to dst.
func (*DefaultFileSystem) Exists ¶
func (f *DefaultFileSystem) Exists(path string) bool
Exists checks if a path exists.
func (*DefaultFileSystem) MkdirAll ¶
func (f *DefaultFileSystem) MkdirAll(path string, perm fs.FileMode) error
MkdirAll creates a directory along with any necessary parents.
func (*DefaultFileSystem) ReadFile ¶
func (f *DefaultFileSystem) ReadFile(path string) ([]byte, error)
ReadFile reads the contents of a file.
func (*DefaultFileSystem) RemoveAll ¶
func (f *DefaultFileSystem) RemoveAll(path string) error
RemoveAll removes path and any children it contains.
func (*DefaultFileSystem) Stat ¶
func (f *DefaultFileSystem) Stat(path string) (fs.FileInfo, error)
Stat returns file info for the given path.
func (*DefaultFileSystem) SyncDir ¶ added in v1.206.0
func (f *DefaultFileSystem) SyncDir(src, dst string, hasher Hasher) (bool, error)
SyncDir performs a true sync: copies changed files, adds new files, deletes removed files. Returns true if any changes were made, false if directories were already in sync. Skips the .atmos/ directory which contains Atmos metadata.
func (*DefaultFileSystem) Walk ¶
func (f *DefaultFileSystem) Walk(root string, fn fs.WalkDirFunc) error
Walk walks the file tree rooted at root, calling fn for each file or directory.
type DefaultHasher ¶
type DefaultHasher struct{}
DefaultHasher is the default implementation of the Hasher interface.
func NewDefaultHasher ¶
func NewDefaultHasher() *DefaultHasher
NewDefaultHasher creates a new default hasher implementation.
type DefaultPathFilter ¶
type DefaultPathFilter struct{}
DefaultPathFilter is the default implementation of the PathFilter interface.
func NewDefaultPathFilter ¶
func NewDefaultPathFilter() *DefaultPathFilter
NewDefaultPathFilter creates a new default path filter implementation.
type ExpiredWorkdirInfo ¶ added in v1.206.0
type ExpiredWorkdirInfo struct {
// Path is the absolute path to the workdir.
Path string
// Name is the workdir name (e.g., "dev-vpc").
Name string
// LastAccessed is when the workdir was last accessed.
LastAccessed time.Time
// Age is how long ago the workdir was last accessed.
Age time.Duration
}
ExpiredWorkdirInfo contains information about an expired workdir.
type FileSystem ¶
type FileSystem interface {
// MkdirAll creates a directory along with any necessary parents.
MkdirAll(path string, perm fs.FileMode) error
// RemoveAll removes path and any children it contains.
RemoveAll(path string) error
// Exists checks if a path exists.
Exists(path string) bool
// ReadFile reads the contents of a file.
ReadFile(path string) ([]byte, error)
// WriteFile writes data to a file with the given permissions.
WriteFile(path string, data []byte, perm fs.FileMode) error
// CopyDir recursively copies a directory from src to dst.
CopyDir(src, dst string) error
// SyncDir syncs files from src to dst using per-file checksums.
// Only copies changed files, adds new files, and deletes removed files.
// Skips the .atmos/ directory which contains Atmos metadata.
// Returns true if any changes were made, false if directories were in sync.
SyncDir(src, dst string, hasher Hasher) (bool, error)
// Walk walks the file tree rooted at root, calling fn for each file or directory.
Walk(root string, fn fs.WalkDirFunc) error
// Stat returns file info for the given path.
Stat(path string) (fs.FileInfo, error)
}
FileSystem abstracts file system operations for testability.
type Hasher ¶
type Hasher interface {
// HashDir computes a hash of all files in a directory.
HashDir(path string) (string, error)
// HashFile computes a hash of a single file.
HashFile(path string) (string, error)
}
Hasher computes content hashes for change detection.
type PathFilter ¶
type PathFilter interface {
// Match returns true if the path should be included.
Match(path string, includedPaths, excludedPaths []string) (bool, error)
}
PathFilter filters paths based on include/exclude patterns.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service coordinates workdir provisioning operations. The workdir provisioner copies local component files to an isolated working directory.
func NewService ¶
func NewService() *Service
NewService creates a new workdir service with default implementations.
func NewServiceWithDeps ¶
func NewServiceWithDeps(fs FileSystem, hasher Hasher) *Service
NewServiceWithDeps creates a new workdir service with injected dependencies.
type SourceType ¶
type SourceType string
SourceType indicates the type of component source.
const ( // SourceTypeLocal indicates the component source is a local path. SourceTypeLocal SourceType = "local" // SourceTypeRemote indicates the component source is a remote URI. SourceTypeRemote SourceType = "remote" )
type WorkdirConfig ¶
type WorkdirConfig struct {
// Enabled controls whether workdir provisioning is active.
// Defaults to false; set provision.workdir.enabled: true to enable.
Enabled bool `yaml:"enabled,omitempty" json:"enabled,omitempty" mapstructure:"enabled"`
}
WorkdirConfig holds configuration for the workdir provisioner.
type WorkdirMetadata ¶
type WorkdirMetadata struct {
// Component is the component name.
Component string `json:"component"`
// Stack is the stack name (optional, for stack-specific workdirs).
Stack string `json:"stack,omitempty"`
// SourceType indicates the source type ("local" or "remote").
SourceType SourceType `json:"source_type"`
// Source is the original component source path.
Source string `json:"source,omitempty"`
// SourceURI is the remote source URI (for remote sources).
SourceURI string `json:"source_uri,omitempty"`
// SourceVersion is the remote source version (for remote sources).
SourceVersion string `json:"source_version,omitempty"`
// CreatedAt is when the workdir was created.
CreatedAt time.Time `json:"created_at"`
// UpdatedAt is when the workdir was last updated.
UpdatedAt time.Time `json:"updated_at"`
// LastAccessed is when the workdir was last accessed (for TTL tracking).
LastAccessed time.Time `json:"last_accessed,omitempty"`
// ContentHash is a hash of the source content for change detection (local sources only).
ContentHash string `json:"content_hash,omitempty"`
}
WorkdirMetadata stores metadata about a working directory. This is persisted to .atmos/metadata.json in each workdir.
func ReadMetadata ¶ added in v1.206.0
func ReadMetadata(workdirPath string) (*WorkdirMetadata, error)
ReadMetadata reads workdir metadata with read lock. Returns nil, nil if metadata file doesn't exist (not an error).