container

package
v0.20.2 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2025 License: Apache-2.0 Imports: 32 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// DefaultWorkerPoolSize is the default number of workers in the pool
	DefaultWorkerPoolSize = 5
	// MaxConcurrentPulls limits concurrent image pulls to prevent overwhelming the registry
	MaxConcurrentPulls = 3
	// DefaultJobBufferSize is the default buffer size for job channels
	DefaultJobBufferSize = 100
)

Variables

View Source
var (
	ErrPoolShutdown      = errors.New("worker pool is shutdown")
	ErrUnknownJobType    = errors.New("unknown job type")
	ErrInvalidJobPayload = errors.New("invalid job payload")
	ErrNoContainerClient = errors.New("no container client provided")
	ErrJobTimeout        = errors.New("job execution timeout")
	ErrTooManyRetries    = errors.New("maximum retries exceeded")
)

Error definitions for concurrency operations

Functions

func ComputeChecksum

func ComputeChecksum(data []byte) string

ComputeChecksum computes SHA256 checksum with memory optimizations Uses streaming approach and buffer pooling for better performance

func ComputeChecksumConcurrent added in v0.18.0

func ComputeChecksumConcurrent(data []byte, numWorkers int) string

ComputeChecksumConcurrent computes SHA256 checksum using concurrent processing for very large data sets. Splits the data into chunks and processes them in parallel.

func GetEnv

func GetEnv(key string) string

func Getenv

func Getenv(key string) string

func ParseImageTag

func ParseImageTag(imageTag string) (string, string)

func SumChecksum added in v0.5.1

func SumChecksum(sums ...[]byte) string

SumChecksum combines multiple checksums with memory optimization

func TarDir added in v0.5.1

func TarDir(src fs.ReadDirFS) (*bytes.Buffer, error)

TarDir creates a tar archive from a filesystem with memory optimizations and concurrent processing

func TarDirConcurrent added in v0.18.0

func TarDirConcurrent(src fs.ReadDirFS, fileCount int, totalSize int64) (*bytes.Buffer, error)

TarDirConcurrent creates a tar archive using concurrent processing for better performance

func TarDirSequential added in v0.18.0

func TarDirSequential(src fs.ReadDirFS) (*bytes.Buffer, error)

TarDirSequential creates a tar archive using sequential processing (original implementation)

Types

type BatchImageOperations added in v0.18.0

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

BatchImageOperations provides batch operations for images

func NewBatchImageOperations added in v0.18.0

func NewBatchImageOperations(client cri.ContainerManager, maxConcurrent int) *BatchImageOperations

NewBatchImageOperations creates a new batch image operations manager

func (*BatchImageOperations) CheckImagesExistParallel added in v0.18.0

func (bio *BatchImageOperations) CheckImagesExistParallel(ctx context.Context, images []string) <-chan ImageExistsResult

CheckImagesExistParallel checks if multiple images exist in parallel

func (*BatchImageOperations) InspectImagesParallel added in v0.18.0

func (bio *BatchImageOperations) InspectImagesParallel(ctx context.Context, images []string) <-chan ImageInspectResult

InspectImagesParallel inspects multiple images in parallel

type Build

type Build struct {
	Leader             Leader
	Platform           types.Platform
	Custom             Custom
	Registries         map[string]*protos2.ContainerRegistry
	BuildType          BuildType `json:"build_type"`
	ContainifyRegistry string
	Folder             string
	App                string `json:"app"`
	Image              string `json:"image"`
	ImageTag           string `json:"image_tag"`
	Registry           string
	Env                EnvType
	File               string
	Repository         string
	Organization       string
	Runtime            utils.RuntimeType
	SourcePackages     []string
	SourceFiles        []string
	Verbose            bool
	// contains filtered or unexported fields
}

TODO: add target container platform Build struct optimized for memory alignment and cache performance

func InitRuntime

func InitRuntime(build *Build) *Build

func NewBuild

func NewBuild(build *Build) *Build

func NewGoServiceBuild

func NewGoServiceBuild(appName string) Build

func NewMavenServiceBuild

func NewMavenServiceBuild(appName string) Build

