deployer

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2025 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BuildJob

type BuildJob struct {
	ServiceName string
	Service     *config.ServiceConfig
	ImageName   string
}

BuildJob represents a single service build job

type BuildResult

type BuildResult struct {
	ServiceName string
	ImageName   string
	Duration    time.Duration
	Error       error
}

BuildResult contains the result of a build job

type CacheManager

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

CacheManager handles build caching using Docker BuildKit

func NewCacheManager

func NewCacheManager(projectName, environment string, verbose bool) *CacheManager

NewCacheManager creates a new cache manager

func (*CacheManager) GenerateCacheKey

func (cm *CacheManager) GenerateCacheKey(serviceName string, service *config.ServiceConfig) (string, error)

GenerateCacheKey generates a cache key for a service based on its build context

func (*CacheManager) GetBuildCommand

func (cm *CacheManager) GetBuildCommand(imageName, buildContext string, service *config.ServiceConfig) string

GetBuildCommand returns the enhanced build command with caching

func (*CacheManager) GetBuildKitFlags

func (cm *CacheManager) GetBuildKitFlags(serviceName string, service *config.ServiceConfig) []string

GetBuildKitFlags returns Docker BuildKit flags for caching

func (*CacheManager) GetLocalCachePath

func (cm *CacheManager) GetLocalCachePath(serviceName string) string

GetLocalCachePath returns the local cache path for a service

func (*CacheManager) IsCached

func (cm *CacheManager) IsCached(serviceName string) bool

IsCached checks if a cached image exists locally

func (*CacheManager) OptimizeBuildContext

func (cm *CacheManager) OptimizeBuildContext(buildPath string) ([]string, error)

OptimizeBuildContext creates an optimized build context by excluding unnecessary files

func (*CacheManager) SaveImageToCache

func (cm *CacheManager) SaveImageToCache(imageName, serviceName string) error

SaveImageToCache saves a Docker image to local cache

type CacheStats

type CacheStats struct {
	TotalBuilds int
	CacheHits   int
	CacheMisses int
	TimesSaved  time.Duration
}

CacheStats tracks cache hit/miss statistics

func (*CacheStats) GetHitRate

func (cs *CacheStats) GetHitRate() float64

GetHitRate returns the cache hit rate as a percentage

func (*CacheStats) Report

func (cs *CacheStats) Report()

Report prints cache statistics

type ContainerManager

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

ContainerManager handles container lifecycle operations

func NewContainerManager

func NewContainerManager(client *ssh.Client, verbose bool) *ContainerManager

NewContainerManager creates a new container manager

func (*ContainerManager) Exists

func (cm *ContainerManager) Exists(containerName string) (bool, error)

Exists checks if a container with the given name exists (running or stopped)

func (*ContainerManager) GetStatus

func (cm *ContainerManager) GetStatus(containerName string) (string, error)

GetStatus returns the status of a container

func (*ContainerManager) IsRunning

func (cm *ContainerManager) IsRunning(containerName string) (bool, error)

IsRunning checks if a container is currently running

func (*ContainerManager) Remove

func (cm *ContainerManager) Remove(containerName string) error

Remove forcefully removes a container

func (*ContainerManager) Rename

func (cm *ContainerManager) Rename(oldName, newName string) error

Rename renames a container

func (*ContainerManager) StopGracefully

func (cm *ContainerManager) StopGracefully(containerName string, gracePeriodSeconds int) error

StopGracefully stops a container with a grace period for cleanup

func (*ContainerManager) WaitForTrafficDrain

func (cm *ContainerManager) WaitForTrafficDrain(containerName string, drainSeconds int)

WaitForTrafficDrain waits for in-flight requests to complete before stopping a container

type Deployer

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

Deployer handles deployment operations

func NewDeployer

func NewDeployer(client *ssh.Client, cfg *config.Config, environment string, verbose bool) *Deployer

NewDeployer creates a new deployer

func NewDeployerWithPool

func NewDeployerWithPool(client *ssh.Client, cfg *config.Config, environment string, sshPool *ssh.Pool, verbose bool) *Deployer

NewDeployerWithPool creates a deployer with SSH pool for multi-server support

func (*Deployer) BuildImage

func (d *Deployer) BuildImage(serviceName string, service *config.ServiceConfig) (string, error)

BuildImage builds a Docker image for a service without deploying it This is used for Swarm mode where we need to build first, then deploy with docker service create

func (*Deployer) CheckPortAvailability

func (d *Deployer) CheckPortAvailability(port int) (*PortInfo, error)

CheckPortAvailability checks if a port is available on the server

func (*Deployer) DeployService

