Documentation
¶
Index ¶
- func GetCurrentState(ctx context.Context, cli DockerClient, stackName string) (*plan.CurrentState, error)
- type DeploymentResult
- type DockerClient
- type MockDockerClient
- func (m *MockDockerClient) Close() error
- func (m *MockDockerClient) ContainerInspect(ctx context.Context, containerID string) (types.ContainerJSON, error)
- func (m *MockDockerClient) ContainerList(ctx context.Context, options container.ListOptions) ([]types.Container, error)
- func (m *MockDockerClient) ContainerRemove(ctx context.Context, containerID string, options container.RemoveOptions) error
- func (m *MockDockerClient) ImagePull(ctx context.Context, refStr string, options image.PullOptions) (io.ReadCloser, error)
- func (m *MockDockerClient) NetworkCreate(ctx context.Context, name string, options network.CreateOptions) (network.CreateResponse, error)
- func (m *MockDockerClient) NetworkInspect(ctx context.Context, networkID string, options network.InspectOptions) (network.Inspect, error)
- func (m *MockDockerClient) NetworkList(ctx context.Context, options network.ListOptions) ([]network.Summary, error)
- func (m *MockDockerClient) NetworkRemove(ctx context.Context, networkID string) error
- func (m *MockDockerClient) ServiceCreate(ctx context.Context, service swarm.ServiceSpec, ...) (swarm.ServiceCreateResponse, error)
- func (m *MockDockerClient) ServiceInspectWithRaw(ctx context.Context, serviceID string, options types.ServiceInspectOptions) (swarm.Service, []byte, error)
- func (m *MockDockerClient) ServiceList(ctx context.Context, options types.ServiceListOptions) ([]swarm.Service, error)
- func (m *MockDockerClient) ServiceRemove(ctx context.Context, serviceID string) error
- func (m *MockDockerClient) ServiceUpdate(ctx context.Context, serviceID string, version swarm.Version, ...) (swarm.ServiceUpdateResponse, error)
- func (m *MockDockerClient) TaskList(ctx context.Context, options types.TaskListOptions) ([]swarm.Task, error)
- func (m *MockDockerClient) VolumeCreate(ctx context.Context, options volume.CreateOptions) (volume.Volume, error)
- func (m *MockDockerClient) VolumeInspect(ctx context.Context, volumeID string) (volume.Volume, error)
- func (m *MockDockerClient) VolumeList(ctx context.Context, options volume.ListOptions) (volume.ListResponse, error)
- type ResourceSnapshot
- type ServiceSnapshot
- type ServiceUpdateResult
- type StackDeployer
- func (d *StackDeployer) CreateSnapshot(ctx context.Context) (*StackSnapshot, error)
- func (d *StackDeployer) Deploy(ctx context.Context, composeFile *compose.ComposeFile, deployID string) (*DeploymentResult, error)
- func (d *StackDeployer) GetStackServices(ctx context.Context) ([]swarm.Service, error)
- func (d *StackDeployer) RemoveExitedContainers(ctx context.Context) error
- func (d *StackDeployer) RemoveStack(ctx context.Context) error
- func (d *StackDeployer) Rollback(ctx context.Context, snapshot *StackSnapshot) error
- type StackSnapshot
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetCurrentState ¶
func GetCurrentState(ctx context.Context, cli DockerClient, stackName string) (*plan.CurrentState, error)
GetCurrentState reads the current state of a stack from Swarm
Types ¶
type DeploymentResult ¶
type DeploymentResult struct {
UpdatedServices []ServiceUpdateResult // Services that were created or updated
DeployID string // Deployment ID for this deployment
}
DeploymentResult contains information about all services deployed
type DockerClient ¶
type DockerClient interface {
ServiceList(ctx context.Context, options types.ServiceListOptions) ([]swarm.Service, error)
ServiceCreate(ctx context.Context, service swarm.ServiceSpec, options types.ServiceCreateOptions) (swarm.ServiceCreateResponse, error)
ServiceUpdate(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options types.ServiceUpdateOptions) (swarm.ServiceUpdateResponse, error)
ServiceRemove(ctx context.Context, serviceID string) error
ServiceInspectWithRaw(ctx context.Context, serviceID string, options types.ServiceInspectOptions) (swarm.Service, []byte, error)
TaskList(ctx context.Context, options types.TaskListOptions) ([]swarm.Task, error)
ContainerList(ctx context.Context, options container.ListOptions) ([]types.Container, error)
ContainerInspect(ctx context.Context, containerID string) (types.ContainerJSON, error)
ContainerRemove(ctx context.Context, containerID string, options container.RemoveOptions) error
NetworkCreate(ctx context.Context, name string, options network.CreateOptions) (network.CreateResponse, error)
NetworkList(ctx context.Context, options network.ListOptions) ([]network.Summary, error)
NetworkInspect(ctx context.Context, networkID string, options network.InspectOptions) (network.Inspect, error)
VolumeCreate(ctx context.Context, options volume.CreateOptions) (volume.Volume, error)
VolumeList(ctx context.Context, options volume.ListOptions) (volume.ListResponse, error)
VolumeInspect(ctx context.Context, volumeID string) (volume.Volume, error)
NetworkRemove(ctx context.Context, networkID string) error
ImagePull(ctx context.Context, refStr string, options image.PullOptions) (io.ReadCloser, error)
Close() error
}
DockerClient определяет интерфейс для взаимодействия с Docker API
type MockDockerClient ¶
type MockDockerClient struct {
// contains filtered or unexported fields
}
MockDockerClient implements DockerClient interface for testing
func (*MockDockerClient) Close ¶
func (m *MockDockerClient) Close() error
func (*MockDockerClient) ContainerInspect ¶
func (m *MockDockerClient) ContainerInspect(ctx context.Context, containerID string) (types.ContainerJSON, error)
func (*MockDockerClient) ContainerList ¶
func (m *MockDockerClient) ContainerList(ctx context.Context, options container.ListOptions) ([]types.Container, error)
func (*MockDockerClient) ContainerRemove ¶
func (m *MockDockerClient) ContainerRemove(ctx context.Context, containerID string, options container.RemoveOptions) error
func (*MockDockerClient) ImagePull ¶
func (m *MockDockerClient) ImagePull(ctx context.Context, refStr string, options image.PullOptions) (io.ReadCloser, error)
func (*MockDockerClient) NetworkCreate ¶
func (m *MockDockerClient) NetworkCreate(ctx context.Context, name string, options network.CreateOptions) (network.CreateResponse, error)
func (*MockDockerClient) NetworkInspect ¶
func (m *MockDockerClient) NetworkInspect(ctx context.Context, networkID string, options network.InspectOptions) (network.Inspect, error)
func (*MockDockerClient) NetworkList ¶
func (m *MockDockerClient) NetworkList(ctx context.Context, options network.ListOptions) ([]network.Summary, error)
func (*MockDockerClient) NetworkRemove ¶
func (m *MockDockerClient) NetworkRemove(ctx context.Context, networkID string) error
func (*MockDockerClient) ServiceCreate ¶
func (m *MockDockerClient) ServiceCreate(ctx context.Context, service swarm.ServiceSpec, options types.ServiceCreateOptions) (swarm.ServiceCreateResponse, error)
func (*MockDockerClient) ServiceInspectWithRaw ¶
func (m *MockDockerClient) ServiceInspectWithRaw(ctx context.Context, serviceID string, options types.ServiceInspectOptions) (swarm.Service, []byte, error)
func (*MockDockerClient) ServiceList ¶
func (m *MockDockerClient) ServiceList(ctx context.Context, options types.ServiceListOptions) ([]swarm.Service, error)
func (*MockDockerClient) ServiceRemove ¶
func (m *MockDockerClient) ServiceRemove(ctx context.Context, serviceID string) error
func (*MockDockerClient) ServiceUpdate ¶
func (m *MockDockerClient) ServiceUpdate(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options types.ServiceUpdateOptions) (swarm.ServiceUpdateResponse, error)
func (*MockDockerClient) TaskList ¶
func (m *MockDockerClient) TaskList(ctx context.Context, options types.TaskListOptions) ([]swarm.Task, error)
func (*MockDockerClient) VolumeCreate ¶
func (m *MockDockerClient) VolumeCreate(ctx context.Context, options volume.CreateOptions) (volume.Volume, error)
func (*MockDockerClient) VolumeInspect ¶
func (*MockDockerClient) VolumeList ¶
func (m *MockDockerClient) VolumeList(ctx context.Context, options volume.ListOptions) (volume.ListResponse, error)
type ResourceSnapshot ¶
type ResourceSnapshot struct {
Networks map[string]string // name -> ID
Volumes map[string]string // name -> ID
}
ResourceSnapshot stores state of stack resources
type ServiceSnapshot ¶
ServiceSnapshot stores the state of a service before deployment
type ServiceUpdateResult ¶
type ServiceUpdateResult struct {
ServiceID string // Docker service ID
ServiceName string // Full service name (stack_service)
Version swarm.Version // Service version after update
Warnings []string // Any warnings from Docker API
Changed bool // Whether service was actually changed
DeployID string // Deployment ID for this deployment
}
ServiceUpdateResult contains information about a service deployment
type StackDeployer ¶
type StackDeployer struct {
MaxFailedTaskCount int // Maximum number of failed tasks before giving up
// contains filtered or unexported fields
}
func NewStackDeployer ¶
func NewStackDeployer(cli DockerClient, stackName string, maxFailedTaskCount int) *StackDeployer
func (*StackDeployer) CreateSnapshot ¶
func (d *StackDeployer) CreateSnapshot(ctx context.Context) (*StackSnapshot, error)
CreateSnapshot creates a snapshot of the current stack state
func (*StackDeployer) Deploy ¶
func (d *StackDeployer) Deploy(ctx context.Context, composeFile *compose.ComposeFile, deployID string) (*DeploymentResult, error)
Deploy deploys a complete stack from a compose file Returns DeploymentResult with information about updated services, or error
func (*StackDeployer) GetStackServices ¶
GetStackServices returns all services in the stack
func (*StackDeployer) RemoveExitedContainers ¶
func (d *StackDeployer) RemoveExitedContainers(ctx context.Context) error
RemoveExitedContainers removes all exited containers from the stack
func (*StackDeployer) RemoveStack ¶
func (d *StackDeployer) RemoveStack(ctx context.Context) error
RemoveStack removes all resources associated with the stack
func (*StackDeployer) Rollback ¶
func (d *StackDeployer) Rollback(ctx context.Context, snapshot *StackSnapshot) error
Rollback restores the stack to a previous snapshot
type StackSnapshot ¶
type StackSnapshot struct {
StackName string
CreatedAt time.Time
Services map[string]ServiceSnapshot // key is service ID
ExistingIDs map[string]bool // IDs that existed before deploy
Resources ResourceSnapshot
IsFirstDeploy bool // true if stack didn't exist before
}
StackSnapshot stores the complete state of a stack before deployment