func NewPythonServiceBuild

func NewPythonServiceBuild(appName string) Build

func NewServiceBuild

func NewServiceBuild(appName string, buildType BuildType) Build

func (*Build) AsFlags

func (b *Build) AsFlags() []string

AsFlags converts build configuration to command-line flags with memory optimization

func (*Build) CustomString added in v0.4.0

func (b *Build) CustomString(key string) string

func (*Build) Defaults

func (b *Build) Defaults() *Build

func (*Build) ImageURI

func (b *Build) ImageURI() string

ImageURI constructs the full image URI with optimized performance

type BuildGroup added in v0.11.0

type BuildGroup struct {
	Builds []*Build
}

type BuildGroups added in v0.11.0

type BuildGroups []*BuildGroup

type BuildImagePayload added in v0.18.0

type BuildImagePayload struct {
	Client     cri.ContainerManager
	ImageName  string
	Platform   string
	Dockerfile []byte
}

BuildImagePayload contains data for image building

type BuildType

type BuildType string
const (
	GoLang  BuildType = "GoLang"
	Maven   BuildType = "Maven"
	Python  BuildType = "Python"
	Generic BuildType = "Generic"
)

func (*BuildType) Set

func (e *BuildType) Set(v string) error

Set must have pointer receiver so it doesn't change the value of a copy

func (*BuildType) String

func (e *BuildType) String() string

String is used both by fmt.Print and by Cobra in help text

func (*BuildType) Type

func (e *BuildType) Type() string

Type is only used in help text

type ConcurrentContainerManager added in v0.18.0

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

ConcurrentContainerManager wraps container operations with concurrency support

func NewConcurrentContainerManager added in v0.18.0

func NewConcurrentContainerManager(client cri.ContainerManager, poolSize int) *ConcurrentContainerManager

NewConcurrentContainerManager creates a new concurrent container manager

func (*ConcurrentContainerManager) CreateContainersParallel added in v0.18.0

func (ccm *ConcurrentContainerManager) CreateContainersParallel(ctx context.Context, requests []ContainerCreateRequest) <-chan ContainerCreateResult

CreateContainersParallel creates multiple containers in parallel

func (*ConcurrentContainerManager) PullImagesParallel added in v0.18.0

func (ccm *ConcurrentContainerManager) PullImagesParallel(ctx context.Context, requests []ImagePullRequest) <-chan ImagePullResult

PullImagesParallel pulls multiple images in parallel with rate limiting

func (*ConcurrentContainerManager) Start added in v0.18.0

func (ccm *ConcurrentContainerManager) Start()

Start starts the concurrent container manager

func (*ConcurrentContainerManager) StartContainersParallel added in v0.18.0

func (ccm *ConcurrentContainerManager) StartContainersParallel(ctx context.Context, containerIDs []string) <-chan ContainerOperationResult

StartContainersParallel starts multiple containers in parallel

func (*ConcurrentContainerManager) Stop added in v0.18.0

func (ccm *ConcurrentContainerManager) Stop()

Stop stops the concurrent container manager

func (*ConcurrentContainerManager) StopContainersParallel added in v0.18.0

func (ccm *ConcurrentContainerManager) StopContainersParallel(ctx context.Context, requests []ContainerStopRequest) <-chan ContainerOperationResult

StopContainersParallel stops multiple containers in parallel

func (*ConcurrentContainerManager) WaitContainersParallel added in v0.18.0

func (ccm *ConcurrentContainerManager) WaitContainersParallel(ctx context.Context, requests []ContainerWaitRequest) <-chan ContainerWaitResult

WaitContainersParallel waits for multiple containers in parallel

type ConcurrentImagePuller added in v0.18.0

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

ConcurrentImagePuller manages concurrent image pulling with rate limiting

func NewConcurrentImagePuller added in v0.18.0

func NewConcurrentImagePuller(maxConcurrent int, maxRetries int) *ConcurrentImagePuller

NewConcurrentImagePuller creates a new concurrent image puller

func (*ConcurrentImagePuller) PullImages added in v0.18.0

