appconfig

package
v0.1.107 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2023 License: Apache-2.0 Imports: 35 Imported by: 0

Documentation

Overview

Package appconfig implements functionality related to reading and writing app configuration files.

Index

Constants

View Source
const (
	// DefaultConfigFileName denotes the default application configuration file name.
	DefaultConfigFileName = "fly.toml"
	// Config is versioned, initially, to separate nomad from machine apps without having to consult
	// the API
	MachinesPlatform = "machines"
	NomadPlatform    = "nomad"
	DetachedPlatform = "detached"
)

Variables

View Source
var (
	ValidationError          = errors.New("invalid app configuration")
	MachinesDeployStrategies = []string{"canary", "rolling", "immediate", "bluegreen"}
)

Functions

func ConfigFileExistsAtPath

func ConfigFileExistsAtPath(p string) (bool, error)

func NameFromContext

func NameFromContext(ctx context.Context) string

NameFromContext returns the app name ctx carries or an empty string.

func ResolveConfigFileFromPath

func ResolveConfigFileFromPath(p string) (string, error)

func WithConfig

func WithConfig(ctx context.Context, cfg *Config) context.Context

WithConfig derives a context that carries cfg from ctx.

func WithName

func WithName(ctx context.Context, name string) context.Context

WithName derives a context that carries the given app name from ctx.

Types

type Build

type Build struct {
	Builder           string            `toml:"builder,omitempty" json:"builder,omitempty"`
	Args              map[string]string `toml:"args,omitempty" json:"args,omitempty"`
	Buildpacks        []string          `toml:"buildpacks,omitempty" json:"buildpacks,omitempty"`
	Image             string            `toml:"image,omitempty" json:"image,omitempty"`
	Settings          map[string]any    `toml:"settings,omitempty" json:"settings,omitempty"`
	Builtin           string            `toml:"builtin,omitempty" json:"builtin,omitempty"`
	Dockerfile        string            `toml:"dockerfile,omitempty" json:"dockerfile,omitempty"`
	Ignorefile        string            `toml:"ignorefile,omitempty" json:"ignorefile,omitempty"`
	DockerBuildTarget string            `toml:"build-target,omitempty" json:"build-target,omitempty"`
}

type Config

type Config struct {
	AppName        string        `toml:"app,omitempty" json:"app,omitempty"`
	PrimaryRegion  string        `toml:"primary_region,omitempty" json:"primary_region,omitempty"`
	KillSignal     *string       `toml:"kill_signal,omitempty" json:"kill_signal,omitempty"`
	KillTimeout    *api.Duration `toml:"kill_timeout,omitempty" json:"kill_timeout,omitempty"`
	SwapSizeMB     *int          `toml:"swap_size_mb,omitempty" json:"swap_size_mb,omitempty"`
	ConsoleCommand string        `toml:"console_command,omitempty" json:"console_command,omitempty"`

	// Sections that are typically short and benefit from being on top
	Experimental *Experimental     `toml:"experimental,omitempty" json:"experimental,omitempty"`
	Build        *Build            `toml:"build,omitempty" json:"build,omitempty"`
	Deploy       *Deploy           `toml:"deploy, omitempty" json:"deploy,omitempty"`
	Env          map[string]string `toml:"env,omitempty" json:"env,omitempty"`

	// Fields that are process group aware must come after Processes
	Processes        map[string]string         `toml:"processes,omitempty" json:"processes,omitempty"`
	Mounts           []Mount                   `toml:"mounts,omitempty" json:"mounts,omitempty"`
	HTTPService      *HTTPService              `toml:"http_service,omitempty" json:"http_service,omitempty"`
	Services         []Service                 `toml:"services,omitempty" json:"services,omitempty"`
	Checks           map[string]*ToplevelCheck `toml:"checks,omitempty" json:"checks,omitempty"`
	Files            []File                    `toml:"files,omitempty" json:"files,omitempty"`
	HostDedicationID string                    `toml:"host_dedication_id,omitempty" json:"host_dedication_id,omitempty"`
	// MergedFiles is a list of files that have been merged from the app config and flags.
	MergedFiles []*api.File `toml:"-" json:"-"`

	// Others, less important.
	Statics []Static   `toml:"statics,omitempty" json:"statics,omitempty"`
	Metrics []*Metrics `toml:"metrics,omitempty" json:"metrics,omitempty"`

	// RawDefinition contains fly.toml parsed as-is
	// If you add any config field that is v2 specific, be sure to remove it in SanitizeDefinition()
	RawDefinition map[string]any `toml:"-" json:"-"`
	// contains filtered or unexported fields
}

Config wraps the properties of app configuration. NOTE: If you any new setting here, please also add a value for it at testdata/rull-reference.toml

