2019-09-24 20:32:35 +03:00
|
|
|
package runtime
|
|
|
|
|
2019-09-24 21:00:11 +03:00
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
)
|
|
|
|
|
2019-11-02 16:25:10 +03:00
|
|
|
type Option func(o *Options)
|
|
|
|
|
|
|
|
// Options configure runtime
|
|
|
|
type Options struct {
|
2020-01-16 16:34:04 +03:00
|
|
|
// Scheduler for updates
|
|
|
|
Scheduler Scheduler
|
2019-11-29 14:35:00 +03:00
|
|
|
// Service type to manage
|
|
|
|
Type string
|
2020-02-05 16:59:35 +03:00
|
|
|
// Source of the services repository
|
|
|
|
Source string
|
|
|
|
}
|
|
|
|
|
2020-02-06 11:52:25 +03:00
|
|
|
// WithSource sets the base image / repository
|
2020-02-05 16:59:35 +03:00
|
|
|
func WithSource(src string) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Source = src
|
|
|
|
}
|
2019-11-02 16:25:10 +03:00
|
|
|
}
|
|
|
|
|
2020-01-16 16:34:04 +03:00
|
|
|
// WithScheduler specifies a scheduler for updates
|
|
|
|
func WithScheduler(n Scheduler) Option {
|
2019-11-02 16:25:10 +03:00
|
|
|
return func(o *Options) {
|
2020-01-16 16:34:04 +03:00
|
|
|
o.Scheduler = n
|
2019-11-02 16:25:10 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-29 14:35:00 +03:00
|
|
|
// WithType sets the service type to manage
|
|
|
|
func WithType(t string) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Type = t
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-24 20:32:35 +03:00
|
|
|
type CreateOption func(o *CreateOptions)
|
|
|
|
|
2019-11-29 14:35:00 +03:00
|
|
|
type ReadOption func(o *ReadOptions)
|
|
|
|
|
2019-11-02 16:25:10 +03:00
|
|
|
// CreateOptions configure runtime services
|
2019-09-24 20:32:35 +03:00
|
|
|
type CreateOptions struct {
|
|
|
|
// command to execute including args
|
|
|
|
Command []string
|
|
|
|
// Environment to configure
|
|
|
|
Env []string
|
2019-09-24 21:00:11 +03:00
|
|
|
// Log output
|
|
|
|
Output io.Writer
|
2019-11-29 14:35:00 +03:00
|
|
|
// Type of service to create
|
|
|
|
Type string
|
2020-02-07 15:02:41 +03:00
|
|
|
// Retries before failing deploy
|
|
|
|
Retries int
|
2020-02-24 20:47:47 +03:00
|
|
|
// Source of the service
|
|
|
|
Source string
|
2019-11-29 14:35:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// ReadOptions queries runtime services
|
|
|
|
type ReadOptions struct {
|
|
|
|
// Service name
|
|
|
|
Service string
|
|
|
|
// Version queries services with given version
|
|
|
|
Version string
|
|
|
|
// Type of service
|
|
|
|
Type string
|
2019-09-24 20:32:35 +03:00
|
|
|
}
|
|
|
|
|
2020-01-17 17:14:47 +03:00
|
|
|
// CreateType sets the type of service to create
|
|
|
|
func CreateType(t string) CreateOption {
|
|
|
|
return func(o *CreateOptions) {
|
|
|
|
o.Type = t
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-24 20:47:47 +03:00
|
|
|
// CreateSource sets the source of service to create
|
|
|
|
func CreateSource(t string) CreateOption {
|
|
|
|
return func(o *CreateOptions) {
|
|
|
|
o.Source = t
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-24 21:00:11 +03:00
|
|
|
// WithCommand specifies the command to execute
|
2019-11-29 14:55:25 +03:00
|
|
|
func WithCommand(args ...string) CreateOption {
|
2019-09-24 20:32:35 +03:00
|
|
|
return func(o *CreateOptions) {
|
|
|
|
// set command
|
2019-11-29 14:55:25 +03:00
|
|
|
o.Command = args
|
2019-09-24 20:32:35 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-07 15:02:41 +03:00
|
|
|
// WithRetries sets the max retries attemps
|
|
|
|
func WithRetries(retries int) CreateOption {
|
|
|
|
return func(o *CreateOptions) {
|
|
|
|
o.Retries = retries
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-02 16:25:10 +03:00
|
|
|
// WithEnv sets the created service environment
|
2019-09-24 20:32:35 +03:00
|
|
|
func WithEnv(env []string) CreateOption {
|
|
|
|
return func(o *CreateOptions) {
|
|
|
|
o.Env = env
|
|
|
|
}
|
|
|
|
}
|
2019-09-24 21:00:11 +03:00
|
|
|
|
|
|
|
// WithOutput sets the arg output
|
|
|
|
func WithOutput(out io.Writer) CreateOption {
|
|
|
|
return func(o *CreateOptions) {
|
|
|
|
o.Output = out
|
|
|
|
}
|
|
|
|
}
|
2019-11-15 16:41:40 +03:00
|
|
|
|
2019-11-29 14:35:00 +03:00
|
|
|
// ReadService returns services with the given name
|
|
|
|
func ReadService(service string) ReadOption {
|
|
|
|
return func(o *ReadOptions) {
|
|
|
|
o.Service = service
|
|
|
|
}
|
2019-11-15 16:41:40 +03:00
|
|
|
}
|
|
|
|
|
2020-02-07 15:02:41 +03:00
|
|
|
// ReadVersion confifgures service version
|
2019-11-29 14:35:00 +03:00
|
|
|
func ReadVersion(version string) ReadOption {
|
2019-11-25 19:31:14 +03:00
|
|
|
return func(o *ReadOptions) {
|
2019-11-15 16:41:40 +03:00
|
|
|
o.Version = version
|
|
|
|
}
|
|
|
|
}
|
2019-11-29 14:35:00 +03:00
|
|
|
|
|
|
|
// ReadType returns services of the given type
|
|
|
|
func ReadType(t string) ReadOption {
|
|
|
|
return func(o *ReadOptions) {
|
|
|
|
o.Type = t
|
|
|
|
}
|
|
|
|
}
|