func (c *containerInstance) Start() error {
	return c.runtime.Start(c.status.ID)
}
Start starts the container.
package container
import (
	"fmt"
	"os"
	"github.com/flexkube/libflexkube/pkg/container/runtime"
	"github.com/flexkube/libflexkube/pkg/container/runtime/docker"
	"github.com/flexkube/libflexkube/pkg/container/types"
)
type Interface interface {
	Create() (InstanceInterface, error)
	FromStatus() (InstanceInterface, error)
	UpdateStatus() error
	Start() error
	Stop() error
	Delete() error
	Status() *types.ContainerStatus
	Config() types.ContainerConfig
	RuntimeConfig() runtime.Config
	Runtime() runtime.Runtime
	SetRuntime(runtime.Runtime)
	SetStatus(types.ContainerStatus)
}
type InstanceInterface interface {
	Status() (types.ContainerStatus, error)
	Read(srcPath []string) ([]*types.File, error)
	Copy(files []*types.File) error
	Stat(paths []string) (map[string]os.FileMode, error)
	Start() error
	Stop() error
	Delete() error
}
type Container struct {
	Config types.ContainerConfig `json:"config"`
	Status *types.ContainerStatus `json:"status,omitempty"`
	Runtime RuntimeConfig `json:"runtime,omitempty"`
}
type RuntimeConfig struct {
	Docker *docker.Config `json:"docker,omitempty"`
}
type container struct {
	base
}
type containerInstance struct {
	base
}
type base struct {
	config types.ContainerConfig
	runtime       runtime.Runtime
	runtimeConfig runtime.Config
	status types.ContainerStatus
}
func (c *Container) New() (Interface, error) {
	if err := c.Validate(); err != nil {
		return nil, fmt.Errorf("container configuration validation failed: %w", err)
	}
	nc := &container{
		base{
			config:        c.Config,
			runtimeConfig: c.Runtime.Docker,
		},
	}
	if c.Status != nil {
		nc.base.status = *c.Status
	}
	if err := nc.selectRuntime(); err != nil {
		return nil, fmt.Errorf("determining container runtime: %w", err)
	}
	return nc, nil
}
func (c *Container) Validate() error {
	if c.Config.Name == "" {
		return fmt.Errorf("name must be set")
	}
	if c.Config.Image == "" {
		return fmt.Errorf("image must be set")
	}
	if c.Runtime.Docker == nil {
		return fmt.Errorf("docker runtime must be set")
	}
	return nil
}
func (c *container) selectRuntime() error {
	r, err := c.runtimeConfig.New()
	if err != nil {
		return fmt.Errorf("selecting container runtime: %w", err)
	}
	c.runtime = r
	return nil
}
func (c *container) Create() (InstanceInterface, error) {
	id, err := c.runtime.Create(&c.config)
	if err != nil {
		return nil, fmt.Errorf("creating container: %w", err)
	}
	return &containerInstance{
		base{
			config:  c.config,
			runtime: c.runtime,
			status: types.ContainerStatus{
				ID: id,
			},
		},
	}, nil
}
func (c *container) FromStatus() (InstanceInterface, error) {
	if !c.status.Exists() {
		return nil, fmt.Errorf("can't create container instance from status without id: %+v", c.status)
	}
	return &containerInstance{
		base: c.base,
	}, nil
}
func (c *container) Config() types.ContainerConfig {
	return c.config
}
func (c *container) RuntimeConfig() runtime.Config {
	return c.runtimeConfig
}
func (c *container) UpdateStatus() error {
	ci, err := c.FromStatus()
	if err != nil {
		return fmt.Errorf("creating container instance: %w", err)
	}
	s, err := ci.Status()
	if err != nil {
		return fmt.Errorf("checking container status: %w", err)
	}
	c.status = s
	return nil
}
func (c *container) Status() *types.ContainerStatus {
	return &c.status
}
func (c *container) SetRuntime(r runtime.Runtime) {
	c.runtime = r
}
func (c *container) SetStatus(s types.ContainerStatus) {
	c.status = s
}
func (c *container) Runtime() runtime.Runtime {
	return c.runtime
}
func (c *container) Start() error {
	ci, err := c.FromStatus()
	if err != nil {
		return fmt.Errorf("getting containers instance from status: %w", err)
	}
	if err := ci.Start(); err != nil {
		return fmt.Errorf("starting container: %w", err)
	}
	return c.UpdateStatus()
}
func (c *container) Stop() error {
	ci, err := c.FromStatus()
	if err != nil {
		return fmt.Errorf("getting containers instance from status: %w", err)
	}
	if err := ci.Stop(); err != nil {
		return fmt.Errorf("stopping container: %w", err)
	}
	return c.UpdateStatus()
}
func (c *container) Delete() error {
	ci, err := c.FromStatus()
	if err != nil {
		return fmt.Errorf("getting containers instance from status: %w", err)
	}
	if err := ci.Delete(); err != nil {
		return fmt.Errorf("deleting container: %w", err)
	}
	c.Status().ID = ""
	return nil
}
func (c *containerInstance) Status() (types.ContainerStatus, error) {
	return c.runtime.Status(c.status.ID)
}
func (c *containerInstance) Read(srcPath []string) ([]*types.File, error) {
	return c.runtime.Read(c.status.ID, srcPath)
}
func (c *containerInstance) Copy(files []*types.File) error {
	return c.runtime.Copy(c.status.ID, files)
}
func (c *containerInstance) Stat(paths []string) (map[string]os.FileMode, error) {
	return c.runtime.Stat(c.status.ID, paths)
}