func (cip *ConcurrentImagePuller) PullImages(ctx context.Context, client cri.ContainerManager, images []ImagePullRequest) error

PullImages pulls multiple images concurrently with retry logic

func (*ConcurrentImagePuller) Start added in v0.18.0

func (cip *ConcurrentImagePuller) Start()

Start starts the concurrent image puller

func (*ConcurrentImagePuller) Stop added in v0.18.0

func (cip *ConcurrentImagePuller) Stop()

Stop stops the concurrent image puller

type Container

type Container struct {
	Source fs.ReadDirFS
	Build  *Build

	Env     EnvType
	Prefix  string
	Image   string
	Name    string
	ID      string
	Opts    types.ContainerConfig
	Verbose bool
	// contains filtered or unexported fields
}

func New

func New(build Build) *Container

func (*Container) Apply

func (c *Container) Apply(opts *types.ContainerConfig)

func (*Container) BuildImage

func (c *Container) BuildImage(dockerfile []byte, imageName string) error

func (*Container) BuildImageByPlatform

func (c *Container) BuildImageByPlatform(dockerfile []byte, imageName string, platform string) error

func (*Container) BuildImageByPlatforms

func (c *Container) BuildImageByPlatforms(dockerfile []byte, dockerCtx *bytes.Buffer, imageName string, platforms []string) ([]string, error)

func (*Container) BuildIntermidiateContainer

func (c *Container) BuildIntermidiateContainer(image string, dockerFile []byte, platforms ...string) error

func (*Container) BuildingContainer

func (c *Container) BuildingContainer(opts types.ContainerConfig) error

func (*Container) Cleanup added in v0.18.0

func (c *Container) Cleanup()

Cleanup properly shuts down concurrency components

func (*Container) Commit

func (c *Container) Commit(imageTag string, comment string, changes ...string) (string, error)

func (*Container) CopyContentTo

func (c *Container) CopyContentTo(content, dest string) error

func (*Container) CopyDirectoryTo

func (c *Container) CopyDirectoryTo(srcPath, dstPath string) error

TODO: ignore hidden folder and files maybe support .dockerignore file or more .dockerinclude file to include folder and files that are ignored by default

func (*Container) CopyFileFromContainer

func (c *Container) CopyFileFromContainer(srcPath string) (string, error)

CopyFileFromContainer reads a single file from a container and returns its content as a string.

func (*Container) CopyFileTo

func (c *Container) CopyFileTo(srcPath, destPath string) error

func (*Container) Create

func (c *Container) Create(opts types.ContainerConfig) error

func (*Container) Exec

func (c *Container) Exec(cmd ...string) error

func (*Container) GetBuild added in v0.11.0

func (c *Container) GetBuild() *Build

func (*Container) ImageExists

func (c *Container) ImageExists(imageName string, platforms ...string) (bool, error)

imageExists checks if the image with the specified tag exists.

func (*Container) Inspect

func (c *Container) Inspect() (*types.ContainerConfig, error)

func (*Container) InspectImage

func (c *Container) InspectImage(image string) (*types.ImageInfo, error)

func (*Container) Pull

func (c *Container) Pull(imageTags ...string) error

func (*Container) PullByPlatform

func (c *Container) PullByPlatform(platform string, imageTags ...string) error

func (*Container) PullDefault

func (c *Container) PullDefault(imageTags ...string) error

func (*Container) Push

func (c *Container) Push(source, target string, opts ...PushOption) error

TODO: find a better way to provide optional parameters like PushOption

func (*Container) Ready

func (c *Container) Ready() error

func (*Container) Start

func (c *Container) Start() error

func (*Container) Stop

func (c *Container) Stop() error

func (*Container) Tag

func (c *Container) Tag(source, target string) error

func (*Container) Wait

func (c *Container) Wait() error

type ContainerCreateRequest added in v0.18.0

type ContainerCreateRequest struct {
	Config     *types.ContainerConfig
	AuthBase64 string
}

ContainerCreateRequest represents a request to create a container

type ContainerCreateResult added in v0.18.0

type ContainerCreateResult struct {
	Error       error
	Name        string
	ContainerID string
}

