core

package
v1.9.5 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2025 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const HashmeTagName = "hash"

Variables

View Source
var (
	// ErrSkippedExecution pass this error to `Execution.Stop` if you wish to mark
	// it as skipped.
	ErrSkippedExecution   = errors.New("skipped execution")
	ErrUnexpected         = errors.New("error unexpected, docker has returned exit code -1, maybe wrong user?")
	ErrMaxTimeRunning     = errors.New("the job has exceed the maximum allowed time running.")
	ErrLocalImageNotFound = errors.New("couldn't find image on the host")
)
View Source
var (
	ErrEmptyScheduler = errors.New("unable to start a empty scheduler.")
	ErrEmptySchedule  = errors.New("unable to add a job with a empty schedule.")
)
View Source
var (
	SchedulerJobs = promauto.NewGauge(prometheus.GaugeOpts{
		Name: "chadburn_scheduler_jobs",
		Help: "Active job count registered on the scheduler.",
	})
	JobRegisterErrorsTotal = promauto.NewCounter(prometheus.CounterOpts{
		Name: "chadburn_scheduler_register_errors_total",
		Help: "Total number of failed scheduler registrations.",
	})
	RunsTotal = promauto.NewCounterVec(
		prometheus.CounterOpts{
			Name: "chadburn_run_total",
			Help: "Total number of completed job runs.",
		},
		[]string{"job_name"},
	)
	RunErrorsTotal = promauto.NewCounterVec(
		prometheus.CounterOpts{
			Name: "chadburn_run_errors_total",
			Help: "Total number of completed job runs that resulted in an error.",
		},
		[]string{"job_name"},
	)
	RunLatest = promauto.NewGaugeVec(
		prometheus.GaugeOpts{
			Name: "chadburn_run_latest_timestamp",
			Help: "Last time a job run completed.",
		},
		[]string{"job_name"},
	)
	RunDuration = promauto.NewHistogramVec(
		prometheus.HistogramOpts{
			Name: "chadburn_run_duration_seconds",
			Help: "Duration of all runs.",
		},
		[]string{"job_name"},
	)
)

Functions

func ProcessVariables added in v1.5.0

func ProcessVariables(input string, context VariableContext) (string, error)

ProcessVariables replaces variables in the input string using the provided context

Types

type BareJob

type BareJob struct {
	Schedule string `hash:"true"`
	Name     string `hash:"true"`
	Command  string `hash:"true"`
	// contains filtered or unexported fields
}

func (*BareJob) GetCommand

func (j *BareJob) GetCommand() string

func (*BareJob) GetCronJobID

func (j *BareJob) GetCronJobID() int

func (*BareJob) GetName

func (j *BareJob) GetName() string

func (*BareJob) GetProcessedCommand added in v1.5.0

func (j *BareJob) GetProcessedCommand(context VariableContext) string

GetProcessedCommand returns the command with variables replaced

func (*BareJob) GetSchedule

func (j *BareJob) GetSchedule() string

func (*BareJob) Middlewares

func (c *BareJob) Middlewares() []Middleware

func (*BareJob) NotifyStart

func (j *BareJob) NotifyStart()

func (*BareJob) NotifyStop

func (j *BareJob) NotifyStop()

func (*BareJob) Running

func (j *BareJob) Running() int32

func (*BareJob) SetCronJobID

func (j *BareJob) SetCronJobID(id int)

func (*BareJob) SetVolumeMounts added in v1.5.0

func (j *BareJob) SetVolumeMounts(volumes []string)

func (*BareJob) Use

func (c *BareJob) Use(ms ...Middleware)

type Container added in v1.7.0

type Container struct {
	ID     string
	Name   string
	Labels map[string]string
	State  struct {
		Running bool
	}
	Config struct {
		Labels map[string]string
	}
}

Container represents a Docker container

type ContainerConfig added in v1.7.0

type ContainerConfig struct {
	Image        string
	Cmd          []string
	Env          []string
	WorkingDir   string
	User         string
	Volumes      map[string]struct{}
	ExposedPorts map[string]struct{}
	Labels       map[string]string
	Tty          bool
	AttachStdin  bool
	AttachStdout bool
	AttachStderr bool
	NetworkMode  string
	HostConfig   *HostConfig
}

