cfg

package
v5.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2024 License: GPL-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package cfg implements the baur configuration file parser.

Index

Constants

View Source
const (

	// Version identifies the format of the configuration files that the
	// package can parse. Whenever an incompatible change is made, the
	// Version number is increased.
	Version int = 7
)

Variables

View Source
var ErrIncludeIDNotFound = errors.New("id not found in include file")

ErrIncludeIDNotFound describes that an include with a specific does not exist in an include file.

Functions

func ToFileOptCommented

func ToFileOptCommented() toFileOpt

ToFileOptCommented comment every line in the config

func ToFileOptOverwrite

func ToFileOptOverwrite() toFileOpt

ToFileOptOverwrite overwrite an existing file instead of returning an error

Types

type App

type App struct {
	Name     string   `toml:"name" comment:"Application name"`
	Includes []string `` /* 174-byte string literal not displayed */
	Tasks    Tasks    `toml:"Task"`
	// contains filtered or unexported fields
}

App stores an application configuration.

func AppFromFile

func AppFromFile(path string) (*App, error)

AppFromFile unmarshals an application configuration from a file and returns it.

func ExampleApp

func ExampleApp(name string) *App

ExampleApp returns an exemplary app cfg struct with the name set to the given value.

func (*App) FilePath

func (a *App) FilePath() string

FilePath returns the path of the app configuration file

func (*App) Merge

func (a *App) Merge(includedb *IncludeDB, includeSpecResolver Resolver) error

Merge merges the configuration with it's includes. The task includes listed in App.Includes are loaded via the includedb and then appeneded to the task list.

func (*App) Resolve

func (a *App) Resolve(resolver Resolver) error

Resolve runs the resolvers on string fields that can contain special strings. These special strings are replaced with concrete values by the resolvers.

func (*App) ToFile

func (a *App) ToFile(filepath string, opts ...toFileOpt) error

ToFile marshals the App into toml format and writes it to the given filepath.

func (*App) Validate

func (a *App) Validate() error

Validate validates the configuration. It should be called after Merge().

type Database

type Database struct {
	PGSQLURL string `` /* 232-byte string literal not displayed */
}

Database contains database configuration

type Discover

type Discover struct {
	Dirs        []string `toml:"application_dirs" comment:"Directories in which applications (.app.toml files) are discovered"`
	SearchDepth int      `toml:"search_depth" comment:"Descend at most search_depth levels to find application configs"`
}

Discover stores the Discover section of the repository configuration.

type DockerImageOutput

type DockerImageOutput struct {
	IDFile         string `toml:"idfile" comment:"File containing the image ID of the produced image (docker build --iidfile)."`
	RegistryUpload []DockerImageRegistryUpload
}

DockerImageOutput describes where a docker container is uploaded to.

type DockerImageRegistryUpload

type DockerImageRegistryUpload struct {
	Registry   string `toml:"registry" comment:"Registry address in the format <HOST>:[<PORT>]. If it's empty the docker agent's default is used."`
	Repository string `toml:"repository"`
	Tag        string `toml:"tag"`
}

DockerImageRegistryUpload stores information about a Docker image upload.

func (*DockerImageRegistryUpload) Resolve

func (d *DockerImageRegistryUpload) Resolve(resolver Resolver) error

type EnvVarsInputs

type EnvVarsInputs struct {
	Names    []string `` /* 207-byte string literal not displayed */
	Optional bool     `toml:"optional" comment:"When optional is true, a variable pattern matching 0 defined variables will not cause an error."`
}

func (*EnvVarsInputs) Validate

func (ei *EnvVarsInputs) Validate() error

Validate always returns nil.

type FileCopy

type FileCopy struct {
	Path string `toml:"path" comment:"Destination directory"`
}

FileCopy describes a filesystem location where a task output is copied to.

type FileExcludeList

type FileExcludeList struct {
	Paths []string `` /* 306-byte string literal not displayed */
}

FileExcludeList specifies paths to files that are excluded as inputs.

func (*FileExcludeList) Validate