ContainerCreateResult represents the result of a container creation

type ContainerOperationResult added in v0.18.0

type ContainerOperationResult struct {
	Error       error
	ContainerID string
}

ContainerOperationResult represents the result of a container operation

type ContainerStopRequest added in v0.18.0

type ContainerStopRequest struct {
	ContainerID string
	Signal      string
}

ContainerStopRequest represents a request to stop a container

type ContainerWaitRequest added in v0.18.0

type ContainerWaitRequest struct {
	ContainerID string
	Condition   string
}

ContainerWaitRequest represents a request to wait for a container

type ContainerWaitResult added in v0.18.0

type ContainerWaitResult struct {
	Error       error
	StatusCode  *int64
	ContainerID string
}

ContainerWaitResult represents the result of waiting for a container

type CopyFilesPayload added in v0.18.0

type CopyFilesPayload struct {
	Client      cri.ContainerManager
	ContainerID string
	SrcPath     string
	DstPath     string
}

CopyFilesPayload contains data for file copy operations

type CreateContainerPayload added in v0.18.0

type CreateContainerPayload struct {
	Client     cri.ContainerManager
	Config     *types.ContainerConfig
	AuthBase64 string
}

CreateContainerPayload contains data for container creation

type Custom added in v0.10.0

type Custom map[string][]string

func (Custom) Bool added in v0.10.0

func (c Custom) Bool(key string) bool

func (Custom) String added in v0.10.0

func (c Custom) String(key string) string

func (Custom) Strings added in v0.10.0

func (c Custom) Strings(key string) []string

func (Custom) UInt added in v0.10.0

func (c Custom) UInt(key string) uint

type EnvType

type EnvType string
const (
	LocalEnv EnvType = "local"
	BuildEnv EnvType = "build"
	ProdEnv  EnvType = "production"
)

func (*EnvType) Set

func (e *EnvType) Set(v string) error

Set must have pointer receiver so it doesn't change the value of a copy

func (*EnvType) String

func (e *EnvType) String() string

String is used both by fmt.Print and by Cobra in help text

func (*EnvType) Type

func (e *EnvType) Type() string

Type is only used in help text

type ExecCommandPayload added in v0.18.0

type ExecCommandPayload struct {
	Client       cri.ContainerManager
	ContainerID  string
	Command      []string
	AttachStdout bool
}

ExecCommandPayload contains data for command execution

type ImageExistsResult added in v0.18.0

type ImageExistsResult struct {
	Error  error
	Image  string
	Exists bool
}

ImageExistsResult represents the result of checking if an image exists

type ImageInspectResult added in v0.18.0

type ImageInspectResult struct {
	Error error
	Info  *types.ImageInfo
	Image string
}

ImageInspectResult represents the result of an image inspection

type ImagePullRequest added in v0.18.0

type ImagePullRequest struct {
	Image      string
	AuthBase64 string
	Platform   string
	Priority   Priority
	Retries    int
}

ImagePullRequest represents a request to pull an image

type ImagePullResult added in v0.18.0

type ImagePullResult struct {
	Reader io.ReadCloser
	Error  error
	Image  string
}

ImagePullResult represents the result of an image pull operation

type InspectImagePayload added in v0.18.0

type InspectImagePayload struct {
	Client cri.ContainerManager
	Image  string
}

InspectImagePayload contains data for image inspection

type Job added in v0.18.0

type Job struct {
	SubmittedAt time.Time
	Payload     interface{}
	Context     context.Context
	ID          string
	Type        JobType
	Priority    Priority
}

Job represents a unit of work to be executed by a worker

type JobResult added in v0.18.0

type JobResult struct {
	StartTime time.Time
	EndTime   time.Time
	Result    interface{}
	Error     error
	Job       Job
	Duration  time.Duration
	WorkerID  int
}

JobResult represents the result of a job execution

type JobType added in v0.18.0

type JobType int

JobType represents different types of container operations

const (
	JobTypePullImage JobType = iota
	JobTypeCreateContainer
	JobTypeStartContainer
	JobTypeStopContainer
	JobTypeBuildImage
	JobTypeCopyFiles
	JobTypeExecCommand
	JobTypeInspectImage
	JobTypeRemoveContainer
	JobTypeWaitContainer
)