ContainerConfig represents configuration for creating a container

type ContainerInfo added in v1.5.0

type ContainerInfo struct {
	Name string
	ID   string
}

ContainerInfo holds information about a container that can be used in variable replacements

type Context

type Context struct {
	Scheduler *Scheduler
	Logger    Logger
	Job       Job
	Execution *Execution
	// contains filtered or unexported fields
}

func NewContext

func NewContext(s *Scheduler, j Job, e *Execution) *Context

NewContext creates a new Context

func (*Context) Log

func (c *Context) Log(msg string)

func (*Context) Next

func (c *Context) Next() error

Next executes the next middleware in the chain

func (*Context) Run added in v1.7.0

func (c *Context) Run() error

func (*Context) Start

func (c *Context) Start()

Start starts the execution

func (*Context) Stop

func (c *Context) Stop(err error)

type CronUtils

type CronUtils struct {
	Logger Logger
}

Implement the cron logger interface

func NewCronUtils

func NewCronUtils(l Logger) *CronUtils

func (*CronUtils) Error

func (c *CronUtils) Error(err error, msg string, keysAndValues ...interface{})

func (*CronUtils) Info

func (c *CronUtils) Info(msg string, keysAndValues ...interface{})

type DockerActor added in v1.7.0

type DockerActor struct {
	ID         string
	Attributes map[string]string
}

DockerActor represents the actor in a Docker event

type DockerClient added in v1.7.0

type DockerClient interface {
	// Container operations
	ListContainers(filters map[string][]string) ([]Container, error)
	InspectContainer(id string) (*Container, error)
	CreateContainer(config *ContainerConfig) (*Container, error)
	StartContainer(id string) error
	StopContainer(id string) error
	RemoveContainer(id string) error
	WaitContainer(id string) (int, error)

	// Exec operations
	CreateExec(containerID string, cmd []string, config *ExecConfig) (string, error)
	StartExec(execID string, attachStdout, attachStderr bool) (io.ReadCloser, error)
	InspectExec(execID string) (*ExecInspect, error)

	// Image operations
	PullImage(image string) error

	// Service operations
	CreateService(config *ServiceConfig) (string, error)
	InspectService(id string) (*Service, error)
	ListTasks(serviceID string) ([]Task, error)
	RemoveService(id string) error

	// Event operations
	WatchEvents(ctx context.Context, eventCh chan<- *DockerEvent, errCh chan<- error)

	// Job creation operations
	CreateExecJob() *OfficialExecJob
	CreateRunJob() *OfficialRunJob
	CreateServiceJob() *OfficialServiceJob
	CreateLifecycleJob() *OfficialLifecycleJob

	// Cleanup
	Close() error
}

DockerClient is an interface for Docker client operations

func NewDockerClient added in v1.7.0

func NewDockerClient() (DockerClient, error)

NewDockerClient creates a new Docker client using the official Docker client

type DockerEvent added in v1.7.0

type DockerEvent struct {
	Action     string
	ID         string
	Type       string
	Actor      DockerActor
	Attributes map[string]string
}

DockerEvent represents a Docker event

type ExecConfig added in v1.7.0

type ExecConfig struct {
	User         string
	Tty          bool
	AttachStdin  bool
	AttachStdout bool
	AttachStderr bool
	Cmd          []string
	WorkingDir   string
}

ExecConfig represents configuration for creating an exec instance

type ExecInspect added in v1.7.0

type ExecInspect struct {
	ID       string
	Running  bool
	ExitCode int
}

ExecInspect represents the result of inspecting an exec instance

type ExecJob

type ExecJob struct {
	BareJob   `mapstructure:",squash"`
	Client    DockerClient `json:"-"`
	Container string       `hash:"true"`
	User      string       `default:"root" hash:"true"`
	TTY       bool         `default:"false" hash:"true"`
	Workdir   string       `default:"" hash:"true"`
	// ContainerName is used for variable processing and is not included in the hash
	ContainerName string `hash:"-"`
}

ExecJob represents a job that executes a command in a running Docker container

