mconfig

package
v3.0.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func EverythingToSnakeCase(s string) string

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

type ContainerAllocation struct {
	Name  string `json:"name"`
	Ports []uint `json:"ports"`
}

All things required to create a service container

type ContainerInformation

type ContainerInformation struct {
	ID    string `json:"id"`
	Name  string `json:"name"`
	Ports []uint `json:"ports"`
}

type Context

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

func DefaultContext

func DefaultContext(appName string, profile string, projectDir string) *Context

func (*Context) AppName

func (c *Context) AppName() string

The app name you set in your config.

func (*Context) Environment

func (c *Context) Environment() *Environment

func (*Context) LoadSecretsToEnvironment

func (c *Context) LoadSecretsToEnvironment(path string) error

Note: In case you use a relative path, expect it to start in the Magic directory.

func (*Context) Plan

func (c *Context) Plan() *Plan

Plan for later (DO NOT EXPECT THIS TO BE FILLED BEFORE DEPLOYMENT STEP)

func (*Context) Ports

func (c *Context) Ports() []uint

func (*Context) Profile

func (c *Context) Profile() string

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 (c *Context) ProjectDirectory() string

func (*Context) Register

func (c *Context) Register(driver ServiceDriver) ServiceDriver

Register a service driver for a service

func (*Context) Services

func (c *Context) Services() []ServiceDriver

Get all services requested.

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

func FromPrintable(printable string) (*Plan, error)

Convert back to a plan from printable form

func (*Plan) ToPrintable

func (p *Plan) ToPrintable() (string, error)

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)

Jump to

Keyboard shortcuts

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