func ConfigFromContext

func ConfigFromContext(ctx context.Context) *Config

ConfigFromContext returns the Config ctx carries.

func FromAppAndMachineSet

func FromAppAndMachineSet(ctx context.Context, appCompact *api.AppCompact, machines machine.MachineSet) (*Config, string, error)

func FromAppCompact added in v0.1.40

func FromAppCompact(ctx context.Context, appCompact *api.AppCompact) (*Config, error)

func FromDefinition

func FromDefinition(definition *api.Definition) (*Config, error)

func FromRemoteApp added in v0.0.479

func FromRemoteApp(ctx context.Context, appName string) (*Config, error)

func LoadConfig

func LoadConfig(path string) (cfg *Config, err error)

LoadConfig loads the app config at the given path.

func NewConfig

func NewConfig() *Config

func (*Config) AllServices added in v0.0.514

func (c *Config) AllServices() (services []Service)

func (*Config) BuildStrategies added in v0.0.500

func (cfg *Config) BuildStrategies() []string

func (*Config) ConfigFilePath

func (c *Config) ConfigFilePath() string

func (*Config) DefaultProcessName added in v0.0.489

func (c *Config) DefaultProcessName() string

DefaultProcessName returns: * "app" when no processes are defined * "app" if present in the processes map * The first process name in ascending lexicographical order

func (*Config) DockerBuildTarget

func (c *Config) DockerBuildTarget() string

func (*Config) Dockerfile

func (c *Config) Dockerfile() string

func (*Config) EnsureV2Config

func (c *Config) EnsureV2Config() error

func (*Config) Flatten added in v0.0.514

func (c *Config) Flatten(groupName string) (*Config, error)

Flatten generates a machine config specific to a process_group.

Only services, mounts, checks, metrics & files specific to the provided progress group will be in the returned config.

func (*Config) ForMachines

func (c *Config) ForMachines() bool

ForMachines is true when the config is intended for the machines platform

func (*Config) FormatProcessNames added in v0.0.509

func (c *Config) FormatProcessNames() string

FormatProcessNames formats the process group list like `['foo', 'bar']`

func (*Config) HasNonHttpAndHttpsStandardServices

func (c *Config) HasNonHttpAndHttpsStandardServices() bool

func (*Config) HasUdpService

func (c *Config) HasUdpService() bool

func (*Config) Ignorefile

func (c *Config) Ignorefile() string

func (*Config) InitCmd added in v0.0.514

func (c *Config) InitCmd(groupName string) ([]string, error)

func (*Config) InternalPort added in v0.0.500

func (c *Config) InternalPort() int

func (*Config) MarshalJSON added in v0.0.508

func (c *Config) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface

func (*Config) MergeFiles added in v0.1.64

func (cfg *Config) MergeFiles(files []*api.File) error

MergeFiles merges the provided files with the files in the config wherein the provided files take precedence.

func (*Config) PlatformVersion added in v0.1.9

func (cfg *Config) PlatformVersion() string

func (*Config) ProcessNames added in v0.0.509

func (c *Config) ProcessNames() (names []string)

ProcessNames lists each key of c.Processes, sorted lexicographically If c.Processes == nil, returns ["app"]

func (*Config) SanitizedDefinition

func (c *Config) SanitizedDefinition() map[string]any

SanitizedDefinition returns a definition cleaned from any extra fields not valid for Web API GQL endpoints.

func (*Config) SetConcurrency

func (c *Config) SetConcurrency(soft int, hard int)

func (*Config) SetConfigFilePath added in v0.0.540

func (c *Config) SetConfigFilePath(configFilePath string)

func (*Config) SetDetachedPlatform added in v0.0.506

func (c *Config) SetDetachedPlatform() error

SetMachinesPlatform informs the TOML marshaller that this config is for the machines platform

func (*Config) SetDockerCommand

func (c *Config) SetDockerCommand(cmd string)

func (*Config) SetDockerEntrypoint

func (c *Config) SetDockerEntrypoint(entrypoint string)

func (*Config) SetEnvVariable

func (c *Config) SetEnvVariable(name, value string)

func (*Config) SetEnvVariables

func (c *Config) SetEnvVariables(vals map[string]string)

func (*Config) SetHttpCheck

func (c *Config) SetHttpCheck(path string, headers map[string]string)

func (*Config) SetInternalPort

func (c *Config) SetInternalPort(port int)

func (*Config) SetKillSignal

func (c *Config) SetKillSignal(signal string)

func (*Config) SetMachinesPlatform

func (c *Config) SetMachinesPlatform() error

SetMachinesPlatform informs the TOML marshaller that this config is for the machines platform

func (*Config) SetMounts added in v0.0.522

func (c *Config) SetMounts(volumes []Mount)