func NewExecJob

func NewExecJob(c DockerClient) *ExecJob

NewExecJob creates a new ExecJob

func (*ExecJob) Hash

func (j *ExecJob) Hash() string

Returns a hash of all the job attributes. Used to detect changes

func (*ExecJob) Middlewares

func (c *ExecJob) Middlewares() []Middleware

func (*ExecJob) Run

func (j *ExecJob) Run(ctx *Context) error

func (*ExecJob) Use

func (c *ExecJob) Use(ms ...Middleware)

type Execution

type Execution struct {
	ID           string
	Date         time.Time
	OutputStream *circbuf.Buffer
	ErrorStream  *circbuf.Buffer
	// contains filtered or unexported fields
}

Execution contains all the information relative to a Job execution.

func NewExecution

func NewExecution() *Execution

func (*Execution) Duration

func (e *Execution) Duration() time.Duration

func (*Execution) Error

func (e *Execution) Error() error

func (*Execution) Failed

func (e *Execution) Failed() bool

func (*Execution) IsRunning

func (e *Execution) IsRunning() bool

IsRunning returns true if the execution is running

func (*Execution) Skipped

func (e *Execution) Skipped() bool

func (*Execution) Start

func (e *Execution) Start()

func (*Execution) Stop

func (e *Execution) Stop(err error)

type HostConfig added in v1.7.0

type HostConfig struct {
	Binds       []string
	NetworkMode string
}

HostConfig represents the container's host configuration

type Job

type Job interface {
	GetName() string
	GetSchedule() string
	GetCommand() string
	GetProcessedCommand(VariableContext) string
	Middlewares() []Middleware
	Use(...Middleware)
	Run(*Context) error
	Running() int32
	NotifyStart()
	NotifyStop()
	GetCronJobID() int
	SetCronJobID(int)
	SetVolumeMounts([]string)
}

type LifecycleEventType added in v1.6.0

type LifecycleEventType string

LifecycleEventType represents the type of container lifecycle event

const (
	// ContainerStart represents a container start event
	ContainerStart LifecycleEventType = "start"
	// ContainerStop represents a container stop event
	ContainerStop LifecycleEventType = "stop"
)

type LifecycleJob added in v1.6.0

type LifecycleJob struct {
	BareJob   `mapstructure:",squash"`
	Client    DockerClient       `json:"-"`
	Container string             `hash:"true"` // Container ID or name to monitor
	EventType LifecycleEventType `hash:"true"` // Type of event to trigger on (start, stop)
	Executed  bool               `hash:"-"`    // Whether this job has been executed
}

LifecycleJob represents a job that runs once on container lifecycle events

func NewLifecycleJob added in v1.6.0

func NewLifecycleJob(c DockerClient) *LifecycleJob

NewLifecycleJob creates a new LifecycleJob

func (*LifecycleJob) Hash added in v1.6.0

func (j *LifecycleJob) Hash() string

Returns a hash of all the job attributes. Used to detect changes

func (*LifecycleJob) Middlewares added in v1.6.0

func (c *LifecycleJob) Middlewares() []Middleware

func (*LifecycleJob) Reset added in v1.6.0

func (j *LifecycleJob) Reset()

Reset resets the executed state of the job

func (*LifecycleJob) Run added in v1.6.0

func (j *LifecycleJob) Run(ctx *Context) error

Run executes the job

func (*LifecycleJob) SetVolumeMounts added in v1.6.0

func (j *LifecycleJob) SetVolumeMounts(volumes []string)

SetVolumeMounts is a no-op for LifecycleJob

func (*LifecycleJob) ShouldRun added in v1.6.0

func (j *LifecycleJob) ShouldRun(eventType LifecycleEventType) bool

ShouldRun determines if the job should run based on the event type

func (*LifecycleJob) Use added in v1.6.0

func (c *LifecycleJob) Use(ms ...Middleware)

type LocalJob

type LocalJob struct {
	BareJob     `mapstructure:",squash"`
	Dir         string
	Environment []string
	// Variables for command processing
	ContainerName string `hash:"-"`
	ContainerID   string `hash:"-"`
}

func NewLocalJob

