Documentation
¶
Overview ¶
Package ami provides Prism's AMI creation system.
Package ami provides Prism's AMI creation system.
Package ami provides Prism's AMI creation system.
Package ami provides Prism's AMI creation system.
Package ami provides Prism's AMI creation system.
Package ami provides Prism's AMI creation system.
Package ami provides Prism's AMI creation system.
Package ami provides Prism's AMI creation system.
Package ami provides Prism's AMI creation system.
Package ami provides Prism's AMI creation system.
This file implements the template management interface for Prism's AMI creation system. It provides functionality for importing, exporting, creating, modifying, and sharing templates across different sources and formats.
The template management system implements Prism's "Progressive Disclosure" principle by providing simple interfaces for common operations while enabling advanced capabilities for power users.
Key Components:
- TemplateManager: Central template management coordinator
- Template operations: Import, export, create, modify, validate, and share
- Template metadata tracking: Source, validation status, and modification time
- Format conversion: YAML, JSON, and other interchange formats
Package ami provides Prism's AMI creation system.
Package ami provides Prism's AMI creation system.
Package ami provides Prism's AMI creation system.
This package implements automated building of Amazon Machine Images (AMIs) for Prism templates. It handles YAML template parsing, EC2 instance management for building, AMI creation, and validation.
Key Components:
- Builder: Core AMI creation service with EC2 orchestration
- Parser: YAML template parser and validator
- Registry: AMI version management and lookup service
- Validator: AMI build validation framework
The AMI builder implements Prism's core principle of "Default to Success" by ensuring every template has reliable, pre-built AMIs available across all supported regions and architectures.
Index ¶
- func CompareVersions(version1, version2 string) (int, error)
- func FormatError(err error) string
- func IsNetworkError(err error) bool
- func IsRetryable(err error) bool
- func IsValidationError(err error) bool
- type AMICopyStep
- type AMICreationStep
- type BaseAMIStep
- type BuildError
- func CommandError(message string, cause error) *BuildError
- func ConfigurationError(message string, cause error) *BuildError
- func DependencyError(message string, cause error) *BuildError
- func ImageCreationError(message string, cause error) *BuildError
- func InstanceError(message string, cause error) *BuildError
- func InternalError(message string, cause error) *BuildError
- func NetworkError(message string, cause error) *BuildError
- func NewBuildError(errType ErrorType, message string, cause error) *BuildError
- func NewRetryableBuildError(errType ErrorType, message string, cause error) *BuildError
- func RegistryError(message string, cause error) *BuildError
- func SSMError(message string, cause error) *BuildError
- func TemplateExportError(message string, cause error) *BuildError
- func TemplateImportError(message string, cause error) *BuildError
- func TemplateManagementError(message string, cause error) *BuildError
- func ValidationError(message string, cause error) *BuildError
- type BuildExecutionStep
- type BuildPipeline
- type BuildRequest
- type BuildResult
- type BuildStep
- type Builder
- type BuilderInstanceStep
- type CleanupStep
- type Clock
- type CompatibleVersionChecker
- type Cost
- type DefaultClock
- type Dependency
- type DependencyResolver
- func (r *DependencyResolver) FindCompatibleVersions(templateName, constraint, operator string) ([]string, error)
- func (r *DependencyResolver) ResolveAndFetchDependencies(templateName string, fetchMissing bool) (map[string]*ResolvedDependency, []string, error)
- func (r *DependencyResolver) ResolveDependencies(templateName string) (map[string]*ResolvedDependency, []string, error)
- func (r *DependencyResolver) ResolveDependencyConflicts(conflicts map[string][]TemplateDependency) (map[string]string, error)
- type Documentation
- type Domain
- type EnhancedBuildRequest
- type EnhancedBuildResult
- type EnhancedBuildStep
- type EnhancedTemplate
- type ErrorType
- type ExactVersionChecker
- type ExactVersionValidator
- type GreaterThanChecker
- type GreaterThanOrEqualChecker
- type GreaterThanOrEqualValidator
- type GreaterThanValidator
- type IdleDetection
- type InstanceAMICopyStep
- type InstanceAMICreationStep
- type InstanceDetailsStep
- type InstanceSavePipeline
- type InstanceSaveRequest
- type InstanceSaveStep
- type InstanceStopStep
- type LessThanChecker
- type LessThanOrEqualChecker
- type LessThanOrEqualValidator
- type LessThanValidator
- type Parser
- func (p *Parser) ListTemplates() ([]string, error)
- func (p *Parser) LoadEnhancedTemplateFromFile(templatePath string) (*Template, error)
- func (p *Parser) ParseEnhancedTemplate(templatePath string) (*Template, error)
- func (p *Parser) ParseTemplate(content string) (*Template, error)
- func (p *Parser) ParseTemplateFile(templatePath string) (*Template, error)
- func (p *Parser) ValidateTemplate(template *Template) error
- func (p *Parser) ValidateTemplateFile(templatePath string) error
- func (p *Parser) ValidateWithSchema(template *Template, validator *SchemaValidator) error
- func (p *Parser) WriteTemplate(template *Template, writer io.Writer) error
- type PipelineStep
- type RealClock
- type Reference
- type Registry
- func (r *Registry) DeleteAMI(ctx context.Context, templateName, region, architecture string) error
- func (r *Registry) DeleteSharedTemplate(ctx context.Context, templateName, version string) error
- func (r *Registry) GetLatestAMIByVersion(ctx context.Context, templateName, region, architecture string) (*Reference, error)
- func (r *Registry) GetSharedTemplate(ctx context.Context, templateName, version string) (*TemplateRegistryEntry, error)
- func (r *Registry) GetTemplateLatestVersion(ctx context.Context, templateName string) (string, error)
- func (r *Registry) ListSharedTemplateVersions(ctx context.Context, templateName string) ([]string, error)
- func (r *Registry) ListSharedTemplates(ctx context.Context) (map[string]*TemplateRegistryEntry, error)
- func (r *Registry) ListTemplateAMIs(ctx context.Context, templateName string) ([]*Reference, error)
- func (r *Registry) ListTemplates(ctx context.Context) ([]string, error)
- func (r *Registry) ListVersions(ctx context.Context, templateName, region, architecture string) ([]string, error)
- func (r *Registry) LookupAMI(ctx context.Context, templateName, region, architecture string) (*Reference, error)
- func (r *Registry) LookupVersionedAMI(ctx context.Context, templateName, region, architecture, version string) (*Reference, error)
- func (r *Registry) PublishAMI(ctx context.Context, buildResult *BuildResult) error
- func (r *Registry) PublishTemplate(ctx context.Context, templateName, templateData, format string, ...) error
- func (r *Registry) PublishVersionedAMI(ctx context.Context, buildResult *BuildResult) error
- type RegistryPublishStep
- type Repository
- type ResolvedDependency
- type Resources
- type RestrictiveVersions
- type SchemaValidator
- type SharedTemplateEntry
- type Size
- type Template
- type TemplateBuilder
- func (b *TemplateBuilder) AddBuildStep(name, script string) *TemplateBuilder
- func (b *TemplateBuilder) AddBuildStepWithTimeout(name, script string, timeoutSeconds int) *TemplateBuilder
- func (b *TemplateBuilder) AddValidation(name, command string, success bool, contains, equals string) *TemplateBuilder
- func (b *TemplateBuilder) Build() (*Template, error)
- func (b *TemplateBuilder) WithArchitecture(arch string) *TemplateBuilder
- func (b *TemplateBuilder) WithBase(base string) *TemplateBuilder
- func (b *TemplateBuilder) WithMinDiskSize(sizeGB int) *TemplateBuilder
- func (b *TemplateBuilder) WithTag(key, value string) *TemplateBuilder
- type TemplateDefinitionStep
- type TemplateDependency
- type TemplateExportOptions
- type TemplateImportOptions
- type TemplateManager
- func (m *TemplateManager) AddDependency(templateName string, dependency TemplateDependency) error
- func (m *TemplateManager) CreateTemplate(name, description string) *TemplateBuilder
- func (m *TemplateManager) CreateTemplateVersion(templateName, component string) (*TemplateBuilder, error)
- func (m *TemplateManager) DeleteTemplate(name string, deleteFile bool) error
- func (m *TemplateManager) ExportToFile(templateName, filePath string, options *TemplateExportOptions) error
- func (m *TemplateManager) ExportToJSON(templateName string, prettyPrint bool) ([]byte, error)
- func (m *TemplateManager) ExportToYAML(templateName string) ([]byte, error)
- func (m *TemplateManager) GetDependencyGraph(templateName string) ([]string, error)
- func (m *TemplateManager) GetTemplate(name string) (*Template, error)
- func (m *TemplateManager) GetTemplateVersion(templateName string) (*VersionInfo, error)
- func (m *TemplateManager) ImportFromFile(filePath string, options *TemplateManagerImportOptions) (*Template, error)
- func (m *TemplateManager) ImportFromGitHub(repo, path, ref string, options *TemplateManagerImportOptions) (*Template, error)
- func (m *TemplateManager) ImportFromTemplate(template *Template, options *TemplateImportOptions) (*Template, error)
- func (m *TemplateManager) ImportFromURL(url string, options *TemplateManagerImportOptions) (*Template, error)
- func (m *TemplateManager) IncrementTemplateVersion(templateName, component string) (*VersionInfo, error)
- func (m *TemplateManager) ListTemplates(includeDirectory bool) (map[string]*Template, error)
- func (m *TemplateManager) ModifyTemplate(name string) (*TemplateBuilder, error)
- func (m *TemplateManager) RemoveDependency(templateName string, dependencyName string) (bool, error)
- func (m *TemplateManager) SetTemplateVersion(templateName string, version *VersionInfo) error
- func (m *TemplateManager) ShareTemplate(templateName string, ctx context.Context) error
- func (m *TemplateManager) ValidateTemplate(templateName string) error
- func (m *TemplateManager) ValidateTemplateDependencies(templateName string, dependencies []TemplateDependency) error
- func (m *TemplateManager) VersionTemplate(templateName string, newVersion *VersionInfo, component string) (*Template, error)
- type TemplateManagerImportOptions
- type TemplateMetadata
- type TemplateRegistryEntry
- type TroubleshootingItem
- type UsageExample
- type Validation
- type ValidationExecutionStep
- type ValidationResult
- type ValidationStep
- type ValidationTest
- type Validator
- type ValidatorOptions
- type VersionChecker
- type VersionInfo
- type VersionValidator
- type Workflow
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CompareVersions ¶
CompareVersions compares two version strings using semantic versioning rules
func IsNetworkError ¶
IsNetworkError checks if the error is a network error.
func IsValidationError ¶
IsValidationError checks if the error is a validation error.
Types ¶
type AMICopyStep ¶
type AMICopyStep struct{}
AMICopyStep copies the AMI to target regions
func (*AMICopyStep) Execute ¶
func (a *AMICopyStep) Execute(ctx context.Context, pipeline *BuildPipeline) error
func (*AMICopyStep) GetName ¶
func (a *AMICopyStep) GetName() string
type AMICreationStep ¶
type AMICreationStep struct{}
AMICreationStep creates the AMI from the builder instance
func (*AMICreationStep) Execute ¶
func (a *AMICreationStep) Execute(ctx context.Context, pipeline *BuildPipeline) error
func (*AMICreationStep) GetName ¶
func (a *AMICreationStep) GetName() string
type BaseAMIStep ¶
type BaseAMIStep struct{}
BaseAMIStep retrieves and validates the base AMI
func (*BaseAMIStep) Execute ¶
func (b *BaseAMIStep) Execute(ctx context.Context, pipeline *BuildPipeline) error
func (*BaseAMIStep) GetName ¶
func (b *BaseAMIStep) GetName() string
type BuildError ¶
type BuildError struct {
Type ErrorType
Message string
Cause error
Context map[string]string
Retryable bool
}
BuildError represents an error that occurred during AMI building.
func CommandError ¶
func CommandError(message string, cause error) *BuildError
CommandError creates a new command execution error.
func ConfigurationError ¶
func ConfigurationError(message string, cause error) *BuildError
ConfigurationError creates a new configuration error.
func DependencyError ¶
func DependencyError(message string, cause error) *BuildError
DependencyError creates a new dependency error.
func ImageCreationError ¶
func ImageCreationError(message string, cause error) *BuildError
ImageCreationError creates a new AMI creation error.
func InstanceError ¶
func InstanceError(message string, cause error) *BuildError
InstanceError creates a new instance error.
func InternalError ¶
func InternalError(message string, cause error) *BuildError
InternalError creates a new internal error.
func NetworkError ¶
func NetworkError(message string, cause error) *BuildError
NetworkError creates a new network configuration error.
func NewBuildError ¶
func NewBuildError(errType ErrorType, message string, cause error) *BuildError
NewBuildError creates a new BuildError.
func NewRetryableBuildError ¶
func NewRetryableBuildError(errType ErrorType, message string, cause error) *BuildError
NewRetryableBuildError creates a new BuildError that is retryable.
func RegistryError ¶
func RegistryError(message string, cause error) *BuildError
RegistryError creates a new registry error.
func SSMError ¶
func SSMError(message string, cause error) *BuildError
SSMError creates a new SSM service error.
func TemplateExportError ¶
func TemplateExportError(message string, cause error) *BuildError
TemplateExportError creates a new template export error.
func TemplateImportError ¶
func TemplateImportError(message string, cause error) *BuildError
TemplateImportError creates a new template import error.
func TemplateManagementError ¶
func TemplateManagementError(message string, cause error) *BuildError
TemplateManagementError creates a new template management error.
func ValidationError ¶
func ValidationError(message string, cause error) *BuildError
ValidationError creates a new validation error.
func (*BuildError) Error ¶
func (e *BuildError) Error() string
Error implements the error interface.
func (*BuildError) FormatErrorDetails ¶
func (e *BuildError) FormatErrorDetails() string
FormatErrorDetails returns a formatted string with error details.
func (*BuildError) IsRetryable ¶
func (e *BuildError) IsRetryable() bool
IsRetryable returns whether the error is retryable.
func (*BuildError) Unwrap ¶
func (e *BuildError) Unwrap() error
Unwrap returns the underlying error.
func (*BuildError) WithContext ¶
func (e *BuildError) WithContext(key, value string) *BuildError
WithContext adds context information to the error.
type BuildExecutionStep ¶
type BuildExecutionStep struct{}
BuildExecutionStep executes all build steps
func (*BuildExecutionStep) Execute ¶
func (b *BuildExecutionStep) Execute(ctx context.Context, pipeline *BuildPipeline) error
func (*BuildExecutionStep) GetName ¶
func (b *BuildExecutionStep) GetName() string
type BuildPipeline ¶
type BuildPipeline struct {
// contains filtered or unexported fields
}
BuildPipeline represents the AMI build pipeline using Builder Pattern (SOLID)
func NewBuildPipeline ¶
func NewBuildPipeline(builder *Builder, request BuildRequest) *BuildPipeline
NewBuildPipeline creates a new build pipeline
func (*BuildPipeline) Execute ¶
func (p *BuildPipeline) Execute(ctx context.Context) (*BuildResult, error)
Execute runs the complete build pipeline
type BuildRequest ¶
type BuildRequest struct {
TemplateName string
Template Template
Region string
Architecture string
Version string // Semantic version in format major.minor.patch
DryRun bool
BuildID string
BuildType string // "scheduled", "manual", "ci"
VpcID string
SubnetID string
SecurityGroup string
CopyToRegions []string // Regions to copy the AMI to after building
SetAsDefault bool // Whether to set this AMI as the default latest
}
BuildRequest contains parameters for building an AMI
type BuildResult ¶
type BuildResult struct {
TemplateID string
TemplateName string
Region string
Architecture string
AMIID string
CopiedAMIs map[string]string // Region -> AMI ID map of copied AMIs
BuildTime time.Time
BuildDuration time.Duration
Status string
ErrorMessage string
Logs string
BuilderID string
ValidationLog string
SourceAMI string // Base AMI used as the source for this build
Version string // Semantic version of the template
}
BuildResult contains the outcome of an AMI build
func (*BuildResult) IsSuccessful ¶
func (b *BuildResult) IsSuccessful() bool
IsSuccessful returns true if the build was successful
type BuildStep ¶
type BuildStep struct {
Name string `yaml:"name"`
Script string `yaml:"script"`
// Optional timeout in seconds (default: 600)
TimeoutSeconds int `yaml:"timeout_seconds,omitempty"`
}
BuildStep represents a single step in the AMI build process
type Builder ¶
type Builder struct {
EC2Client *ec2.Client
SSMClient *ssm.Client
RegistryClient *Registry
BaseAMIs map[string]map[string]string // region -> arch -> ami
DefaultVPC string
DefaultSubnet string
BuilderRole string
BuilderProfile string
SecurityGroupID string
}
Builder handles the AMI creation process
func NewBuilder ¶
func NewBuilder(ec2Client *ec2.Client, ssmClient *ssm.Client, registry *Registry, config map[string]string) (*Builder, error)
NewBuilder creates a new AMI builder with the provided configuration
func (*Builder) BuildAMI ¶
func (b *Builder) BuildAMI(ctx context.Context, request BuildRequest) (*BuildResult, error)
BuildAMI builds an AMI from a template BuildAMI builds an AMI using the Builder Pattern (SOLID: Single Responsibility)
func (*Builder) CreateAMIFromInstance ¶
func (b *Builder) CreateAMIFromInstance(ctx context.Context, request InstanceSaveRequest) (*BuildResult, error)
CreateAMIFromInstance creates an AMI from a running Prism instance using Builder Pattern (SOLID: Single Responsibility)
type BuilderInstanceStep ¶
type BuilderInstanceStep struct{}
BuilderInstanceStep launches the builder instance
func (*BuilderInstanceStep) Execute ¶
func (b *BuilderInstanceStep) Execute(ctx context.Context, pipeline *BuildPipeline) error
func (*BuilderInstanceStep) GetName ¶
func (b *BuilderInstanceStep) GetName() string
type CleanupStep ¶
type CleanupStep struct{}
CleanupStep performs cleanup operations
func (*CleanupStep) Execute ¶
func (c *CleanupStep) Execute(ctx context.Context, pipeline *BuildPipeline) error
func (*CleanupStep) GetName ¶
func (c *CleanupStep) GetName() string
type CompatibleVersionChecker ¶
type CompatibleVersionChecker struct{}
CompatibleVersionChecker validates ~> version constraints (Strategy Pattern)
func (*CompatibleVersionChecker) Check ¶
func (c *CompatibleVersionChecker) Check(version *VersionInfo, constraint *VersionInfo) bool
type Cost ¶
type Cost struct {
// BaseDailyUSD is the base daily cost estimate in USD for the default size
BaseDailyUSD float64 `yaml:"base_daily" json:"base_daily"`
// XSDailyUSD is the daily cost estimate in USD for the XS size
XSDailyUSD float64 `yaml:"xs_daily,omitempty" json:"xs_daily,omitempty"`
// SDailyUSD is the daily cost estimate in USD for the S size
SDailyUSD float64 `yaml:"s_daily,omitempty" json:"s_daily,omitempty"`
// MDailyUSD is the daily cost estimate in USD for the M size
MDailyUSD float64 `yaml:"m_daily,omitempty" json:"m_daily,omitempty"`
// LDailyUSD is the daily cost estimate in USD for the L size
LDailyUSD float64 `yaml:"l_daily,omitempty" json:"l_daily,omitempty"`
// XLDailyUSD is the daily cost estimate in USD for the XL size
XLDailyUSD float64 `yaml:"xl_daily,omitempty" json:"xl_daily,omitempty"`
// GPUSDailyUSD is the daily cost estimate in USD for the GPU-S size
GPUSDailyUSD float64 `yaml:"gpu_s_daily,omitempty" json:"gpu_s_daily,omitempty"`
// GPUMDailyUSD is the daily cost estimate in USD for the GPU-M size
GPUMDailyUSD float64 `yaml:"gpu_m_daily,omitempty" json:"gpu_m_daily,omitempty"`
// GPULDailyUSD is the daily cost estimate in USD for the GPU-L size
GPULDailyUSD float64 `yaml:"gpu_l_daily,omitempty" json:"gpu_l_daily,omitempty"`
}
Cost contains cost estimates.
type DefaultClock ¶
type DefaultClock struct{}
DefaultClock implements the Clock interface using system time
func (*DefaultClock) Now ¶
func (c *DefaultClock) Now() time.Time
Now returns the current system time
type Dependency ¶
type Dependency struct {
// Repository is the repository name
Repository string `yaml:"repository" json:"repository"`
// Template is the template name
Template string `yaml:"template" json:"template"`
// Version is the template version
Version string `yaml:"version" json:"version"`
}
Dependency represents a template dependency (new in 0.3.0).
type DependencyResolver ¶
type DependencyResolver struct {
Manager *TemplateManager
}
DependencyResolver handles automatic resolution of template dependencies
func NewDependencyResolver ¶
func NewDependencyResolver(manager *TemplateManager) *DependencyResolver
NewDependencyResolver creates a new dependency resolver
func (*DependencyResolver) FindCompatibleVersions ¶
func (r *DependencyResolver) FindCompatibleVersions(templateName, constraint, operator string) ([]string, error)
FindCompatibleVersions finds compatible versions for a dependency
This function searches the registry for versions of a template that satisfy the version constraint. This is useful for suggesting alternatives when the current version doesn't satisfy the constraint.
Parameters:
- templateName: The name of the template
- constraint: The version constraint
- operator: The operator for the constraint
Returns:
- []string: List of compatible version strings
- error: Any errors
func (*DependencyResolver) ResolveAndFetchDependencies ¶
func (r *DependencyResolver) ResolveAndFetchDependencies(templateName string, fetchMissing bool) (map[string]*ResolvedDependency, []string, error)
ResolveAndFetchDependencies resolves dependencies and fetches missing templates
This function analyzes dependencies, resolves conflicts, and attempts to fetch missing templates from the registry.
Parameters:
- templateName: The name of the template to resolve dependencies for
- fetchMissing: Whether to fetch missing templates from the registry
Returns:
- map[string]*ResolvedDependency: Map of resolved dependencies
- []string: List of fetched templates
- error: Any resolution errors
func (*DependencyResolver) ResolveDependencies ¶
func (r *DependencyResolver) ResolveDependencies(templateName string) (map[string]*ResolvedDependency, []string, error)
ResolveDependencies resolves all dependencies for a template
This function analyzes all dependencies and attempts to find compatible versions to satisfy the requirements.
Parameters:
- templateName: The name of the template to resolve dependencies for
Returns:
- map[string]*ResolvedDependency: Map of resolved dependencies
- []string: Ordered build list
- error: Any resolution errors
func (*DependencyResolver) ResolveDependencyConflicts ¶
func (r *DependencyResolver) ResolveDependencyConflicts(conflicts map[string][]TemplateDependency) (map[string]string, error)
ResolveDependencyConflicts attempts to resolve conflicts between dependencies
This function analyzes conflicts between different version requirements for the same dependency and tries to find a version that satisfies all constraints.
Parameters:
- conflicts: Map of template name to list of conflicting dependencies
Returns:
- map[string]string: Map of template name to resolved version
- error: Any resolution errors
type Documentation ¶
type Documentation struct {
// UsageExamples are examples of using the template
UsageExamples []UsageExample `yaml:"usage_examples,omitempty" json:"usage_examples,omitempty"`
// CommonWorkflows are common workflows for the template
CommonWorkflows []Workflow `yaml:"common_workflows,omitempty" json:"common_workflows,omitempty"`
// Troubleshooting contains troubleshooting information
Troubleshooting []TroubleshootingItem `yaml:"troubleshooting,omitempty" json:"troubleshooting,omitempty"`
}
Documentation contains template documentation (new in 0.3.0).
type Domain ¶
type Domain struct {
// Category is the top-level research category
Category string `yaml:"category" json:"category"`
// Subcategory is the specific research domain
Subcategory string `yaml:"subcategory" json:"subcategory"`
// WorkloadType is the computational profile
WorkloadType string `yaml:"workload_type" json:"workload_type"`
// AnalysisType is the type of analysis
AnalysisType string `yaml:"analysis_type,omitempty" json:"analysis_type,omitempty"`
// DataScale is the expected data scale
DataScale string `yaml:"data_scale,omitempty" json:"data_scale,omitempty"`
// CommonTools is a list of common tools included
CommonTools []string `yaml:"common_tools,omitempty" json:"common_tools,omitempty"`
// RecommendedStorage is the recommended storage in GB
RecommendedStorage int `yaml:"recommended_storage,omitempty" json:"recommended_storage,omitempty"`
// IdleProfile is the default idle detection profile
IdleProfile string `yaml:"idle_profile,omitempty" json:"idle_profile,omitempty"`
}
Domain contains research domain metadata (new in 0.3.0).
type EnhancedBuildRequest ¶
type EnhancedBuildRequest struct {
// Template is the name of the template to build
Template string `json:"template"`
// Region is the AWS region to build in
Region string `json:"region"`
// SubnetID is the subnet ID to use for the builder instance
SubnetID string `json:"subnet_id,omitempty"`
// SecurityGroupID is the security group ID to use for the builder instance
SecurityGroupID string `json:"security_group_id,omitempty"`
// InstanceType is the EC2 instance type to use for the builder instance
InstanceType string `json:"instance_type,omitempty"`
// Architecture is the CPU architecture to build for (x86_64 or arm64)
Architecture string `json:"architecture,omitempty"`
// DryRun indicates whether this is a dry run (no resources created)
DryRun bool `json:"dry_run,omitempty"`
// AMIName is the name to give the built AMI
AMIName string `json:"ami_name,omitempty"`
// CopyRegions are regions to copy the AMI to after building
CopyRegions []string `json:"copy_regions,omitempty"`
// Public indicates whether the AMI should be made public
Public bool `json:"public,omitempty"`
// Tags are tags to apply to the AMI
Tags map[string]string `json:"tags,omitempty"`
}
EnhancedBuildRequest represents an enhanced request to build an AMI.
type EnhancedBuildResult ¶
type EnhancedBuildResult struct {
// RequestID is a unique identifier for the build request
RequestID string `json:"request_id"`
// Template is the name of the template that was built
Template string `json:"template"`
// Region is the AWS region the build was performed in
Region string `json:"region"`
// AMIID is the ID of the built AMI
AMIID string `json:"ami_id"`
// TemplatePath is the path to the template file
TemplatePath string `json:"template_path"`
// Architecture is the CPU architecture of the AMI
Architecture string `json:"architecture"`
// BuildTime is the time it took to build the AMI
BuildTime time.Duration `json:"build_time"`
// StartTime is the time the build started
StartTime time.Time `json:"start_time"`
// EndTime is the time the build completed
EndTime time.Time `json:"end_time"`
// Status is the status of the build
Status string `json:"status"`
// Error is any error that occurred during the build
Error string `json:"error,omitempty"`
// CopiedAMIs are the AMI IDs in other regions
CopiedAMIs map[string]string `json:"copied_amis,omitempty"`
}
EnhancedBuildResult represents the enhanced result of an AMI build.
type EnhancedBuildStep ¶
type EnhancedBuildStep struct {
// Name is the step name
Name string `yaml:"name" json:"name"`
// Description is the step description
Description string `yaml:"description,omitempty" json:"description,omitempty"`
// Script is the shell script to execute
Script string `yaml:"script" json:"script"`
// TimeoutSeconds is the maximum execution time in seconds
TimeoutSeconds int `yaml:"timeout_seconds,omitempty" json:"timeout_seconds,omitempty"`
}
EnhancedBuildStep represents an enhanced step in building an AMI.
type EnhancedTemplate ¶
type EnhancedTemplate struct {
// Name is the template name
Name string `yaml:"name" json:"name"`
// Description is the template description
Description string `yaml:"description" json:"description"`
// Base is the base OS image to use
Base string `yaml:"base" json:"base"`
// Architecture is the CPU architecture to build for (x86_64 or arm64)
Architecture string `yaml:"architecture" json:"architecture"`
// Version is the template version
Version string `yaml:"version" json:"version"`
// Domain contains research domain metadata (new in 0.3.0)
Domain *Domain `yaml:"domain,omitempty" json:"domain,omitempty"`
// Resources contains resource recommendations
Resources *Resources `yaml:"resources,omitempty" json:"resources,omitempty"`
// Cost contains cost estimates
Cost *Cost `yaml:"cost,omitempty" json:"cost,omitempty"`
// BuildSteps are the steps to build the AMI
BuildSteps []BuildStep `yaml:"build_steps" json:"build_steps"`
// ValidationTests are the tests to validate the AMI
ValidationTests []ValidationTest `yaml:"validation,omitempty" json:"validation,omitempty"`
// UserData is the user data script to run at instance launch
UserData string `yaml:"user_data,omitempty" json:"user_data,omitempty"`
// IdleDetection contains idle detection configuration (new in 0.3.0)
IdleDetection *IdleDetection `yaml:"idle_detection,omitempty" json:"idle_detection,omitempty"`
// Repository contains repository information (new in 0.3.0)
Repository *Repository `yaml:"repository,omitempty" json:"repository,omitempty"`
// Dependencies are the template's dependencies (new in 0.3.0)
Dependencies []Dependency `yaml:"dependencies,omitempty" json:"dependencies,omitempty"`
// Documentation contains template documentation (new in 0.3.0)
Documentation *Documentation `yaml:"docs,omitempty" json:"docs,omitempty"`
}
EnhancedTemplate represents an enhanced Prism template with additional fields.
type ErrorType ¶
type ErrorType string
ErrorType represents the type of error that occurred during AMI building.
const ( // ErrorTypeValidation indicates a validation error (template, parameters, etc.) ErrorTypeValidation ErrorType = "validation" // ErrorTypeInstance indicates an error with EC2 instance operations ErrorTypeInstance ErrorType = "instance" // ErrorTypeCommand indicates an error executing commands via SSM ErrorTypeCommand ErrorType = "command" // ErrorTypeImageCreation indicates an error creating or copying AMIs ErrorTypeImageCreation ErrorType = "image_creation" // ErrorTypeSSM indicates an error with the AWS SSM service ErrorTypeSSM ErrorType = "ssm" // ErrorTypeNetwork indicates a network configuration error ErrorTypeNetwork ErrorType = "network" // ErrorTypeConfiguration indicates a configuration error ErrorTypeConfiguration ErrorType = "configuration" // ErrorTypeRegistry indicates an error with the AMI registry ErrorTypeRegistry ErrorType = "registry" // ErrorTypeInternal indicates an unexpected internal error ErrorTypeInternal ErrorType = "internal" // ErrorTypeTemplateImport indicates a template import error ErrorTypeTemplateImport ErrorType = "template_import" // ErrorTypeTemplateExport indicates a template export error ErrorTypeTemplateExport ErrorType = "template_export" // ErrorTypeTemplateManagement indicates a template management error ErrorTypeTemplateManagement ErrorType = "template_management" // ErrorTypeDependency indicates a template dependency error ErrorTypeDependency ErrorType = "dependency" )
type ExactVersionChecker ¶
type ExactVersionChecker struct{}
ExactVersionChecker validates exact version matches (Strategy Pattern)
func (*ExactVersionChecker) Check ¶
func (c *ExactVersionChecker) Check(version *VersionInfo, constraint *VersionInfo) bool
type ExactVersionValidator ¶
type ExactVersionValidator struct{}
ExactVersionValidator validates exact version matches (Strategy Pattern)
func (*ExactVersionValidator) Validate ¶
func (v *ExactVersionValidator) Validate(dep TemplateDependency, depVersion *VersionInfo, reqVersion *VersionInfo) error
type GreaterThanChecker ¶
type GreaterThanChecker struct{}
GreaterThanChecker validates > version constraints (Strategy Pattern)
func (*GreaterThanChecker) Check ¶
func (c *GreaterThanChecker) Check(version *VersionInfo, constraint *VersionInfo) bool
type GreaterThanOrEqualChecker ¶
type GreaterThanOrEqualChecker struct{}
GreaterThanOrEqualChecker validates >= version constraints (Strategy Pattern)
func (*GreaterThanOrEqualChecker) Check ¶
func (c *GreaterThanOrEqualChecker) Check(version *VersionInfo, constraint *VersionInfo) bool
type GreaterThanOrEqualValidator ¶
type GreaterThanOrEqualValidator struct{}
GreaterThanOrEqualValidator validates >= version constraints (Strategy Pattern)
func (*GreaterThanOrEqualValidator) Validate ¶
func (v *GreaterThanOrEqualValidator) Validate(dep TemplateDependency, depVersion *VersionInfo, reqVersion *VersionInfo) error
type GreaterThanValidator ¶
type GreaterThanValidator struct{}
GreaterThanValidator validates > version constraints (Strategy Pattern)
func (*GreaterThanValidator) Validate ¶
func (v *GreaterThanValidator) Validate(dep TemplateDependency, depVersion *VersionInfo, reqVersion *VersionInfo) error
type IdleDetection ¶
type IdleDetection struct {
// Profile is the idle detection profile to use
Profile string `yaml:"profile" json:"profile"`
// CPUThreshold is the CPU usage threshold percentage
CPUThreshold float64 `yaml:"cpu_threshold,omitempty" json:"cpu_threshold,omitempty"`
// MemoryThreshold is the memory usage threshold percentage
MemoryThreshold float64 `yaml:"memory_threshold,omitempty" json:"memory_threshold,omitempty"`
// NetworkThreshold is the network activity threshold in KBps
NetworkThreshold float64 `yaml:"network_threshold,omitempty" json:"network_threshold,omitempty"`
// DiskThreshold is the disk I/O threshold in KBps
DiskThreshold float64 `yaml:"disk_threshold,omitempty" json:"disk_threshold,omitempty"`
// GPUThreshold is the GPU usage threshold percentage
GPUThreshold float64 `yaml:"gpu_threshold,omitempty" json:"gpu_threshold,omitempty"`
// IdleMinutes is the minutes before an action is taken
IdleMinutes int `yaml:"idle_minutes,omitempty" json:"idle_minutes,omitempty"`
// Action is the action to take when idle
Action string `yaml:"action,omitempty" json:"action,omitempty"`
// Notification indicates whether to send a notification
Notification bool `yaml:"notification,omitempty" json:"notification,omitempty"`
}
IdleDetection contains idle detection configuration (new in 0.3.0).
type InstanceAMICopyStep ¶
type InstanceAMICopyStep struct{}
InstanceAMICopyStep copies the AMI to target regions
func (*InstanceAMICopyStep) Execute ¶
func (i *InstanceAMICopyStep) Execute(ctx context.Context, pipeline *InstanceSavePipeline) error
func (*InstanceAMICopyStep) GetName ¶
func (i *InstanceAMICopyStep) GetName() string
type InstanceAMICreationStep ¶
type InstanceAMICreationStep struct{}
InstanceAMICreationStep creates the AMI from stopped instance
func (*InstanceAMICreationStep) Execute ¶
func (i *InstanceAMICreationStep) Execute(ctx context.Context, pipeline *InstanceSavePipeline) error
func (*InstanceAMICreationStep) GetName ¶
func (i *InstanceAMICreationStep) GetName() string
type InstanceDetailsStep ¶
type InstanceDetailsStep struct{}
InstanceDetailsStep gets instance details and sets up the result
func (*InstanceDetailsStep) Execute ¶
func (i *InstanceDetailsStep) Execute(ctx context.Context, pipeline *InstanceSavePipeline) error
func (*InstanceDetailsStep) GetName ¶
func (i *InstanceDetailsStep) GetName() string
type InstanceSavePipeline ¶
type InstanceSavePipeline struct {
// contains filtered or unexported fields
}
InstanceSavePipeline represents the instance save pipeline using Builder Pattern (SOLID)
func NewInstanceSavePipeline ¶
func NewInstanceSavePipeline(builder *Builder, request InstanceSaveRequest) *InstanceSavePipeline
NewInstanceSavePipeline creates a new instance save pipeline
func (*InstanceSavePipeline) Execute ¶
func (p *InstanceSavePipeline) Execute(ctx context.Context) (*BuildResult, error)
Execute runs the complete instance save pipeline
func (*InstanceSavePipeline) LogSaveStep ¶
func (p *InstanceSavePipeline) LogSaveStep(stepName string, success bool, duration time.Duration, output string, err error)
LogSaveStep logs a save step result
type InstanceSaveRequest ¶
type InstanceSaveRequest struct {
InstanceID string // EC2 instance ID to save
InstanceName string // Prism instance name
TemplateName string // Name for the new template
Description string // Template description
CopyToRegions []string // Regions to copy AMI
Tags map[string]string // Custom tags
ProjectID string // Associated project (Phase 4)
Public bool // Allow public sharing
}
InstanceSaveRequest contains parameters for saving a running instance as an AMI
type InstanceSaveStep ¶
type InstanceSaveStep interface {
Execute(ctx context.Context, pipeline *InstanceSavePipeline) error
GetName() string
}
InstanceSaveStep represents a single step in the instance save pipeline
type InstanceStopStep ¶
type InstanceStopStep struct{}
InstanceStopStep stops the instance for consistent AMI creation
func (*InstanceStopStep) Execute ¶
func (i *InstanceStopStep) Execute(ctx context.Context, pipeline *InstanceSavePipeline) error
func (*InstanceStopStep) GetName ¶
func (i *InstanceStopStep) GetName() string
type LessThanChecker ¶
type LessThanChecker struct{}
LessThanChecker validates < version constraints (Strategy Pattern)
func (*LessThanChecker) Check ¶
func (c *LessThanChecker) Check(version *VersionInfo, constraint *VersionInfo) bool
type LessThanOrEqualChecker ¶
type LessThanOrEqualChecker struct{}
LessThanOrEqualChecker validates <= version constraints (Strategy Pattern)
func (*LessThanOrEqualChecker) Check ¶
func (c *LessThanOrEqualChecker) Check(version *VersionInfo, constraint *VersionInfo) bool
type LessThanOrEqualValidator ¶
type LessThanOrEqualValidator struct{}
LessThanOrEqualValidator validates <= version constraints (Strategy Pattern)
func (*LessThanOrEqualValidator) Validate ¶
func (v *LessThanOrEqualValidator) Validate(dep TemplateDependency, depVersion *VersionInfo, reqVersion *VersionInfo) error
type LessThanValidator ¶
type LessThanValidator struct{}
LessThanValidator validates < version constraints (Strategy Pattern)
func (*LessThanValidator) Validate ¶
func (v *LessThanValidator) Validate(dep TemplateDependency, depVersion *VersionInfo, reqVersion *VersionInfo) error
type Parser ¶
Parser handles YAML template parsing and validation
func (*Parser) ListTemplates ¶
ListTemplates returns a list of available templates from default template directories
func (*Parser) LoadEnhancedTemplateFromFile ¶
LoadEnhancedTemplateFromFile loads a template from a file with support for 0.3.0 format.
func (*Parser) ParseEnhancedTemplate ¶
ParseEnhancedTemplate parses a template file with support for 0.3.0 format.
func (*Parser) ParseTemplate ¶
ParseTemplate parses a template from a string
func (*Parser) ParseTemplateFile ¶
ParseTemplateFile parses a template from a file
func (*Parser) ValidateTemplate ¶
ValidateTemplate validates a template against the enhanced schema
func (*Parser) ValidateTemplateFile ¶
ValidateTemplateFile validates a template file against the enhanced schema.
func (*Parser) ValidateWithSchema ¶
func (p *Parser) ValidateWithSchema(template *Template, validator *SchemaValidator) error
ValidateWithSchema enhances the Parser's ValidateTemplate method with schema validation
type PipelineStep ¶
type PipelineStep interface {
Execute(ctx context.Context, pipeline *BuildPipeline) error
GetName() string
}
PipelineStep represents a single step in the build pipeline
type Reference ¶
type Reference struct {
AMIID string
Region string
Architecture string
TemplateName string
Version string
BuildDate time.Time
Tags map[string]string
}
Reference contains details for referencing an AMI
type Registry ¶
type Registry struct {
SSMClient *ssm.Client
// SSM parameter path prefix for AMI registry
ParameterPrefix string
}
Registry handles AMI version tracking and lookup
func NewRegistry ¶
NewRegistry creates a new AMI registry
func (*Registry) DeleteSharedTemplate ¶
DeleteSharedTemplate deletes a template from the registry
This method removes a template from SSM Parameter Store.
Parameters:
- ctx: Context for cancellation and timeouts
- templateName: Name of the template to delete
- version: Optional version to delete ("" for all versions)
Returns:
- error: Any deletion errors
func (*Registry) GetLatestAMIByVersion ¶
func (r *Registry) GetLatestAMIByVersion(ctx context.Context, templateName, region, architecture string) (*Reference, error)
GetLatestAMIByVersion gets the latest AMI for a template based on semantic versioning
func (*Registry) GetSharedTemplate ¶
func (r *Registry) GetSharedTemplate(ctx context.Context, templateName, version string) (*TemplateRegistryEntry, error)
GetSharedTemplate gets a template from the registry
This method retrieves a template from SSM Parameter Store.
Parameters:
- ctx: Context for cancellation and timeouts
- templateName: Name of the template to retrieve
- version: Optional version to retrieve ("" for latest)
Returns:
- *TemplateRegistryEntry: The template registry entry
- error: Any retrieval errors
func (*Registry) GetTemplateLatestVersion ¶
func (r *Registry) GetTemplateLatestVersion(ctx context.Context, templateName string) (string, error)
GetTemplateLatestVersion gets the latest version of a template from the registry
func (*Registry) ListSharedTemplateVersions ¶
func (r *Registry) ListSharedTemplateVersions(ctx context.Context, templateName string) ([]string, error)
ListSharedTemplateVersions lists all versions of a template in the registry
This method queries SSM Parameter Store for all versions of a specific template.
Parameters:
- ctx: Context for cancellation and timeouts
- templateName: Name of the template to list versions for
Returns:
- []string: List of version strings (e.g., "1.0.0", "1.1.0")
- error: Any listing errors
func (*Registry) ListSharedTemplates ¶
func (r *Registry) ListSharedTemplates(ctx context.Context) (map[string]*TemplateRegistryEntry, error)
ListSharedTemplates lists templates available in the registry
This method queries SSM Parameter Store for templates shared in the registry.
Parameters:
- ctx: Context for cancellation and timeouts
Returns:
- map[string]*TemplateRegistryEntry: Map of template names to registry entries
- error: Any listing errors
func (*Registry) ListTemplateAMIs ¶
ListTemplateAMIs returns all AMIs for a specific template
func (*Registry) ListTemplates ¶
ListTemplates returns all templates that have AMIs in the registry
func (*Registry) ListVersions ¶
func (r *Registry) ListVersions(ctx context.Context, templateName, region, architecture string) ([]string, error)
ListVersions returns all versions available for a specific template, region, and architecture
func (*Registry) LookupAMI ¶
func (r *Registry) LookupAMI(ctx context.Context, templateName, region, architecture string) (*Reference, error)
LookupAMI finds the latest AMI for a template, region, and architecture
func (*Registry) LookupVersionedAMI ¶
func (r *Registry) LookupVersionedAMI(ctx context.Context, templateName, region, architecture, version string) (*Reference, error)
LookupVersionedAMI finds a specific version of an AMI for a template, region, and architecture
func (*Registry) PublishAMI ¶
func (r *Registry) PublishAMI(ctx context.Context, buildResult *BuildResult) error
PublishAMI registers a new AMI in the registry
func (*Registry) PublishTemplate ¶
func (r *Registry) PublishTemplate(ctx context.Context, templateName, templateData, format string, metadata map[string]string) error
PublishTemplate publishes a template to the registry
This method serializes a template and stores it in SSM Parameter Store with associated metadata for discovery and sharing.
Parameters:
- ctx: Context for cancellation and timeouts
- templateName: Name of the template to share
- templateData: Serialized template data (YAML or JSON)
- format: Format of the template data (yaml, json)
- metadata: Additional metadata for the template
Returns:
- error: Any sharing errors
func (*Registry) PublishVersionedAMI ¶
func (r *Registry) PublishVersionedAMI(ctx context.Context, buildResult *BuildResult) error
PublishVersionedAMI registers a versioned AMI in the registry
type RegistryPublishStep ¶
type RegistryPublishStep struct{}
RegistryPublishStep publishes the AMI to the registry
func (*RegistryPublishStep) Execute ¶
func (r *RegistryPublishStep) Execute(ctx context.Context, pipeline *InstanceSavePipeline) error
func (*RegistryPublishStep) GetName ¶
func (r *RegistryPublishStep) GetName() string
type Repository ¶
type Repository struct {
// Name is the repository name
Name string `yaml:"name" json:"name"`
// URL is the repository URL
URL string `yaml:"url" json:"url"`
// Maintainer is the repository maintainer
Maintainer string `yaml:"maintainer,omitempty" json:"maintainer,omitempty"`
// License is the repository license
License string `yaml:"license,omitempty" json:"license,omitempty"`
}
Repository contains repository information (new in 0.3.0).
type ResolvedDependency ¶
type ResolvedDependency struct {
Name string
OriginalName string
Version string
IsOptional bool
Status string // "satisfied", "missing", "version-mismatch"
}
ResolvedDependency contains information about a resolved dependency
type Resources ¶
type Resources struct {
// Sizes maps T-shirt sizes to instance types
Sizes map[string]Size `yaml:"sizes" json:"sizes"`
// DefaultSize is the default T-shirt size
DefaultSize string `yaml:"default_size" json:"default_size"`
// MemoryRequired is the minimum memory required in GB
MemoryRequired int `yaml:"memory_required,omitempty" json:"memory_required,omitempty"`
// CPURequired is the minimum CPU cores required
CPURequired int `yaml:"cpu_required,omitempty" json:"cpu_required,omitempty"`
// GPURecommended indicates whether a GPU is recommended
GPURecommended bool `yaml:"gpu_recommended,omitempty" json:"gpu_recommended,omitempty"`
}
Resources contains resource recommendations.
type RestrictiveVersions ¶
RestrictiveVersions holds the most restrictive versions for each operator type
type SchemaValidator ¶
type SchemaValidator struct {
// contains filtered or unexported fields
}
SchemaValidator validates templates against the JSON schema
func NewSchemaValidator ¶
func NewSchemaValidator() (*SchemaValidator, error)
NewSchemaValidator creates a new schema validator
func (*SchemaValidator) GetSchema ¶
func (v *SchemaValidator) GetSchema() ([]byte, error)
GetSchema returns the JSON schema document
func (*SchemaValidator) Validate ¶
func (v *SchemaValidator) Validate(template *Template) error
Validate validates a template against the JSON schema
This method converts the template to JSON and validates it against the schema.
Parameters:
- template: The template to validate
Returns:
- error: Validation error or nil if valid
type SharedTemplateEntry ¶
type SharedTemplateEntry struct {
}
SharedTemplateEntry represents a template entry in the shared registry
type Size ¶
type Size struct {
// InstanceType is the AWS instance type
InstanceType string `yaml:"instance_type" json:"instance_type"`
// Architecture is the CPU architecture
Architecture string `yaml:"architecture" json:"architecture"`
}
Size represents an instance size.
type Template ¶
type Template struct {
Name string `yaml:"name"`
Base string `yaml:"base"`
Description string `yaml:"description"`
BuildSteps []BuildStep `yaml:"build_steps"`
Validation []Validation `yaml:"validation"`
// Optional fields
Tags map[string]string `yaml:"tags,omitempty"`
MinDiskSize int `yaml:"min_disk_size,omitempty"` // GB
Architecture string `yaml:"architecture,omitempty"` // Default is both
// Dependency management
Dependencies []TemplateDependency `yaml:"dependencies,omitempty"` // Template dependencies
}
Template defines the YAML structure for an AMI template
type TemplateBuilder ¶
type TemplateBuilder struct {
// contains filtered or unexported fields
}
TemplateBuilder is a builder for creating and modifying templates
func (*TemplateBuilder) AddBuildStep ¶
func (b *TemplateBuilder) AddBuildStep(name, script string) *TemplateBuilder
AddBuildStep adds a build step to the template
func (*TemplateBuilder) AddBuildStepWithTimeout ¶
func (b *TemplateBuilder) AddBuildStepWithTimeout(name, script string, timeoutSeconds int) *TemplateBuilder
AddBuildStepWithTimeout adds a build step with a custom timeout to the template
func (*TemplateBuilder) AddValidation ¶
func (b *TemplateBuilder) AddValidation(name, command string, success bool, contains, equals string) *TemplateBuilder
AddValidation adds a validation check to the template
func (*TemplateBuilder) Build ¶
func (b *TemplateBuilder) Build() (*Template, error)
Build finalizes and validates the template
This method validates and stores the template in the manager.
Returns:
- *Template: The built template
- error: Any validation errors
func (*TemplateBuilder) WithArchitecture ¶
func (b *TemplateBuilder) WithArchitecture(arch string) *TemplateBuilder
WithArchitecture sets the architecture for the template
func (*TemplateBuilder) WithBase ¶
func (b *TemplateBuilder) WithBase(base string) *TemplateBuilder
WithBase sets the base image for the template
func (*TemplateBuilder) WithMinDiskSize ¶
func (b *TemplateBuilder) WithMinDiskSize(sizeGB int) *TemplateBuilder
WithMinDiskSize sets the minimum disk size for the template
func (*TemplateBuilder) WithTag ¶
func (b *TemplateBuilder) WithTag(key, value string) *TemplateBuilder
WithTag adds a tag to the template
type TemplateDefinitionStep ¶
type TemplateDefinitionStep struct{}
TemplateDefinitionStep creates the template definition file
func (*TemplateDefinitionStep) Execute ¶
func (t *TemplateDefinitionStep) Execute(ctx context.Context, pipeline *InstanceSavePipeline) error
func (*TemplateDefinitionStep) GetName ¶
func (t *TemplateDefinitionStep) GetName() string
type TemplateDependency ¶
type TemplateDependency struct {
Name string `json:"name" yaml:"name"`
Version string `json:"version,omitempty" yaml:"version,omitempty"`
VersionOperator string `json:"version_operator,omitempty" yaml:"version_operator,omitempty"`
Optional bool `json:"optional,omitempty" yaml:"optional,omitempty"`
}
TemplateDependency represents a dependency on another template
type TemplateExportOptions ¶
TemplateExportOptions configures template export behavior
type TemplateImportOptions ¶
ImportTemplateOptions contains options for template importing
type TemplateManager ¶
type TemplateManager struct {
Parser *Parser
Registry *Registry
TemplateDirectory string
Templates map[string]*Template
TemplateMetadata map[string]TemplateMetadata
HTTPClient *http.Client
SchemaValidator *SchemaValidator
PublicDirectory string // Directory for publicly shared templates
// contains filtered or unexported fields
}
TemplateManager handles template management operations
func NewTemplateManager ¶
func NewTemplateManager(parser *Parser, registry *Registry, templateDir string) *TemplateManager
NewTemplateManager creates a new template manager
The template manager serves as a central coordinator for all template operations, providing functionality to import, export, create, modify, and share templates.
Parameters:
- parser: YAML template parser instance
- registry: AMI registry for template sharing
- templateDir: Directory to store template files
Returns:
- *TemplateManager: Initialized template manager
Example:
parser := ami.NewParser(baseAMIs) registry := ami.NewRegistry(ssmClient, "/cloudworkstation/ami") manager := ami.NewTemplateManager(parser, registry, "./templates")
func (*TemplateManager) AddDependency ¶
func (m *TemplateManager) AddDependency(templateName string, dependency TemplateDependency) error
AddDependency adds a dependency to a template
This function adds a new dependency to a template.
Parameters:
- templateName: The name of the template to modify
- dependency: The dependency to add
Returns:
- error: Any errors
func (*TemplateManager) CreateTemplate ¶
func (m *TemplateManager) CreateTemplate(name, description string) *TemplateBuilder
CreateTemplate creates a new template with the builder pattern
This method starts the template creation process using a builder pattern, allowing for fluent definition of the template properties.
Parameters:
- name: Template name
- description: Template description
Returns:
- *TemplateBuilder: Builder for the template
Example:
template, err := manager.CreateTemplate("custom-python", "Custom Python environment").
WithBase("ubuntu-22.04").
AddBuildStep("install-python", "apt-get update && apt-get install -y python3").
AddValidation("check-python", "python3 --version", true, "", "").
Build()
func (*TemplateManager) CreateTemplateVersion ¶
func (m *TemplateManager) CreateTemplateVersion(templateName, component string) (*TemplateBuilder, error)
CreateTemplateVersion creates a new version of a template with changes
This method creates a new version of a template with changes applied via the builder pattern.
Parameters:
- templateName: Name of the template to version
- component: Component to increment ("major", "minor", or "patch")
Returns:
- *TemplateBuilder: Builder for the new version
- error: Any errors
func (*TemplateManager) DeleteTemplate ¶
func (m *TemplateManager) DeleteTemplate(name string, deleteFile bool) error
DeleteTemplate deletes a template from cache and optionally from disk
This method removes a template from the manager's cache and optionally deletes the template file from disk.
Parameters:
- name: Template name
- deleteFile: Whether to delete the template file from disk
Returns:
- error: Any deletion errors
func (*TemplateManager) ExportToFile ¶
func (m *TemplateManager) ExportToFile(templateName, filePath string, options *TemplateExportOptions) error
ExportToFile exports a template to a file
This method exports a template to a file in the specified format.
Parameters:
- templateName: Name of the template to export
- filePath: Path to export the template to
- options: Export options (can be nil for defaults)
Returns:
- error: Any export errors
Example:
err := manager.ExportToFile("r-research", "./exported/r-research.yaml", nil)
func (*TemplateManager) ExportToJSON ¶
func (m *TemplateManager) ExportToJSON(templateName string, prettyPrint bool) ([]byte, error)
ExportToJSON exports a template to JSON format
This method serializes a template to JSON format and returns the result.
Parameters:
- templateName: Name of the template to export
- prettyPrint: Whether to format the JSON with indentation
Returns:
- []byte: The JSON data
- error: Any export errors
Example:
data, err := manager.ExportToJSON("python-ml", true)
if err != nil {
log.Fatalf("Failed to export template: %v", err)
}
func (*TemplateManager) ExportToYAML ¶
func (m *TemplateManager) ExportToYAML(templateName string) ([]byte, error)
ExportToYAML exports a template to YAML format
This method serializes a template to YAML format and returns the result.
Parameters:
- templateName: Name of the template to export
Returns:
- []byte: The YAML data
- error: Any export errors
Example:
data, err := manager.ExportToYAML("bioinformatics")
if err != nil {
log.Fatalf("Failed to export template: %v", err)
}
func (*TemplateManager) GetDependencyGraph ¶
func (m *TemplateManager) GetDependencyGraph(templateName string) ([]string, error)
GetDependencyGraph builds a dependency graph for a template
This function returns a sorted list of templates in the order they should be built.
Parameters:
- templateName: The name of the template to build graph for
Returns:
- []string: Sorted list of template names in build order
- error: Any errors
func (*TemplateManager) GetTemplate ¶
func (m *TemplateManager) GetTemplate(name string) (*Template, error)
GetTemplate retrieves a template by name
This method gets a template from the cache or loads it from disk if not cached.
Parameters:
- name: Template name
Returns:
- *Template: The template
- error: Any retrieval errors
func (*TemplateManager) GetTemplateVersion ¶
func (m *TemplateManager) GetTemplateVersion(templateName string) (*VersionInfo, error)
GetTemplateVersion gets the version of a template
This method extracts the version from a template's metadata.
Parameters:
- templateName: Name of the template
Returns:
- *VersionInfo: The template version
- error: Any errors
func (*TemplateManager) ImportFromFile ¶
func (m *TemplateManager) ImportFromFile(filePath string, options *TemplateManagerImportOptions) (*Template, error)
ImportFromFile imports a template from a local file
This method imports a template from a local YAML file, validates it, and adds it to the template cache with metadata.
Parameters:
- filePath: Path to the template file
- options: Import options (can be nil for defaults)
Returns:
- *Template: The imported template
- error: Any import errors
Example:
template, err := manager.ImportFromFile("./templates/r-research.yaml", nil)
if err != nil {
log.Fatalf("Failed to import template: %v", err)
}
func (*TemplateManager) ImportFromGitHub ¶
func (m *TemplateManager) ImportFromGitHub(repo, path, ref string, options *TemplateManagerImportOptions) (*Template, error)
ImportFromGitHub imports a template from a GitHub repository
This method downloads a template from a GitHub repository, validates it, and adds it to the template cache. It supports both public and private repositories.
Parameters:
- repo: GitHub repository (username/repo)
- path: Path to template file in the repository
- ref: Git reference (branch, tag, commit)
- options: Import options (can be nil for defaults)
Returns:
- *Template: The imported template
- error: Any import errors
Example:
template, err := manager.ImportFromGitHub(
"cloudworkstation/templates",
"r-research.yaml",
"main",
nil,
)
func (*TemplateManager) ImportFromTemplate ¶
func (m *TemplateManager) ImportFromTemplate(template *Template, options *TemplateImportOptions) (*Template, error)
ImportFromTemplate imports a template from an existing Template struct
This method adds an existing template to the manager's cache with optional validation.
Parameters:
- template: The template to import
- options: Import options (can be nil for defaults)
Returns:
- *Template: The imported template
- error: Any import errors
Example:
template, err := manager.ImportFromTemplate(existingTemplate, nil)
func (*TemplateManager) ImportFromURL ¶
func (m *TemplateManager) ImportFromURL(url string, options *TemplateManagerImportOptions) (*Template, error)
ImportFromURL imports a template from a URL
This method downloads a template from a URL, validates it, and adds it to the template cache.
Parameters:
- url: URL to the template file
- options: Import options (can be nil for defaults)
Returns:
- *Template: The imported template
- error: Any import errors
Example:
template, err := manager.ImportFromURL("https://example.com/templates/python-ml.yaml", nil)
func (*TemplateManager) IncrementTemplateVersion ¶
func (m *TemplateManager) IncrementTemplateVersion(templateName, component string) (*VersionInfo, error)
IncrementTemplateVersion increments the version of a template
This method increments the major, minor, or patch version of a template.
Parameters:
- templateName: Name of the template
- component: Which component to increment ("major", "minor", or "patch")
Returns:
- *VersionInfo: The new version
- error: Any errors
func (*TemplateManager) ListTemplates ¶
func (m *TemplateManager) ListTemplates(includeDirectory bool) (map[string]*Template, error)
ListTemplates lists all available templates
This method returns all templates in the cache and optionally scans the template directory for additional templates.
Parameters:
- includeDirectory: Whether to scan the template directory
Returns:
- map[string]*Template: Map of template name to template
- error: Any listing errors
func (*TemplateManager) ModifyTemplate ¶
func (m *TemplateManager) ModifyTemplate(name string) (*TemplateBuilder, error)
ModifyTemplate creates a builder for modifying an existing template
This method starts the template modification process using a builder pattern.
Parameters:
- name: Name of the template to modify
Returns:
- *TemplateBuilder: Builder for the template
- error: Any template retrieval errors
Example:
builder, err := manager.ModifyTemplate("r-research")
if err != nil {
log.Fatalf("Failed to modify template: %v", err)
}
modified := builder.
AddBuildStep("install-tidyverse", "R -e 'install.packages(\"tidyverse\")'").
Build()
func (*TemplateManager) RemoveDependency ¶
func (m *TemplateManager) RemoveDependency(templateName string, dependencyName string) (bool, error)
RemoveDependency removes a dependency from a template
Parameters:
- templateName: The name of the template to modify
- dependencyName: The name of the dependency to remove
Returns:
- bool: True if dependency was found and removed
- error: Any errors
func (*TemplateManager) SetTemplateVersion ¶
func (m *TemplateManager) SetTemplateVersion(templateName string, version *VersionInfo) error
SetTemplateVersion sets the version of a template
This method updates the version in a template's metadata.
Parameters:
- templateName: Name of the template
- version: The version to set
Returns:
- error: Any errors
func (*TemplateManager) ShareTemplate ¶
func (m *TemplateManager) ShareTemplate(templateName string, ctx context.Context) error
ShareTemplate shares a template via the registry
This method publishes a template to the AMI registry, making it available for other Prism instances.
Parameters:
- templateName: Name of the template to share
- ctx: Context for cancellation and timeouts
Returns:
- error: Any sharing errors
Example:
err := manager.ShareTemplate("custom-ml", context.Background())
if err != nil {
log.Fatalf("Failed to share template: %v", err)
}
func (*TemplateManager) ValidateTemplate ¶
func (m *TemplateManager) ValidateTemplate(templateName string) error
ValidateTemplate validates a template against schema and requirements
This method performs comprehensive validation of a template, including schema validation, base AMI validation, and additional custom checks.
Parameters:
- templateName: Name of the template to validate
Returns:
- error: Validation error or nil if valid
Example:
err := manager.ValidateTemplate("r-research")
if err != nil {
log.Fatalf("Template validation failed: %v", err)
}
func (*TemplateManager) ValidateTemplateDependencies ¶
func (m *TemplateManager) ValidateTemplateDependencies(templateName string, dependencies []TemplateDependency) error
ValidateTemplateDependencies validates all dependencies for a template
This function ensures all dependencies exist and version constraints are satisfied.
Parameters:
- templateName: The name of the template being validated
- dependencies: List of dependencies to validate
Returns:
- error: Any validation errors
func (*TemplateManager) VersionTemplate ¶
func (m *TemplateManager) VersionTemplate(templateName string, newVersion *VersionInfo, component string) (*Template, error)
VersionTemplate creates a new versioned copy of a template
This method creates a new template with a new version number.
Parameters:
- templateName: Name of the template to version
- newVersion: New version info (or nil to auto-increment)
- component: Component to increment if newVersion is nil ("major", "minor", or "patch")
Returns:
- *Template: The new versioned template
- error: Any errors
type TemplateManagerImportOptions ¶
TemplateManagerImportOptions configures template import behavior for the template manager
type TemplateMetadata ¶
type TemplateMetadata struct {
SourcePath string `json:"source_path,omitempty"`
SourceURL string `json:"source_url,omitempty"`
LastModified time.Time `json:"last_modified"`
ValidationStatus string `json:"validation_status"`
IsBuiltIn bool `json:"is_built_in"`
Description string `json:"description,omitempty"`
Author string `json:"author,omitempty"`
Version string `json:"version,omitempty"`
}
TemplateMetadata contains additional information about a template
type TemplateRegistryEntry ¶
type TemplateRegistryEntry struct {
Name string `json:"name"`
Description string `json:"description"`
Version string `json:"version"`
PublishedAt time.Time `json:"published_at"`
PublishedBy string `json:"published_by"`
Architecture string `json:"architecture,omitempty"`
Tags map[string]string `json:"tags,omitempty"`
Format string `json:"format"` // yaml, json, etc.
TemplateData string `json:"template_data"`
}
TemplateRegistryEntry represents a shared template in the registry
type TroubleshootingItem ¶
type TroubleshootingItem struct {
// Problem is the problem description
Problem string `yaml:"problem" json:"problem"`
// Solution is the solution to the problem
Solution string `yaml:"solution" json:"solution"`
}
TroubleshootingItem represents a troubleshooting item for a template.
type UsageExample ¶
type UsageExample struct {
// Description is the example description
Description string `yaml:"description" json:"description"`
// Command is the example command
Command string `yaml:"command" json:"command"`
}
UsageExample represents a usage example for a template.
type Validation ¶
type Validation struct {
Name string `yaml:"name"`
Command string `yaml:"command"`
// Validation options (at least one required)
Success bool `yaml:"success,omitempty"` // Command must exit with code 0
Contains string `yaml:"contains,omitempty"` // Output must contain string
Equals string `yaml:"equals,omitempty"` // Output must exactly match
}
Validation represents a test to validate the AMI build
type ValidationExecutionStep ¶
type ValidationExecutionStep struct{}
ValidationExecutionStep runs validation tests
func (*ValidationExecutionStep) Execute ¶
func (v *ValidationExecutionStep) Execute(ctx context.Context, pipeline *BuildPipeline) error
func (*ValidationExecutionStep) GetName ¶
func (v *ValidationExecutionStep) GetName() string
type ValidationResult ¶
type ValidationResult struct {
Successful bool
FailedChecks []string
SuccessfulTests int
TotalTests int
Details map[string]string
}
ValidationResult contains the outcome of AMI validation
type ValidationStep ¶
type ValidationStep struct{}
ValidationStep validates the build request
func (*ValidationStep) Execute ¶
func (v *ValidationStep) Execute(ctx context.Context, pipeline *BuildPipeline) error
func (*ValidationStep) GetName ¶
func (v *ValidationStep) GetName() string
type ValidationTest ¶
type ValidationTest struct {
// Name is the test name
Name string `yaml:"name" json:"name"`
// Command is the command to execute
Command string `yaml:"command,omitempty" json:"command,omitempty"`
// Script is the shell script to execute
Script string `yaml:"script,omitempty" json:"script,omitempty"`
// ExpectedOutput is the expected output of the command (substring match)
ExpectedOutput string `yaml:"expected_output,omitempty" json:"expected_output,omitempty"`
// ExpectedExitCode is the expected exit code of the command
ExpectedExitCode int `yaml:"expected_exit_code,omitempty" json:"expected_exit_code,omitempty"`
}
ValidationTest represents a validation test for an AMI.
type Validator ¶
type Validator struct {
SSMClient *ssm.Client
Options ValidatorOptions
}
Validator handles AMI validation
func NewValidator ¶
func NewValidator(ssmClient *ssm.Client, options ValidatorOptions) *Validator
NewValidator creates a new AMI validator
func (*Validator) FormatValidationResult ¶
func (v *Validator) FormatValidationResult(result *ValidationResult) string
FormatValidationResult formats a validation result for output
func (*Validator) ValidateAMI ¶
func (v *Validator) ValidateAMI(instanceID string, template *Template) (*ValidationResult, error)
ValidateAMI validates an AMI build
type ValidatorOptions ¶
ValidatorOptions configures the validation process
type VersionChecker ¶
type VersionChecker interface {
Check(version *VersionInfo, constraint *VersionInfo) bool
}
VersionChecker defines the interface for version constraint checking using Strategy Pattern (SOLID: Open/Closed)
type VersionInfo ¶
VersionInfo represents the semantic version of a template
func NewVersionInfo ¶
func NewVersionInfo(version string) (*VersionInfo, error)
NewVersionInfo creates a new version info from a version string
The version string must be in the format "x.y.z" where x, y, and z are integers.
Parameters:
- version: The version string in the format "x.y.z"
Returns:
- *VersionInfo: The parsed version info
- error: Any parsing errors
func (*VersionInfo) Equals ¶
func (v *VersionInfo) Equals(other *VersionInfo) bool
Equals checks if two versions are equal
func (*VersionInfo) IncrementMajor ¶
func (v *VersionInfo) IncrementMajor()
IncrementMajor increments the major version number
func (*VersionInfo) IncrementMinor ¶
func (v *VersionInfo) IncrementMinor()
IncrementMinor increments the minor version number
func (*VersionInfo) IncrementPatch ¶
func (v *VersionInfo) IncrementPatch()
IncrementPatch increments the patch version number
func (*VersionInfo) IsGreaterThan ¶
func (v *VersionInfo) IsGreaterThan(other *VersionInfo) bool
IsGreaterThan returns true if this version is greater than the other version
func (*VersionInfo) String ¶
func (v *VersionInfo) String() string
String returns the string representation of the version
type VersionValidator ¶
type VersionValidator interface {
Validate(dep TemplateDependency, depVersion *VersionInfo, reqVersion *VersionInfo) error
}
VersionValidator defines the interface for version constraint validation using Strategy Pattern (SOLID: Open/Closed)
type Workflow ¶
type Workflow struct {
// Name is the workflow name
Name string `yaml:"name" json:"name"`
// Description is the workflow description
Description string `yaml:"description" json:"description"`
// Steps are the workflow steps
Steps []string `yaml:"steps" json:"steps"`
}
Workflow represents a common workflow for a template.