language

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package language provides the base implementation and error types for language-specific builders in engine-ci.

This package eliminates code duplication across language packages by providing:

  • BaseLanguageBuilder: Common functionality shared by all language builders
  • Standardized error types: ValidationError, BuildError, ContainerError, CacheError
  • Interface compliance: Implements LanguageBuilder and BuildStep interfaces
  • Configuration integration: Centralized configuration management

The BaseLanguageBuilder replaces duplicated code patterns that were scattered across individual language packages (golang, python, maven, etc.) with a shared implementation that handles:

  • Container management and lifecycle
  • Configuration access and validation
  • Logging and error handling
  • Cache management
  • Image tagging and metadata

Language packages should embed BaseLanguageBuilder and implement language-specific build logic while leveraging the shared infrastructure.

Example usage in a language package:

type PythonContainer struct {
    *language.BaseLanguageBuilder
    // Language-specific fields
}

func New(build container.Build) *PythonContainer {
    cfg := &config.LanguageConfig{
        BaseImage: "python:3.11-slim-bookworm",
        CacheLocation: "/root/.cache/pip",
        // ... other config
    }

    baseBuilder := language.NewBaseLanguageBuilder("python", cfg, container.New(build), nil)
    return &PythonContainer{BaseLanguageBuilder: baseBuilder}
}

This file provides standardized error types for language builders.

These error types replace the antipattern of os.Exit(1) calls scattered throughout the codebase. They provide:

  • Structured error information with context
  • Error wrapping for better debugging
  • Consistent error messages across all language packages
  • Support for error recovery and handling strategies

The error types follow Go's error handling best practices and integrate with the standard errors package for error unwrapping and type checking.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseLanguageBuilder

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

BaseLanguageBuilder provides common functionality for all language builders. This eliminates code duplication across language packages by implementing shared behavior that all language builders need.

func NewBaseLanguageBuilder

func NewBaseLanguageBuilder(
	name string,
	config *config.LanguageConfig,
	container *container.Container,
	cache build.CacheManager,
) *BaseLanguageBuilder

NewBaseLanguageBuilder creates a new base language builder

func (*BaseLanguageBuilder) BaseImage

func (b *BaseLanguageBuilder) BaseImage() string

BaseImage returns the base container image for this language

func (*BaseLanguageBuilder) Build

func (b *BaseLanguageBuilder) Build() (string, error)

Build executes the build process and returns the resulting image ID This method must be implemented by specific language builders

func (*BaseLanguageBuilder) BuildImage

func (b *BaseLanguageBuilder) BuildImage() (string, error)

BuildImage builds the intermediate language-specific image This method must be implemented by specific language builders

func (*BaseLanguageBuilder) BuildScript

func (b *BaseLanguageBuilder) BuildScript() string

BuildScript generates the build script for this language This method must be implemented by specific language builders

func (*BaseLanguageBuilder) BuildTimeout

func (b *BaseLanguageBuilder) BuildTimeout() time.Duration

BuildTimeout returns the maximum build time allowed for this language

func (*BaseLanguageBuilder) CacheLocation

func (b *BaseLanguageBuilder) CacheLocation() string

CacheLocation returns the cache directory path inside the container

func (*BaseLanguageBuilder) ComputeImageTag

func (b *BaseLanguageBuilder) ComputeImageTag(data []byte) string

ComputeImageTag computes a deterministic tag from dockerfile content This replaces the duplicated ComputeChecksum functions across packages

func (*BaseLanguageBuilder) CreateBuildStepAdapter

func (b *BaseLanguageBuilder) CreateBuildStepAdapter() build.BuildStep

CreateBuildStepAdapter creates a BuildStep adapter for this language builder This allows language builders to be used in build pipelines

func (*BaseLanguageBuilder) DefaultEnvironment

func (b *BaseLanguageBuilder) DefaultEnvironment() []string

DefaultEnvironment returns the default environment variables for this language

func (*BaseLanguageBuilder) GetCacheManager

func (b *BaseLanguageBuilder) GetCacheManager() build.CacheManager

GetCacheManager returns the cache manager instance

func (*BaseLanguageBuilder) GetConfig

func (b *BaseLanguageBuilder) GetConfig() *config.LanguageConfig

GetConfig returns the language configuration

func (*BaseLanguageBuilder) GetContainer

func (b *BaseLanguageBuilder) GetContainer() *container.Container

GetContainer returns the underlying container instance

func (*BaseLanguageBuilder) GetLogger

func (b *BaseLanguageBuilder) GetLogger() *slog.Logger

GetLogger returns the logger instance

func (*BaseLanguageBuilder) Images

func (b *BaseLanguageBuilder) Images() []string

Images returns all images required by this builder This method must be implemented by specific language builders