func NewLocalJob() *LocalJob

func (*LocalJob) Hash added in v1.0.9

func (j *LocalJob) Hash() string

Returns a hash of all the job attributes. Used to detect changes

func (*LocalJob) Middlewares

func (c *LocalJob) Middlewares() []Middleware

func (*LocalJob) Run

func (j *LocalJob) Run(ctx *Context) error

func (*LocalJob) Use

func (c *LocalJob) Use(ms ...Middleware)

type Logger

type Logger interface {
	Criticalf(format string, args ...interface{})
	Debugf(format string, args ...interface{})
	Errorf(format string, args ...interface{})
	Noticef(format string, args ...interface{})
	Warningf(format string, args ...interface{})
}

type Middleware

type Middleware interface {
	// Run is called instead of the original `Job.Run`, you MUST call to `ctx.Run`
	// inside of the middleware `Run` function otherwise you will broken the
	// Job workflow.
	Run(*Context) error
	// ContinueOnStop,  If return true the Run function will be called even if
	// the execution is stopped
	ContinueOnStop() bool
}

Middleware can wrap any job execution, allowing to execution code before or/and after of each `Job.Run`

type MockDockerClient added in v1.7.0

type MockDockerClient struct {
}

MockDockerClient is a mock implementation of the DockerClient interface for testing

func (*MockDockerClient) Close added in v1.7.0

func (c *MockDockerClient) Close() error

Close closes the Docker client

func (*MockDockerClient) CreateContainer added in v1.7.0

func (c *MockDockerClient) CreateContainer(config *ContainerConfig) (*Container, error)

CreateContainer creates a new container

func (*MockDockerClient) CreateExec added in v1.7.0

func (c *MockDockerClient) CreateExec(containerID string, cmd []string, config *ExecConfig) (string, error)

CreateExec creates an exec instance in a container

func (*MockDockerClient) CreateExecJob added in v1.7.0

func (c *MockDockerClient) CreateExecJob() *OfficialExecJob

CreateExecJob creates a new ExecJob

func (*MockDockerClient) CreateLifecycleJob added in v1.7.0

func (c *MockDockerClient) CreateLifecycleJob() *OfficialLifecycleJob

CreateLifecycleJob creates a new LifecycleJob

func (*MockDockerClient) CreateRunJob added in v1.7.0

func (c *MockDockerClient) CreateRunJob() *OfficialRunJob

CreateRunJob creates a new RunJob

func (*MockDockerClient) CreateService added in v1.7.0

func (c *MockDockerClient) CreateService(config *ServiceConfig) (string, error)

CreateService creates a new service

func (*MockDockerClient) CreateServiceJob added in v1.7.0

func (c *MockDockerClient) CreateServiceJob() *OfficialServiceJob

CreateServiceJob creates a new ServiceJob

func (*MockDockerClient) InspectContainer added in v1.7.0

func (c *MockDockerClient) InspectContainer(id string) (*Container, error)

InspectContainer inspects a container by ID

func (*MockDockerClient) InspectExec added in v1.7.0

func (c *MockDockerClient) InspectExec(execID string) (*ExecInspect, error)

InspectExec inspects an exec instance

func (*MockDockerClient) InspectService added in v1.7.0

func (c *MockDockerClient) InspectService(id string) (*Service, error)

InspectService inspects a service

func (*MockDockerClient) ListContainers added in v1.7.0

func (c *MockDockerClient) ListContainers(filterMap map[string][]string) ([]Container, error)

ListContainers lists containers with the given filters

func (*MockDockerClient) ListTasks added in v1.7.0

func (c *MockDockerClient) ListTasks(serviceID string) ([]Task, error)

ListTasks lists tasks for a service

func (*MockDockerClient) PullImage added in v1.7.0

func (c *MockDockerClient) PullImage(imageName string) error

PullImage pulls an image from a registry

func (*MockDockerClient) RemoveContainer added in v1.7.0

func (c *MockDockerClient) RemoveContainer(id string) error

RemoveContainer removes a container

func (*MockDockerClient) RemoveService added in v1.7.0

func (c *MockDockerClient) RemoveService(id string) error

RemoveService removes a service