func (f *FileExcludeList) Validate() error

type FileInputs

type FileInputs struct {
	// if attributes are added/removed or modified, the input resolver
	// cache *must* be adapted to ensure that the caching logic respects
	// the attribute change.
	Paths          []string `` /* 228-byte string literal not displayed */
	Optional       bool     `toml:"optional" comment:"When optional is true a path pattern that matches 0 files will not cause an error."`
	GitTrackedOnly bool     `toml:"git_tracked_only" comment:"Only resolve to files that are part of the Git repository."`
}

FileInputs stores glob paths to inputs of a task.

type FileOutput

type FileOutput struct {
	Path     string     `toml:"path" comment:"Path relative to the application directory."`
	FileCopy []FileCopy `comment:"Copy the file to a local directory."`
	S3Upload []S3Upload `comment:"Upload the file to S3."`
}

FileOutput describes where a file output is stored.

type GolangSources

type GolangSources struct {
	// if attributes are added/removed or modified, the input resolver
	// cache *must* be adapted to ensure that the caching logic respects
	// the attribute change.
	Queries     []string `` /* 487-byte string literal not displayed */
	Environment []string `toml:"environment" comment:"Environment when running the go query tool."`
	BuildFlags  []string `toml:"build_flags" comment:"List of command-line flags to be passed through to the Go query tool."`
	Tests       bool     `toml:"tests" comment:"If true queries are resolved to test files, otherwise testfiles are ignored."`
}

GolangSources specifies inputs for Golang Applications

type Include

type Include struct {
	Input  InputIncludes
	Output OutputIncludes
	Task   TaskIncludes
	// contains filtered or unexported fields
}

func ExampleInclude

func ExampleInclude() *Include

ExampleInclude returns an Include struct with exemplary values.

func IncludeFromFile

func IncludeFromFile(path string) (*Include, error)

IncludeFromFile unmarshals an Include struct from a file.

func (*Include) ToFile

func (incl *Include) ToFile(filepath string, opts ...toFileOpt) error

ToFile marshals the Include struct to TOML and writes it to filepath.

type IncludeDB

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

IncludeDB loads and stores include config files. It's methods are not concurrency-safe.

func NewIncludeDB

func NewIncludeDB(logf LogFn) *IncludeDB

type Input

type Input struct {
	EnvironmentVariables []EnvVarsInputs
	Files                []FileInputs
	GolangSources        []GolangSources `comment:"Inputs specified by resolving dependencies of Golang source files or packages."`
	TaskInfos            []TaskInfo      `comment:"Information about another baur task."`
	ExcludedFiles        FileExcludeList
}

Input contains information about task inputs

func (*Input) IsEmpty

func (in *Input) IsEmpty() bool

type InputInclude

type InputInclude struct {
	IncludeID string `toml:"include_id" comment:"identifier of the include"`

	EnvironmentVariables []EnvVarsInputs
	Files                []FileInputs
	GolangSources        []GolangSources `comment:"Inputs specified by resolving dependencies of Golang source files or packages."`
	ExcludedFiles        FileExcludeList
	TaskInfos            []TaskInfo `comment:"Information about task of the same App"`
	// contains filtered or unexported fields
}

InputInclude is a reusable Input definition.

func (*InputInclude) IsEmpty

func (in *InputInclude) IsEmpty() bool

type InputIncludes

type InputIncludes []*InputInclude

InputIncludes is a list of InputInclude.

type LogFn

type LogFn func(format string, v ...any)

type Output

type Output struct {
	DockerImage []DockerImageOutput
	File        []FileOutput
}

Output is the tasks output section

func (*Output) DockerImageOutputs

func (out *Output) DockerImageOutputs() []DockerImageOutput

func (*Output) FileOutputs

func (out *Output) FileOutputs() []FileOutput

func (*Output) Merge

func (out *Output) Merge(other OutputDef)

Merge appends the information in other to out.

func (*Output) Resolve

func (out *Output) Resolve(resolver Resolver) error

type OutputDef