func (d *Deployer) DeployService(serviceName string, service *config.ServiceConfig, skipBuild bool) error

DeployService deploys a service with multi-replica support using blue-green strategy

func (*Deployer) DeployServiceSwarm

func (d *Deployer) DeployServiceSwarm(serviceName string, service *config.ServiceConfig, fullImageName string) error

DeployServiceSwarm deploys a service to Docker Swarm

func (*Deployer) IsSwarmMode

func (d *Deployer) IsSwarmMode() bool

IsSwarmMode returns true if this environment should use Swarm

func (*Deployer) ResolvePortConflict

func (d *Deployer) ResolvePortConflict(portInfo *PortInfo, serviceName string, autoKill bool) error

ResolvePortConflict attempts to resolve a port conflict

func (*Deployer) Rollback

func (d *Deployer) Rollback(serviceName string) error

Rollback rolls back to the previous deployment

func (*Deployer) RollbackToState

func (d *Deployer) RollbackToState(serviceName string, serviceState *state.ServiceState) error

RollbackToState rolls back a service to a specific deployment state

func (*Deployer) SetupSwarmCluster

func (d *Deployer) SetupSwarmCluster() error

SetupSwarmCluster initializes the Docker Swarm cluster

func (*Deployer) VerifyDatabaseConnectivity

func (d *Deployer) VerifyDatabaseConnectivity(serviceName string, service *config.ServiceConfig) error

VerifyDatabaseConnectivity verifies that a service can reach its database

func (*Deployer) VerifyNetworkSetup

func (d *Deployer) VerifyNetworkSetup() error

VerifyNetworkSetup verifies that Traefik is connected to all project networks

type DeploymentMetrics

type DeploymentMetrics struct {
	StartTime        time.Time
	EndTime          time.Time
	TotalDuration    time.Duration
	BuildDuration    time.Duration
	DeployDuration   time.Duration
	ServicesDeployed int
	BuildsParallel   int
	DeploysParallel  int
	CacheHitRate     float64
	ParallelSpeedup  float64
	Failures         []string
}

DeploymentMetrics tracks deployment performance metrics

type DeploymentOrchestrator

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

DeploymentOrchestrator coordinates the entire deployment pipeline

func NewDeploymentOrchestrator

func NewDeploymentOrchestrator(deployer *Deployer, config OrchestratorConfig) *DeploymentOrchestrator

NewDeploymentOrchestrator creates a new deployment orchestrator

func (*DeploymentOrchestrator) Deploy

func (do *DeploymentOrchestrator) Deploy(ctx context.Context, services map[string]config.ServiceConfig, skipBuild bool) error

Deploy executes the complete deployment pipeline

func (*DeploymentOrchestrator) EstimateDeploymentTime

func (do *DeploymentOrchestrator) EstimateDeploymentTime(serviceCount int) time.Duration

EstimateDeploymentTime estimates deployment time based on service count and configuration

func (*DeploymentOrchestrator) GetMetrics

func (do *DeploymentOrchestrator) GetMetrics() *DeploymentMetrics

GetMetrics returns the deployment metrics

type EnhancedBuildResult

type EnhancedBuildResult struct {
	ServiceName string
	ImageName   string
	Duration    time.Duration
	CacheHit    bool
	Error       error
}

EnhancedBuildResult contains build result with cache information

func (*EnhancedBuildResult) String

func (r *EnhancedBuildResult) String() string

String returns a string representation of the result

type EnvManager

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

EnvManager handles environment variable management

func NewEnvManager

func NewEnvManager(client *ssh.Client, projectName, environment string, verbose bool) *EnvManager

NewEnvManager creates a new environment manager

func (*EnvManager) LoadAndMerge

func (em *EnvManager) LoadAndMerge(service *config.ServiceConfig) map[string]string

LoadAndMerge loads environment variables from envFile and merges with explicit env vars Priority: explicit env > envFile

type HealthChecker

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

HealthChecker handles container health verification

func NewHealthChecker

func NewHealthChecker(client *ssh.Client, verbose bool) *HealthChecker

NewHealthChecker creates a new health checker

func (*HealthChecker) VerifyDatabaseConnectivity

func (hc *HealthChecker) VerifyDatabaseConnectivity(containerName string, service *config.ServiceConfig) error

VerifyDatabaseConnectivity verifies that a service can reach its database

func (*HealthChecker) WaitForHealthy

func (hc *HealthChecker) WaitForHealthy(containerName string, retries int) error

WaitForHealthy waits for a container to become healthy

type IgnoreParser

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

IgnoreParser handles parsing of .gitignore and .dockerignore files