func (JobType) String added in v0.18.0

func (jt JobType) String() string

String returns a string representation of the job type

type Leader added in v0.11.0

type Leader interface {
	Leader(id string, fnc func() error)
}

type Priority added in v0.18.0

type Priority int

Priority represents the priority of a job

const (
	PriorityLow Priority = iota
	PriorityNormal
	PriorityHigh
	PriorityCritical
)

func (Priority) String added in v0.18.0

func (p Priority) String() string

String returns a string representation of the priority

type PullImagePayload added in v0.18.0

type PullImagePayload struct {
	Client     cri.ContainerManager
	Image      string
	AuthBase64 string
	Platform   string
}

PullImagePayload contains data for image pull operations

type PushOption

type PushOption struct {
	Remove bool
}

type RemoveContainerPayload added in v0.18.0

type RemoveContainerPayload struct {
	Client      cri.ContainerManager
	ContainerID string
}

RemoveContainerPayload contains data for container removal

type Semaphore added in v0.18.0

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

Semaphore provides a simple semaphore implementation for rate limiting

func NewSemaphore added in v0.18.0

func NewSemaphore(capacity int) *Semaphore

NewSemaphore creates a new semaphore with the given capacity

func (*Semaphore) Acquire added in v0.18.0

func (s *Semaphore) Acquire(ctx context.Context) error

Acquire acquires a permit from the semaphore

func (*Semaphore) Available added in v0.18.0

func (s *Semaphore) Available() int

Available returns the number of available permits

func (*Semaphore) Release added in v0.18.0

func (s *Semaphore) Release()

Release releases a permit back to the semaphore

func (*Semaphore) TryAcquire added in v0.18.0

func (s *Semaphore) TryAcquire() bool

TryAcquire tries to acquire a permit without blocking

type StartContainerPayload added in v0.18.0

type StartContainerPayload struct {
	Client      cri.ContainerManager
	ContainerID string
}

StartContainerPayload contains data for starting containers

type StopContainerPayload added in v0.18.0

type StopContainerPayload struct {
	Client      cri.ContainerManager
	ContainerID string
	Signal      string
}

StopContainerPayload contains data for stopping containers

type WaitContainerPayload added in v0.18.0

type WaitContainerPayload struct {
	Client      cri.ContainerManager
	ContainerID string
	Condition   string
}

WaitContainerPayload contains data for waiting on containers

type Worker added in v0.18.0

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

Worker represents a single worker in the pool

type WorkerPool added in v0.18.0

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

WorkerPool manages a pool of workers for concurrent container operations

func NewWorkerPool added in v0.18.0

func NewWorkerPool(size int) *WorkerPool

NewWorkerPool creates a new worker pool with the specified size

func (*WorkerPool) GetMetrics added in v0.18.0

func (wp *WorkerPool) GetMetrics() WorkerPoolMetrics

GetMetrics returns current pool metrics

func (*WorkerPool) Results added in v0.18.0

func (wp *WorkerPool) Results() <-chan JobResult

Results returns the result channel for reading job results

func (*WorkerPool) Start added in v0.18.0

func (wp *WorkerPool) Start()

Start starts all workers in the pool

func (*WorkerPool) Stop added in v0.18.0

func (wp *WorkerPool) Stop()

Stop gracefully stops all workers

func (*WorkerPool) Submit added in v0.18.0

func (wp *WorkerPool) Submit(job Job) error

Submit submits a job to the worker pool

type WorkerPoolMetrics added in v0.18.0

type WorkerPoolMetrics struct {
	PoolSize         int
	JobsSubmitted    int64
	JobsCompleted    int64
	JobsFailed       int64
	CurrentQueueLen  int64
	PeakQueueDepth   int64
	AvgQueueTime     time.Duration
	AvgExecutionTime time.Duration
	IsStarted        bool
	IsShutdown       bool
}

WorkerPoolMetrics contains metrics about the worker pool

Jump to

Keyboard shortcuts

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