func (*MockDockerClient) StartContainer added in v1.7.0

func (c *MockDockerClient) StartContainer(id string) error

StartContainer starts a container

func (*MockDockerClient) StartExec added in v1.7.0

func (c *MockDockerClient) StartExec(execID string, attachStdout, attachStderr bool) (io.ReadCloser, error)

StartExec starts an exec instance

func (*MockDockerClient) StopContainer added in v1.7.0

func (c *MockDockerClient) StopContainer(id string) error

StopContainer stops a container

func (*MockDockerClient) WaitContainer added in v1.7.0

func (c *MockDockerClient) WaitContainer(id string) (int, error)

WaitContainer waits for a container to exit and returns its exit code

func (*MockDockerClient) WatchEvents added in v1.7.0

func (c *MockDockerClient) WatchEvents(ctx context.Context, eventCh chan<- *DockerEvent, errCh chan<- error)

WatchEvents watches Docker events and sends them to the provided channel

type OfficialDockerClient added in v1.7.0

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

OfficialDockerClient implements DockerClient using the official Docker client

func (*OfficialDockerClient) Close added in v1.7.0

func (c *OfficialDockerClient) Close() error

Close closes the Docker client

func (*OfficialDockerClient) CreateContainer added in v1.7.0

func (c *OfficialDockerClient) CreateContainer(config *ContainerConfig) (*Container, error)

CreateContainer creates a new container

func (*OfficialDockerClient) CreateExec added in v1.7.0

func (c *OfficialDockerClient) CreateExec(containerID string, cmd []string, config *ExecConfig) (string, error)

CreateExec creates an exec instance in a container

func (*OfficialDockerClient) CreateExecJob added in v1.7.0

func (c *OfficialDockerClient) CreateExecJob() *OfficialExecJob

CreateExecJob creates a new OfficialExecJob

func (*OfficialDockerClient) CreateLifecycleJob added in v1.7.0

func (c *OfficialDockerClient) CreateLifecycleJob() *OfficialLifecycleJob

CreateLifecycleJob creates a new OfficialLifecycleJob

func (*OfficialDockerClient) CreateRunJob added in v1.7.0

func (c *OfficialDockerClient) CreateRunJob() *OfficialRunJob

CreateRunJob creates a new OfficialRunJob

func (*OfficialDockerClient) CreateService added in v1.7.0

func (c *OfficialDockerClient) CreateService(config *ServiceConfig) (string, error)

CreateService creates a new service

func (*OfficialDockerClient) CreateServiceJob added in v1.7.0

func (c *OfficialDockerClient) CreateServiceJob() *OfficialServiceJob

CreateServiceJob creates a new OfficialServiceJob

func (*OfficialDockerClient) InspectContainer added in v1.7.0

func (c *OfficialDockerClient) InspectContainer(id string) (*Container, error)

InspectContainer inspects a container by ID

func (*OfficialDockerClient) InspectExec added in v1.7.0

func (c *OfficialDockerClient) InspectExec(execID string) (*ExecInspect, error)

InspectExec inspects an exec instance

func (*OfficialDockerClient) InspectService added in v1.7.0

func (c *OfficialDockerClient) InspectService(id string) (*Service, error)

InspectService inspects a service

func (*OfficialDockerClient) ListContainers added in v1.7.0

func (c *OfficialDockerClient) ListContainers(filterMap map[string][]string) ([]Container, error)

ListContainers lists containers with the given filters

func (*OfficialDockerClient) ListTasks added in v1.7.0

func (c *OfficialDockerClient) ListTasks(serviceID string) ([]Task, error)

ListTasks lists tasks for a service

func (*OfficialDockerClient) PullImage added in v1.7.0

func (c *OfficialDockerClient) PullImage(imageName string) error

PullImage pulls an image from a registry

func (*OfficialDockerClient) RemoveContainer added in v1.7.0

func (c *OfficialDockerClient) RemoveContainer(id string) error

RemoveContainer removes a container

func (*OfficialDockerClient) RemoveService added in v1.7.0

func (c *OfficialDockerClient) RemoveService(id string) error

RemoveService removes a service

func (*OfficialDockerClient) StartContainer added in v1.7.0