type OutputDef interface {
	DockerImageOutputs() []DockerImageOutput
	FileOutputs() []FileOutput
}

type OutputInclude

type OutputInclude struct {
	IncludeID string `toml:"include_id" comment:"identifier of the include"`

	DockerImage []DockerImageOutput `comment:"Docker images that are produced by the [Task.command]"`
	File        []FileOutput        `comment:"Files that are produces by the [Task.command]"`
	// contains filtered or unexported fields
}

OutputInclude is a reusable Output definition

func (*OutputInclude) DockerImageOutputs

func (out *OutputInclude) DockerImageOutputs() []DockerImageOutput

func (*OutputInclude) FileOutputs

func (out *OutputInclude) FileOutputs() []FileOutput

type OutputIncludes

type OutputIncludes []*OutputInclude

OutputIncludes is a list of OutputInclude

type Repository

type Repository struct {
	ConfigVersion int `toml:"config_version" comment:"Internal field, version of baur configuration format"`

	Database Database
	Discover Discover
	// contains filtered or unexported fields
}

Repository contains the repository configuration.

func ExampleRepository

func ExampleRepository() *Repository

ExampleRepository returns an exemplary Repository config

func RepositoryFromFile

func RepositoryFromFile(cfgPath string) (*Repository, error)

RepositoryFromFile reads the repository config from a file and returns it.

func (*Repository) FilePath

func (r *Repository) FilePath() string

func (*Repository) ToFile

func (r *Repository) ToFile(filepath string, opts ...toFileOpt) error

ToFile writes an Repository configuration file to filepath.

func (*Repository) Validate

func (r *Repository) Validate() error

Validate validates a repository configuration

type Resolver

type Resolver interface {
	Resolve(string) (string, error)
}

Resolver is an interface for replacing substrings with a special meaning in strings.

type S3Upload

type S3Upload struct {
	Bucket string `toml:"bucket"`
	Key    string `toml:"key"`
}

S3Upload contains S3 upload information

type Task

type Task struct {
	Name     string   `toml:"name" comment:"Task name"`
	Command  []string `toml:"command" comment:"Command to execute.\n The first element is the command, the following its arguments."`
	Includes []string `` /* 186-byte string literal not displayed */
	Input    Input    `toml:"Input" comment:"Inputs are tracked, when they change the task is rerun."`
	Output   Output   `toml:"Output" comment:"Artifacts produced by the Task.command and their upload destinations."`
	// contains filtered or unexported fields
}

cfg Task is a task section

func (*Task) Filepaths

func (t *Task) Filepaths() []string

Filepaths returns a list of all parsed config files. This is the app config file and files of the included sections.

type TaskInclude

type TaskInclude struct {
	IncludeID string `toml:"include_id" comment:"identifier of the include"`

	Name     string   `toml:"name" comment:"Task name"`
	Command  []string `` /* 219-byte string literal not displayed */
	Includes []string `` /* 181-byte string literal not displayed */
	Input    Input    `toml:"Input" comment:"Specification of task inputs like source files, Makefiles, etc"`
	Output   Output   `toml:"Output" comment:"Specification of task outputs produced by the Task.command"`
	// contains filtered or unexported fields
}

TaskInclude is a reusable Tasks definition

type TaskIncludes

type TaskIncludes []*TaskInclude

type TaskInfo

type TaskInfo struct {
	TaskName   string `toml:"task_name" comment:"name of a task of the same app"`
	EnvVarName string `` /* 196-byte string literal not displayed */
}

func (*TaskInfo) Validate

func (t *TaskInfo) Validate() error

type Tasks

type Tasks []*Task

Directories

Path Synopsis
Package resolver provides templating for baur configuration files.
Package resolver provides templating for baur configuration files.
upgrade
v5
Package v5 provides helpers to convert baur configs in v5 format (baur 2.x) to v7 (baur 4.x)
Package v5 provides helpers to convert baur configs in v5 format (baur 2.x) to v7 (baur 4.x)

Jump to

Keyboard shortcuts

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