Documentation
¶
Index ¶
- Variables
- func ContainerName[S ServiceDriver](appName string, profile string, driver S) string
- func EverythingToSnakeCase(s string) string
- func PlannedContainerName[S ServiceDriver](plan *Plan, driver S) string
- func RegisterDriver(driver ServiceDriver)
- type ContainerAllocation
- type ContainerInformation
- type Context
- func (c *Context) AppName() string
- func (c *Context) Environment() *Environment
- func (c *Context) LoadSecretsToEnvironment(path string) error
- func (c *Context) Plan() *Plan
- func (c *Context) Ports() []uint
- func (c *Context) Profile() string
- func (c *Context) ProjectDirectory() string
- func (c *Context) Register(driver ServiceDriver) ServiceDriver
- func (c *Context) Services() []ServiceDriver
- func (c *Context) ValuePort(preferredPort uint) EnvironmentValue
- func (c *Context) WithEnvironment(env Environment)
- type Environment
- type EnvironmentValue
- type Instruction
- type Plan
- type ServiceDriver
Constants ¶
This section is empty.
Variables ¶
var VerboseLogging bool = false
If verbose logging is enabled
Functions ¶
func ContainerName ¶
func ContainerName[S ServiceDriver](appName string, profile string, driver S) string
Name for a service Docker container
func EverythingToSnakeCase ¶
Convert every character except for letters and digits directly to _
func PlannedContainerName ¶
func PlannedContainerName[S ServiceDriver](plan *Plan, driver S) string
Name for a service container (get by plan)
func RegisterDriver ¶
func RegisterDriver(driver ServiceDriver)
Register a service driver for instruction calling (THIS IS NOT THE DRIVER ACTUALLY USED TO CREATE YOUR DATABASES, DO NOT USE OUTSIDE OF MAGIC INTERNALLY)
Types ¶
type ContainerAllocation ¶
All things required to create a service container
type ContainerInformation ¶
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
func DefaultContext ¶
func (*Context) Environment ¶
func (c *Context) Environment() *Environment
func (*Context) LoadSecretsToEnvironment ¶
Note: In case you use a relative path, expect it to start in the Magic directory.
func (*Context) Profile ¶
The current profile.
test = Test profile. default = Default profile. You can set the profile by passing the --m-profile flag to the executable that includes magic.
func (*Context) ProjectDirectory ¶
func (*Context) Register ¶
func (c *Context) Register(driver ServiceDriver) ServiceDriver
Register a service driver for a service
func (*Context) ValuePort ¶
func (c *Context) ValuePort(preferredPort uint) EnvironmentValue
Allocate a new port for the container (and parse it as a environment variable).
func (*Context) WithEnvironment ¶
func (c *Context) WithEnvironment(env Environment)
Set the environment.
type Environment ¶
type Environment map[string]EnvironmentValue
func (*Environment) Generate ¶
func (e *Environment) Generate() map[string]string
Apply all the environment variables
type EnvironmentValue ¶
type EnvironmentValue struct {
// contains filtered or unexported fields
}
func ValueFunction ¶
func ValueFunction(get func() string) EnvironmentValue
func ValueStatic ¶
func ValueStatic(value string) EnvironmentValue
Create a new static environment value.
func ValueWithBase ¶
func ValueWithBase(values []EnvironmentValue, builder func([]string) string) EnvironmentValue
Create a new environment value based on other environment values.
The index in the values array matches the output of the environment value.
type Instruction ¶
type Instruction string
An instruction to do something with a container.
This is used by Magic to for example tell database providers to clear their databases.
const ( InstructionDropTables Instruction = "database:drop_tables" InstructionClearTables Instruction = "database:clear_tables" )
type Plan ¶
type Plan struct {
AppName string `json:"app_name"`
Profile string `json:"profile"`
Environment map[string]string `json:"environment"`
AllocatedPorts map[uint]uint `json:"ports"`
Containers map[string]ContainerAllocation `json:"containers"` // Service id -> Container allocation
Services map[string]string `json:"services"` // Service id -> Data
}
func FromPrintable ¶
Convert back to a plan from printable form
func (*Plan) ToPrintable ¶
Turn the plan into printable form
type ServiceDriver ¶
type ServiceDriver interface {
GetUniqueId() string
// Should return the amount of ports required to start the container.
GetRequiredPortAmount() int
// Should return the image. Magic will pull it automatically.
GetImage() string
// Create a new container for this type of service
CreateContainer(ctx context.Context, c *client.Client, a ContainerAllocation) (string, error)
// This method should check if the container with the id is healthy for this service
IsHealthy(ctx context.Context, c *client.Client, container ContainerInformation) (bool, error)
// Called to initialize the container when it is healthy
Initialize(ctx context.Context, c *client.Client, container ContainerInformation) error
// An instruction sent down from Magic to potentially do something with the container (not every service has to handle every instruction).
//
// When implementing, please look into the instructions you can support.
HandleInstruction(ctx context.Context, c *client.Client, container ContainerInformation, instruction Instruction) error
// For creating a new instance of the service driver with the loaded data
Load(data string) (ServiceDriver, error)
// Save the current data of the service driver into string form (will be persisted in the plan)
Save() (string, error)
}
A service driver is a manager for containers running a particular service image.
That can be databases or literally anything you could imagine. It provides a unified interface for Magic to be able to properly control those Docker containers.
func GetDriver ¶
func GetDriver(serviceId string) (ServiceDriver, bool)
Get a service driver by its unique id (THIS IS NOT THE DRIVER ACTUALLY USED TO CREATE YOUR DATABASES, DO NOT USE OUTSIDE OF MAGIC INTERNALLY)