func (c *OfficialDockerClient) StartContainer(id string) error

StartContainer starts a container

func (*OfficialDockerClient) StartExec added in v1.7.0

func (c *OfficialDockerClient) StartExec(execID string, attachStdout, attachStderr bool) (io.ReadCloser, error)

StartExec starts an exec instance

func (*OfficialDockerClient) StopContainer added in v1.7.0

func (c *OfficialDockerClient) StopContainer(id string) error

StopContainer stops a container

func (*OfficialDockerClient) WaitContainer added in v1.7.0

func (c *OfficialDockerClient) WaitContainer(id string) (int, error)

WaitContainer waits for a container to exit and returns its exit code

func (*OfficialDockerClient) WatchEvents added in v1.7.0

func (c *OfficialDockerClient) WatchEvents(ctx context.Context, eventCh chan<- *DockerEvent, errCh chan<- error)

WatchEvents watches Docker events and sends them to the provided channel

type OfficialExecJob added in v1.7.0

type OfficialExecJob struct {
	BareJob   `mapstructure:",squash"`
	Client    DockerClient `json:"-"`
	Container string       `hash:"true"`
	User      string       `default:"root" hash:"true"`
	TTY       bool         `default:"false" hash:"true"`
}

OfficialExecJob is an adapter for ExecJob that uses the DockerClient interface

func NewOfficialExecJob added in v1.7.0

func NewOfficialExecJob(c DockerClient) *OfficialExecJob

NewOfficialExecJob creates a new OfficialExecJob

func (*OfficialExecJob) Hash added in v1.7.0

func (j *OfficialExecJob) Hash() string

Hash returns a hash of all the job attributes

func (*OfficialExecJob) Middlewares added in v1.7.0

func (c *OfficialExecJob) Middlewares() []Middleware

func (*OfficialExecJob) Run added in v1.7.0

func (j *OfficialExecJob) Run(ctx *Context) error

Run executes the job

func (*OfficialExecJob) Use added in v1.7.0

func (c *OfficialExecJob) Use(ms ...Middleware)

type OfficialLifecycleJob added in v1.7.0

type OfficialLifecycleJob struct {
	BareJob   `mapstructure:",squash"`
	Client    DockerClient       `json:"-"`
	Container string             `hash:"true"`
	User      string             `default:"root" hash:"true"`
	TTY       bool               `default:"false" hash:"true"`
	EventType LifecycleEventType `hash:"true"`
	Executed  bool               `hash:"-"`
}

OfficialLifecycleJob is an adapter for LifecycleJob that uses the DockerClient interface

func NewOfficialLifecycleJob added in v1.7.0

func NewOfficialLifecycleJob(c DockerClient) *OfficialLifecycleJob

NewOfficialLifecycleJob creates a new OfficialLifecycleJob

func (*OfficialLifecycleJob) Hash added in v1.7.0

func (j *OfficialLifecycleJob) Hash() string

Hash returns a hash of all the job attributes

func (*OfficialLifecycleJob) Middlewares added in v1.7.0

func (c *OfficialLifecycleJob) Middlewares() []Middleware

func (*OfficialLifecycleJob) Run added in v1.7.0

func (j *OfficialLifecycleJob) Run(ctx *Context) error

Run executes the job

func (*OfficialLifecycleJob) Use added in v1.7.0

func (c *OfficialLifecycleJob) Use(ms ...Middleware)

type OfficialRunJob added in v1.7.0

type OfficialRunJob struct {
	BareJob     `mapstructure:",squash"`
	Client      DockerClient `json:"-"`
	Image       string       `hash:"true"`
	Network     string       `default:"bridge" hash:"true"`
	Pull        string       `default:"missing" hash:"true"`
	User        string       `default:"root" hash:"true"`
	TTY         bool         `default:"false" hash:"true"`
	Environment []string     `hash:"true"`
	Volumes     []string     `hash:"true"`
	WorkingDir  string       `hash:"true"`
}

OfficialRunJob is an adapter for RunJob that uses the DockerClient interface

func NewOfficialRunJob added in v1.7.0

func NewOfficialRunJob(c DockerClient) *OfficialRunJob