func NewIgnoreParser

func NewIgnoreParser() *IgnoreParser

NewIgnoreParser creates a new ignore parser

func (*IgnoreParser) AddDefaultExclusions

func (ip *IgnoreParser) AddDefaultExclusions()

AddDefaultExclusions adds commonly excluded patterns

func (*IgnoreParser) GetExcludedPatterns

func (ip *IgnoreParser) GetExcludedPatterns() []string

GetExcludedPatterns returns all exclusion patterns

func (*IgnoreParser) LoadIgnoreFile

func (ip *IgnoreParser) LoadIgnoreFile(filePath string) error

LoadIgnoreFile loads patterns from a .gitignore or .dockerignore file

func (*IgnoreParser) ShouldIgnore

func (ip *IgnoreParser) ShouldIgnore(relPath string) bool

ShouldIgnore checks if a file path should be ignored

type MaintenanceManager

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

MaintenanceManager handles maintenance mode operations

func NewMaintenanceManager

func NewMaintenanceManager(client *ssh.Client, projectName string, verbose bool) *MaintenanceManager

NewMaintenanceManager creates a new maintenance manager

func (*MaintenanceManager) IsActive

func (mm *MaintenanceManager) IsActive(serviceName string) (bool, error)

IsActive checks if maintenance mode is currently active for a service

func (*MaintenanceManager) Remove

func (mm *MaintenanceManager) Remove(serviceName string) error

Remove removes the maintenance page container if it exists This is called automatically during deployment to restore normal traffic

type OrchestratorConfig

type OrchestratorConfig struct {
	MaxConcurrentBuilds  int
	MaxConcurrentDeploys int
	EnableCache          bool
	BuildTimeout         time.Duration
	DeployTimeout        time.Duration
}

OrchestratorConfig contains orchestrator configuration

type ParallelBuilder

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

ParallelBuilder handles parallel service builds with dependency-aware grouping

func NewParallelBuilder

func NewParallelBuilder(deployer *Deployer, maxConcurrent int) *ParallelBuilder

NewParallelBuilder creates a new parallel builder

func (*ParallelBuilder) BuildAllLevels

func (pb *ParallelBuilder) BuildAllLevels(ctx context.Context, services map[string]config.ServiceConfig, skipBuild bool) (map[string]string, error)

BuildAllLevels builds all services in dependency order with parallelization

func (*ParallelBuilder) GroupByDependencyLevel

func (pb *ParallelBuilder) GroupByDependencyLevel(services map[string]config.ServiceConfig) [][]string

GroupByDependencyLevel groups services by dependency level Level 0: services with no dependencies Level 1: services that depend only on level 0 services Level N: services that depend on services up to level N-1

type ParallelDeployer

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

ParallelDeployer handles parallel service deployments

func NewParallelDeployer

func NewParallelDeployer(deployer *Deployer, maxConcurrent int) *ParallelDeployer

NewParallelDeployer creates a new parallel deployer

func (*ParallelDeployer) DeployLevel

func (pd *ParallelDeployer) DeployLevel(ctx context.Context, services map[string]config.ServiceConfig, serviceNames []string, imageMap map[string]string) error

DeployLevel deploys all services in a level in parallel

type PortInfo

type PortInfo struct {
	Port        int
	ProcessName string
	PID         string
	IsDocker    bool
	ContainerID string
}

PortInfo contains information about a port in use

type ReplicaManager

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

ReplicaManager handles replica cleanup and management

func NewReplicaManager

func NewReplicaManager(client *ssh.Client, projectName, environment string, verbose bool) *ReplicaManager

NewReplicaManager creates a new replica manager

func (*ReplicaManager) CleanupOld

func (rm *ReplicaManager) CleanupOld(serviceName string, desiredCount int) error

CleanupOld removes replica containers that exceed the desired count

func (*ReplicaManager) GetContainerName

func (rm *ReplicaManager) GetContainerName(serviceName string, replicaNum int) string

GetContainerName returns the standard container name for a replica

type Stage

type Stage struct {
	Name string
	Fn   func(context.Context) error
}

Stage represents a deployment pipeline stage

type VolumeTransformer

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

VolumeTransformer handles volume path transformations

func NewVolumeTransformer

func NewVolumeTransformer(projectName, environment string) *VolumeTransformer

NewVolumeTransformer creates a new volume transformer

func (*VolumeTransformer) Transform

func (vt *VolumeTransformer) Transform(volumes []string) []string

Transform prefixes named volumes with project name and environment for isolation Leaves bind mounts (absolute paths) unchanged

Jump to

Keyboard shortcuts

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