conf

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: May 16, 2014 License: Apache-2.0 Imports: 5 Imported by: 0

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

View Source
const ConfigFileName = "hroot.toml"
View Source
const DockFolder = "dock"
View Source
const GraphFolder = "graph"

Variables

View Source
var DefaultConfiguration = Configuration{
	Settings: DefaultContainer,
}

Default configuration

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

func LoadContainerSettings

func LoadContainerSettings(base *Container, inc *Container, meta *toml.MetaData, key ...string)

Loads a container configuration object, overriding a base This function prevents empty TOML keys (anything you didn't specify) from overriding a preset value.

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

func (*Container) Localize

func (c *Container) Localize(dir string)

Localize a container object to a given folder

type Folders

type Folders struct {
	//Where we've decided the graph folder is or should be
	Graph string
}

Folder location

func DefaultFolders

func DefaultFolders(dir string) *Folders

Default folders

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

Jump to

Keyboard shortcuts

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