NewOfficialRunJob creates a new OfficialRunJob

func (*OfficialRunJob) Hash added in v1.7.0

func (j *OfficialRunJob) Hash() string

Hash returns a hash of all the job attributes

func (*OfficialRunJob) Middlewares added in v1.7.0

func (c *OfficialRunJob) Middlewares() []Middleware

func (*OfficialRunJob) Run added in v1.7.0

func (j *OfficialRunJob) Run(ctx *Context) error

Run executes the job

func (*OfficialRunJob) Use added in v1.7.0

func (c *OfficialRunJob) Use(ms ...Middleware)

type OfficialServiceJob added in v1.7.0

type OfficialServiceJob struct {
	BareJob   `mapstructure:",squash"`
	Client    DockerClient `json:"-"`
	Container string       `hash:"true"`
	User      string       `default:"root" hash:"true"`
	TTY       bool         `default:"false" hash:"true"`
}

OfficialServiceJob is an adapter for ServiceJob that uses the DockerClient interface

func NewOfficialServiceJob added in v1.7.0

func NewOfficialServiceJob(c DockerClient) *OfficialServiceJob

NewOfficialServiceJob creates a new OfficialServiceJob

func (*OfficialServiceJob) GetProcessedCommand added in v1.7.0

func (j *OfficialServiceJob) GetProcessedCommand(varContext VariableContext) string

GetProcessedCommand returns the processed command with variables replaced

func (*OfficialServiceJob) Hash added in v1.7.0

func (j *OfficialServiceJob) Hash() string

Hash returns a hash of all the job attributes

func (*OfficialServiceJob) Middlewares added in v1.7.0

func (c *OfficialServiceJob) Middlewares() []Middleware

func (*OfficialServiceJob) Run added in v1.7.0

func (j *OfficialServiceJob) Run(ctx *Context) error

Run executes the job

func (*OfficialServiceJob) Use added in v1.7.0

func (c *OfficialServiceJob) Use(ms ...Middleware)

type ReadCloserWrapper added in v1.7.0

type ReadCloserWrapper struct {
	*bufio.Reader
	// contains filtered or unexported fields
}

ReadCloserWrapper wraps a bufio.Reader to implement io.ReadCloser

func (*ReadCloserWrapper) Close added in v1.7.0

func (r *ReadCloserWrapper) Close() error

Close calls the stored closer function

type RestartPolicy added in v1.7.0

type RestartPolicy struct {
	Condition   string
	Delay       time.Duration
	MaxAttempts int
}

RestartPolicy represents the restart policy for a service

type RunJob

type RunJob struct {
	BareJob   `mapstructure:",squash"`
	Client    DockerClient `json:"-"`
	Container string       `hash:"true"`
	Image     string       `hash:"true"`
	User      string       `default:"root" hash:"true"`
	TTY       bool         `default:"false" hash:"true"`
	Delete    bool         `default:"true" hash:"true"`
	Network   string       `hash:"true"`
	Volume    []string     `hash:"true"`
}

RunJob represents a job that runs a command in a Docker container

func NewRunJob

func NewRunJob(c DockerClient) *RunJob

NewRunJob creates a new RunJob

func (*RunJob) Hash added in v1.5.0

func (j *RunJob) Hash() string

Returns a hash of all the job attributes. Used to detect changes

func (*RunJob) Middlewares

func (c *RunJob) Middlewares() []Middleware

func (*RunJob) Run

func (j *RunJob) Run(ctx *Context) error

func (*RunJob) Use

func (c *RunJob) Use(ms ...Middleware)

type RunServiceJob

type RunServiceJob struct {
	BareJob `mapstructure:",squash"`
	Client  DockerClient `json:"-"`
	User    string       `default:"root"`
	TTY     bool         `default:"false"`
	// do not use bool values with "default:true" because if
	// user would set it to "false" explicitly, it still will be
	// changed to "true" https://github.com/mcuadros/ofelia/issues/135
	// so lets use strings here as workaround
	Delete  string `default:"true"`
	Image   string
	Network string
}

RunServiceJob represents a job that runs a Docker service

func NewRunServiceJob