func (*Config) SetNomadPlatform

func (c *Config) SetNomadPlatform() error

SetNomadPlatform informs the TOML marshaller that this config is for the nomad platform

func (*Config) SetPlatformVersion

func (c *Config) SetPlatformVersion(platform string) error

func (*Config) SetProcess

func (c *Config) SetProcess(name, value string)

func (*Config) SetReleaseCommand

func (c *Config) SetReleaseCommand(cmd string)

func (*Config) SetStatics

func (c *Config) SetStatics(statics []Static)

func (*Config) ToConsoleMachineConfig added in v0.0.557

func (c *Config) ToConsoleMachineConfig() (*api.MachineConfig, error)

func (*Config) ToDefinition

func (c *Config) ToDefinition() (*api.Definition, error)

func (*Config) ToMachineConfig added in v0.0.510

func (c *Config) ToMachineConfig(processGroup string, src *api.MachineConfig) (*api.MachineConfig, error)

func (*Config) ToReleaseMachineConfig added in v0.0.510

func (c *Config) ToReleaseMachineConfig() (*api.MachineConfig, error)

func (*Config) URL added in v0.0.533

func (cfg *Config) URL() *url.URL

func (*Config) Validate

func (cfg *Config) Validate(ctx context.Context) (err error, extra_info string)

func (*Config) ValidateForMachinesPlatform added in v0.0.500

func (cfg *Config) ValidateForMachinesPlatform(ctx context.Context) (err error, extra_info string)

func (*Config) ValidateForNomadPlatform added in v0.0.500

func (cfg *Config) ValidateForNomadPlatform(ctx context.Context) (err error, extra_info string)

func (*Config) WriteTo added in v0.0.508

func (c *Config) WriteTo(w io.Writer) error

func (*Config) WriteToDisk

func (c *Config) WriteToDisk(ctx context.Context, path string) (err error)

func (*Config) WriteToFile

func (c *Config) WriteToFile(filename string) (err error)

type Deploy

type Deploy struct {
	ReleaseCommand string `toml:"release_command,omitempty" json:"release_command,omitempty"`
	Strategy       string `toml:"strategy,omitempty" json:"strategy,omitempty"`
}

type Experimental

type Experimental struct {
	Cmd          []string `toml:"cmd,omitempty" json:"cmd,omitempty"`
	Entrypoint   []string `toml:"entrypoint,omitempty" json:"entrypoint,omitempty"`
	Exec         []string `toml:"exec,omitempty" json:"exec,omitempty"`
	AutoRollback bool     `toml:"auto_rollback,omitempty" json:"auto_rollback,omitempty"`
	EnableConsul bool     `toml:"enable_consul,omitempty" json:"enable_consul,omitempty"`
	EnableEtcd   bool     `toml:"enable_etcd,omitempty" json:"enable_etcd,omitempty"`
}

type File added in v0.1.64

type File struct {
	GuestPath  string   `toml:"guest_path" json:"guest_path,omitempty" validate:"required"`
	LocalPath  string   `toml:"local_path" json:"local_path,omitempty"`
	SecretName string   `toml:"secret_name" json:"secret_name,omitempty"`
	RawValue   string   `toml:"raw_value" json:"raw_value,omitempty"`
	Processes  []string `json:"processes,omitempty" toml:"processes,omitempty"`
}

type HTTPService

type HTTPService struct {
	InternalPort int  `json:"internal_port,omitempty" toml:"internal_port,omitempty" validate:"required,numeric"`
	ForceHTTPS   bool `toml:"force_https,omitempty" json:"force_https,omitempty"`
	// AutoStopMachines and AutoStartMachines should not have omitempty for TOML; see the note in Service.
	AutoStopMachines   *bool                          `json:"auto_stop_machines,omitempty" toml:"auto_stop_machines"`
	AutoStartMachines  *bool                          `json:"auto_start_machines,omitempty" toml:"auto_start_machines"`
	MinMachinesRunning *int                           `json:"min_machines_running,omitempty" toml:"min_machines_running,omitempty"`
	Processes          []string                       `json:"processes,omitempty" toml:"processes,omitempty"`
	Concurrency        *api.MachineServiceConcurrency `toml:"concurrency,omitempty" json:"concurrency,omitempty"`
	TLSOptions         *api.TLSOptions                `json:"tls_options,omitempty" toml:"tls_options,omitempty"`
	HTTPOptions        *api.HTTPOptions               `json:"http_options,omitempty" toml:"http_options,omitempty"`
	HTTPChecks         []*ServiceHTTPCheck            `json:"checks,omitempty" toml:"checks,omitempty"`
}

func (*HTTPService) ToService added in v0.0.514

func (s *HTTPService) ToService() *Service

type Metrics added in v0.1.93

