Documentation ¶
Overview ¶
This package contains the config file loading system used by hroot. It produces conf.Settings from TOML-formatted configuration files.
Config files can arranged in nested directories, will loaded recursively, with config values accumulating and the deeper config files overriding the values from the shallower files, providing a simple structure for inheriting common configuration.
This package isolates conf.Settings from any specific knowledge of TOML (admittedly, conf.Settings is annotated to help the toml loader; but it does *not* have a compile-time dep on a toml library).
Index ¶
- Constants
- Variables
- func LoadConfigurationFromDisk(dir string, parser ConfigParser) (*Configuration, *Folders)
- func LoadContainerSettings(base *Container, inc *Container, meta *toml.MetaData, key ...string)
- type ConfigParser
- type Configuration
- type Container
- type Folders
- type Image
- type TomlConfigParser
Constants ¶
const ConfigFileName = "hroot.toml"
const DockFolder = "dock"
const GraphFolder = "graph"
Variables ¶
var DefaultConfiguration = Configuration{ Settings: DefaultContainer, }
Default configuration
var DefaultContainer = Container{ Command: []string{}, Folder: "/", Privileged: false, Mounts: [][]string{}, Ports: [][]string{}, DNS: []string{}, Attach: false, Purge: false, Environment: [][]string{}, }
Default container
Functions ¶
func LoadConfigurationFromDisk ¶
func LoadConfigurationFromDisk(dir string, parser ConfigParser) (*Configuration, *Folders)
Recursively finds configuration files & folders.
Types ¶
type ConfigParser ¶
type ConfigParser interface { //Parses a new configuration string. //Each call should override configuration added before. AddConfig(data, dir string) ConfigParser //Called to get the final configuration after loading. GetConfig() *Configuration }
A generic interface for loading configuration. Our implementation reads TOML files; roll your own!
type Configuration ¶
type Configuration struct { //The image struct Image Image `toml:"image"` //The settings struct Settings Container `toml:"settings"` //A map of named targets, each representing another set of container settings Targets map[string]Container `toml:"target"` }
Hroot configuration
func ParseString ¶
func ParseString(data string) (*Configuration, *toml.MetaData)
Parse a TOML-formatted string into a configuration struct.
type Container ¶
type Container struct { //What command to run Command []string `toml:"command"` //Which folder to start Folder string `toml:"folder"` //Run in privileged mode? Privileged bool `toml:"privileged"` //Array of mounts (each an array of strings: hostfolder, guestfolder, "ro"/"rw" permission) Mounts [][]string `toml:"mounts"` //What ports do you want to forward? (each an array of ints: hostport, guestport) Ports [][]string `toml:"ports"` //Do you want to use custom DNS servers? DNS []string `toml:"dns"` //Attach interactive terminal? Attach bool `toml:"attach"` //Delete when done? Purge bool `toml:"purge"` //Env variables (each an array of strings: variable, value) Environment [][]string `toml:"environment"` }
A container's settings
type Folders ¶
type Folders struct { //Where we've decided the graph folder is or should be Graph string }
Folder location
type Image ¶
type Image struct { //What image to use Name string `toml:"name"` //What image to build from Upstream string `toml:"upstream"` //What the upstream image is called in the docker index Index string `toml:"index"` }
Image and parent image
type TomlConfigParser ¶
type TomlConfigParser struct {
// contains filtered or unexported fields
}
func (*TomlConfigParser) AddConfig ¶
func (p *TomlConfigParser) AddConfig(data, dir string) ConfigParser
func (*TomlConfigParser) GetConfig ¶
func (p *TomlConfigParser) GetConfig() *Configuration