func NewRunServiceJob(c DockerClient) *RunServiceJob

NewRunServiceJob creates a new RunServiceJob

func (*RunServiceJob) Middlewares

func (c *RunServiceJob) Middlewares() []Middleware

func (*RunServiceJob) Run

func (j *RunServiceJob) Run(ctx *Context) error

func (*RunServiceJob) Use

func (c *RunServiceJob) Use(ms ...Middleware)

type Scheduler

type Scheduler struct {
	Jobs   []Job
	Logger Logger
	// contains filtered or unexported fields
}

func NewScheduler

func NewScheduler(l Logger) *Scheduler

func (*Scheduler) AddJob

func (s *Scheduler) AddJob(j Job) error

func (*Scheduler) IsRunning

func (s *Scheduler) IsRunning() bool

func (*Scheduler) Middlewares

func (c *Scheduler) Middlewares() []Middleware

func (*Scheduler) RemoveJob

func (s *Scheduler) RemoveJob(j Job) error

func (*Scheduler) Start

func (s *Scheduler) Start() error

func (*Scheduler) Stop

func (s *Scheduler) Stop() error

func (*Scheduler) Use

func (c *Scheduler) Use(ms ...Middleware)

type Service added in v1.7.0

type Service struct {
	ID          string
	Name        string
	CreatedAt   time.Time
	UpdatedAt   time.Time
	Spec        ServiceConfig
	Endpoint    ServiceEndpoint
	UpdateState ServiceUpdateState
}

Service represents a Docker service

type ServiceConfig added in v1.7.0

type ServiceConfig struct {
	Name          string
	Image         string
	Cmd           []string
	Env           []string
	Labels        map[string]string
	RestartPolicy *RestartPolicy
	Networks      []string
	Mounts        []ServiceMount
}

ServiceConfig represents configuration for creating a service

type ServiceEndpoint added in v1.7.0

type ServiceEndpoint struct {
	Ports []ServicePort
}

ServiceEndpoint represents the endpoint of a service

type ServiceJob added in v1.5.0

type ServiceJob struct {
	BareJob   `mapstructure:",squash"`
	Container string       `hash:"true"`
	Client    DockerClient `json:"-"`
	TTY       bool         `default:"false" hash:"true"`
	User      string       `default:"root" hash:"true"`
}

ServiceJob represents a job that runs a command in a Docker container as a service

func NewServiceJob added in v1.5.0

func NewServiceJob(c DockerClient) *ServiceJob

NewServiceJob creates a new ServiceJob

func (*ServiceJob) GetProcessedCommand added in v1.5.0

func (j *ServiceJob) GetProcessedCommand(varContext VariableContext) string

func (*ServiceJob) Middlewares added in v1.5.0

func (c *ServiceJob) Middlewares() []Middleware

func (*ServiceJob) Run added in v1.5.0

func (j *ServiceJob) Run(ctx *Context) error

func (*ServiceJob) Use added in v1.5.0

func (c *ServiceJob) Use(ms ...Middleware)

type ServiceMount added in v1.7.0

type ServiceMount struct {
	Source string
	Target string
	Type   string
}

ServiceMount represents a mount for a service

type ServicePort added in v1.7.0

type ServicePort struct {
	Protocol      string
	TargetPort    uint32
	PublishedPort uint32
}

ServicePort represents a port of a service

type ServiceUpdateState added in v1.7.0

type ServiceUpdateState struct {
	State     string
	Message   string
	StartedAt time.Time
}

ServiceUpdateState represents the update state of a service

type Task added in v1.7.0

type Task struct {
	ID           string
	ServiceID    string
	NodeID       string
	Status       TaskStatus
	DesiredState string
	CreatedAt    time.Time
	UpdatedAt    time.Time
}

Task represents a Docker task

type TaskStatus added in v1.7.0

type TaskStatus struct {
	Timestamp time.Time
	State     string
	Message   string
	Err       string
}

TaskStatus represents the status of a task

type VariableContext added in v1.5.0

type VariableContext struct {
	Container ContainerInfo
}

VariableContext holds all the variables that can be used in replacements

Jump to

Keyboard shortcuts

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