func (*BaseLanguageBuilder) IsAsync

func (b *BaseLanguageBuilder) IsAsync() bool

IsAsync returns whether this builder supports async execution Most language builders are synchronous by default

func (*BaseLanguageBuilder) Name

func (b *BaseLanguageBuilder) Name() string

Name returns the name of the language builder

func (*BaseLanguageBuilder) PostBuild

func (b *BaseLanguageBuilder) PostBuild() error

PostBuild executes common post-build operations

func (*BaseLanguageBuilder) PreBuild

func (b *BaseLanguageBuilder) PreBuild() error

PreBuild executes common pre-build operations

func (*BaseLanguageBuilder) Pull

func (b *BaseLanguageBuilder) Pull() error

Pull pulls the required base images for this language

func (*BaseLanguageBuilder) SetValidator

func (b *BaseLanguageBuilder) SetValidator(validator build.Validator)

SetValidator sets the validator for this builder

func (*BaseLanguageBuilder) Validate

func (b *BaseLanguageBuilder) Validate() error

Validate validates the builder configuration and dependencies

func (*BaseLanguageBuilder) ValidateWithValidator

func (b *BaseLanguageBuilder) ValidateWithValidator(ctx context.Context) (*build.ValidationResult, error)

ValidateWithValidator uses the configured validator if available

type BuildError

type BuildError struct {
	Cause     error
	Context   map[string]interface{}
	Operation string
	Language  string
}

BuildError represents a build-related error

func NewBuildError

func NewBuildError(operation, language string, cause error) *BuildError

NewBuildError creates a new build error

func (*BuildError) Error

func (e *BuildError) Error() string

Error implements the error interface

func (*BuildError) Unwrap

func (e *BuildError) Unwrap() error

Unwrap returns the underlying error for error unwrapping

func (*BuildError) WithContext

func (e *BuildError) WithContext(key string, value interface{}) *BuildError

WithContext adds context information to the build error

type CacheError

type CacheError struct {
	Cause     error
	Operation string
	Language  string
	CachePath string
}

CacheError represents a cache-related error

func NewCacheError

func NewCacheError(operation, language string, cause error) *CacheError

NewCacheError creates a new cache error

func (*CacheError) Error

func (e *CacheError) Error() string

Error implements the error interface

func (*CacheError) Unwrap

func (e *CacheError) Unwrap() error

Unwrap returns the underlying error for error unwrapping

func (*CacheError) WithPath

func (e *CacheError) WithPath(cachePath string) *CacheError

WithPath adds cache path to the error

type ContainerError

type ContainerError struct {
	Cause       error
	Operation   string
	ContainerID string
	ImageName   string
}

ContainerError represents a container-related error

func NewContainerError

func NewContainerError(operation string, cause error) *ContainerError

NewContainerError creates a new container error

func (*ContainerError) Error

func (e *ContainerError) Error() string

Error implements the error interface

func (*ContainerError) Unwrap

func (e *ContainerError) Unwrap() error

Unwrap returns the underlying error for error unwrapping

func (*ContainerError) WithContainer

func (e *ContainerError) WithContainer(containerID string) *ContainerError

WithContainer adds container ID to the error

func (*ContainerError) WithImage

func (e *ContainerError) WithImage(imageName string) *ContainerError

WithImage adds image name to the error

type LanguageBuilderStep

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

LanguageBuilderStep adapts a LanguageBuilder to the BuildStep interface

func (*LanguageBuilderStep) Dependencies

func (s *LanguageBuilderStep) Dependencies() []string

Dependencies returns the dependencies for this build step

func (*LanguageBuilderStep) Execute

func (s *LanguageBuilderStep) Execute(ctx context.Context) error

Execute executes the language builder as a build step

func (*LanguageBuilderStep) IsAsync

func (s *LanguageBuilderStep) IsAsync() bool

IsAsync returns whether this step can run asynchronously

func (*LanguageBuilderStep) Name

func (s *LanguageBuilderStep) Name() string

Name returns the name of this build step

func (*LanguageBuilderStep) Timeout

func (s *LanguageBuilderStep) Timeout() time.Duration

Timeout returns the timeout for this build step

func (*LanguageBuilderStep) Validate

func (s *LanguageBuilderStep) Validate() error

Validate validates this build step

type ValidationError

type ValidationError struct {
	Field   string      // The field that failed validation
	Value   interface{} // The value that failed validation
	Message string      // Human-readable error message
}

ValidationError represents a validation error in language builders

func NewValidationError

func NewValidationError(field string, value interface{}, message string) *ValidationError

NewValidationError creates a new validation error

func (*ValidationError) Error

func (e *ValidationError) Error() string

Error implements the error interface

Jump to

Keyboard shortcuts

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