type Metrics struct {
	*api.MachineMetrics
	Processes []string `json:"processes,omitempty" toml:"processes,omitempty"`
}

type Mount added in v0.0.522

type Mount = scanner.Volume

type Service

type Service struct {
	Protocol     string `json:"protocol,omitempty" toml:"protocol"`
	InternalPort int    `json:"internal_port,omitempty" toml:"internal_port"`
	// AutoStopMachines and AutoStartMachines should not have omitempty for TOML. The encoder
	// already omits nil since it can't be represented, and omitempty makes it omit false as well.
	AutoStopMachines   *bool                          `json:"auto_stop_machines,omitempty" toml:"auto_stop_machines"`
	AutoStartMachines  *bool                          `json:"auto_start_machines,omitempty" toml:"auto_start_machines"`
	MinMachinesRunning *int                           `json:"min_machines_running,omitempty" toml:"min_machines_running,omitempty"`
	Ports              []api.MachinePort              `json:"ports,omitempty" toml:"ports"`
	Concurrency        *api.MachineServiceConcurrency `json:"concurrency,omitempty" toml:"concurrency"`
	TCPChecks          []*ServiceTCPCheck             `json:"tcp_checks,omitempty" toml:"tcp_checks,omitempty"`
	HTTPChecks         []*ServiceHTTPCheck            `json:"http_checks,omitempty" toml:"http_checks,omitempty"`
	Processes          []string                       `json:"processes,omitempty" toml:"processes,omitempty"`
}

type ServiceHTTPCheck

type ServiceHTTPCheck struct {
	Interval    *api.Duration `json:"interval,omitempty" toml:"interval,omitempty"`
	Timeout     *api.Duration `json:"timeout,omitempty" toml:"timeout,omitempty"`
	GracePeriod *api.Duration `toml:"grace_period,omitempty" json:"grace_period,omitempty"`

	// HTTP Specifics
	HTTPMethod        *string           `json:"method,omitempty" toml:"method,omitempty"`
	HTTPPath          *string           `json:"path,omitempty" toml:"path,omitempty"`
	HTTPProtocol      *string           `json:"protocol,omitempty" toml:"protocol,omitempty"`
	HTTPTLSSkipVerify *bool             `json:"tls_skip_verify,omitempty" toml:"tls_skip_verify,omitempty"`
	HTTPTLSServerName *string           `json:"tls_server_name,omitempty" toml:"tls_server_name,omitempty"`
	HTTPHeaders       map[string]string `json:"headers,omitempty" toml:"headers,omitempty"`
}

func (*ServiceHTTPCheck) String

func (chk *ServiceHTTPCheck) String(port int) string

type ServiceTCPCheck

type ServiceTCPCheck struct {
	Interval    *api.Duration `json:"interval,omitempty" toml:"interval,omitempty"`
	Timeout     *api.Duration `json:"timeout,omitempty" toml:"timeout,omitempty"`
	GracePeriod *api.Duration `toml:"grace_period,omitempty" json:"grace_period,omitempty"`
}

func (*ServiceTCPCheck) String

func (chk *ServiceTCPCheck) String(port int) string

type Static

type Static struct {
	GuestPath string `toml:"guest_path" json:"guest_path,omitempty" validate:"required"`
	UrlPrefix string `toml:"url_prefix" json:"url_prefix,omitempty" validate:"required"`
}

type ToplevelCheck

type ToplevelCheck struct {
	Port              *int              `json:"port,omitempty" toml:"port,omitempty"`
	Type              *string           `json:"type,omitempty" toml:"type,omitempty"`
	Interval          *api.Duration     `json:"interval,omitempty" toml:"interval,omitempty"`
	Timeout           *api.Duration     `json:"timeout,omitempty" toml:"timeout,omitempty"`
	GracePeriod       *api.Duration     `json:"grace_period,omitempty" toml:"grace_period,omitempty"`
	HTTPMethod        *string           `json:"method,omitempty" toml:"method,omitempty"`
	HTTPPath          *string           `json:"path,omitempty" toml:"path,omitempty"`
	HTTPProtocol      *string           `json:"protocol,omitempty" toml:"protocol,omitempty"`
	HTTPTLSSkipVerify *bool             `json:"tls_skip_verify,omitempty" toml:"tls_skip_verify,omitempty"`
	HTTPTLSServerName *string           `json:"tls_server_name,omitempty" toml:"tls_server_name,omitempty"`
	HTTPHeaders       map[string]string `json:"headers,omitempty" toml:"headers,omitempty"`
	Processes         []string          `json:"processes,omitempty" toml:"processes,omitempty"`
}

func (*ToplevelCheck) String

func (chk *ToplevelCheck) String() string

Jump to

Keyboard shortcuts

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