Documentation ¶
Index ¶
- Variables
- func StdIOConsumer(p *ProcessLogger) error
- type Attr
- type FPM
- type FileConsumer
- type Loader
- type Package
- func (p *Package) Build() error
- func (p *Package) BuildAndPackage() error
- func (p *Package) Cleanup() error
- func (p *Package) ExpandRecursive(parent *Package) error
- func (p *Package) Package() error
- func (p *Package) Render(tmpl string) (bytes.Buffer, error)
- func (p *Package) SetCache(cache cache.Cache)
- func (p *Package) SetLogger(logger *logrus.Logger)
- func (p *Package) SetTemplate(tmpl *Template)
- func (p *Package) Setup() error
- func (p *Package) TotalPackages() int
- type Packager
- type ProcessLogger
- type Resource
- type RollupConsumer
- type Scripts
- type Target
- type Template
- func (t *Template) BuildFile(name string) string
- func (t *Template) Empty() string
- func (t *Template) Include(path string) (string, error)
- func (t *Template) IncludeTemplate(path string) (string, error)
- func (t *Template) Render(in string) (bytes.Buffer, error)
- func (t *Template) SpecFile(name string) string
- func (t *Template) Top() *Package
- func (t *Template) Variable(name string) (string, error)
Constants ¶
This section is empty.
Variables ¶
var ( // ErrFieldRequired is returned when a required field is not set. ErrFieldRequired = errors.New("field is required") // ErrInvalidScriptName is returned when a bad script name is set and passed // to FPM. ErrInvalidScriptName = errors.New("invalid script name") )
var ( // ErrBadResponse is returned when the resources is not found or returns an // otherwise problematic response ErrBadResponse = errors.New("bad response") // ErrBadHash is returned when the given hash and the actual file hash do not // match ErrBadHash = errors.New("bad hash") // ErrBadHashType is returned when a hash type that Hammer does not not know // how to calculate is given. ErrBadHashType = errors.New("bad hash type") )
var ( // ErrNoScript is returend when the requested script isn't found. ErrNoScript = errors.New("no such script") )
Functions ¶
func StdIOConsumer ¶
func StdIOConsumer(p *ProcessLogger) error
StdIOConsumer replays logs written to stdio
Types ¶
type Attr ¶
type Attr struct { File string `yaml:"file"` Mode string `yaml:"mode,omitempty"` User string `yaml:"user,omitempty"` Group string `yaml:"group,omitempty"` }
Attr describes the permissions, Owner and Group for a file
type FPM ¶
type FPM struct { Package *Package // contains filtered or unexported fields }
FPM is a wrapper around the Ruby FPM tool, and will call it in a subprocess.
type FileConsumer ¶
type FileConsumer struct {
// contains filtered or unexported fields
}
FileConsumer logs files to the given directory
func NewFileConsumer ¶
func NewFileConsumer(p *ProcessLogger, path, name string) (*FileConsumer, error)
NewFileConsumer starts a FileConsumer with the given options
func (*FileConsumer) Error ¶
func (f *FileConsumer) Error() error
type Loader ¶
type Loader struct { // The loader looks for packages in Root Root string // The loader looks for files named the value of Indicator to signify a package Indicator string }
Loader looks for Package specs in a given root.
type Package ¶
type Package struct { Architecture string `yaml:"architecture,omitempty"` Depends []string `yaml:"depends,omitempty"` Description string `yaml:"description,omitempty"` Epoch string `yaml:"epoch,omitempty"` ExtraArgs string `yaml:"extra-args,omitempty"` Attrs []Attr `yaml:"attrs,omitempty"` Iteration string `yaml:"iteration,omitempty"` License string `yaml:"license,omitempty"` Name string `yaml:"name,omitempty"` Obsoletes []string `yaml:"obsoletes,omitempty"` Resources []Resource `yaml:"resources,omitempty"` Scripts Scripts `yaml:"scripts,omitempty"` Targets []Target `yaml:"targets,omitempty"` Type string `yaml:"type,omitempty"` URL string `yaml:"url,omitempty"` Vendor string `yaml:"vendor,omitempty"` Version string `yaml:"version,omitempty"` // Multi parametrizes builds by expanding recursively. This information is // then moved to Parent and Children. Multi []*Package `yaml:"multi,omitempty"` // various roots BuildRoot string `yaml:"-"` Empty string `yaml:"-"` OutputRoot string `yaml:"-"` ScriptRoot string `yaml:"-"` SpecRoot string `yaml:"-"` TargetRoot string `yaml:"-"` LogRoot string `yaml:"-"` // graph of builds Parent *Package `yaml:"-"` Children []*Package `yaml:"-"` // information about the machine doing the building CPUs int `yaml:"-"` // Extra variables that will be available to templates Vars map[string]string `yaml:"vars,omitempty"` StreamLogs bool `yaml:"-"` // contains filtered or unexported fields }
Package is the main struct in Hammer. It contains all the (meta-)information needed to produce a package.
func NewPackage ¶
func NewPackage() *Package
NewPackage sets up defaults for build machine information, the logger, and the templater
func NewPackageFromYAML ¶
NewPackageFromYAML loads a package from YAML if it can
func (*Package) Build ¶
Build runs the build script in the specified shell and build directory. If there is not a build script specified for the package, Build is basically a no-op but will warn about missing the script.
func (*Package) BuildAndPackage ¶
BuildAndPackage is the main function you'll want to call after loading a Package. It takes care of all the stages of the build, including setup and cleanup.
func (*Package) Cleanup ¶
Cleanup is basically the opposite function of Setup, although it doesn't have nearly as much work to do. It just recursively removes the temporary directories.
func (*Package) ExpandRecursive ¶
ExpandRecursive fills in inheritance for the Multi field
func (*Package) Package ¶
Package drives the FPM instance created during Setup to package the output of the Build step.
func (*Package) SetLogger ¶
SetLogger sets the package logger from a plain logrus Logger, and sets a "name" field before accepting it.
func (*Package) SetTemplate ¶
SetTemplate sets the default template renderer for the package
func (*Package) Setup ¶
Setup does all the filesystem work necessary to make sure that the package can be built. This includes:
- creating all temporary directories - getting the sources and storing them - rendering and writing all the scripts to disk - setting up the build logging - making sure FPM has an environment it can run in
func (*Package) TotalPackages ¶
TotalPackages is the total count of packages for this and all children.
type Packager ¶
type Packager struct {
// contains filtered or unexported fields
}
Packager takes a list of packages and controls their simultaneous building
func NewPackager ¶
NewPackager returns a configured Package
func (*Packager) Build ¶
Build builds all the packages in the Packager up to the given concurrency level. It assumes that the packages will report errors to the user through their given logger, and therefor only returns a success or failure.
func (*Packager) EnsureOutputDir ¶
EnsureOutputDir makes sure that the output directory is set
type ProcessLogger ¶
type ProcessLogger struct {
// contains filtered or unexported fields
}
ProcessLogger logs a given process
func NewProcessLogger ¶
func NewProcessLogger(cmd *exec.Cmd) (*ProcessLogger, error)
NewProcessLogger creates a ProcessLogger when given a process
func (*ProcessLogger) Start ¶
func (p *ProcessLogger) Start() error
Start the process after subscribers are registered
func (*ProcessLogger) Stop ¶
func (p *ProcessLogger) Stop() error
Stop the process after the command is finished to clean up goroutines
type Resource ¶
type Resource struct { URL string `yaml:"url"` HashType string `yaml:"hash-type"` Hash string `yaml:"hash"` Unpack bool `yaml:"unpack"` }
Resource describes a remote resource that will be downloaded to be built for the package.
func (*Resource) Download ¶
Download downloads this resource, make sure the checksum matches, and returns the bytes
func (*Resource) Name ¶
Name returns the file name at the URL. So for example, "http://example.com/source.tgz" would return "source.tgz"
type RollupConsumer ¶
RollupConsumer keeps a tally of the logs written so far in memory
func NewRollupConsumer ¶
func NewRollupConsumer(p *ProcessLogger) (*RollupConsumer, error)
NewRollupConsumer gets a new RollupConsumer
type Scripts ¶
Scripts is just an alias for a map[string]string - this means that you can specify any script names you like (whether they'll be accepted, however, is a different story)
type Target ¶
type Target struct { Src string `yaml:"src"` Dest string `yaml:"dest"` Template bool `yaml:"template"` Config bool `yaml:"config"` }
Target describes the output of a build. It has a source (Src) and a destination (Dest), and can be templated and marked as a config file.
type Template ¶
Template controls template rendering within a Package
func NewTemplate ¶
NewTemplate takes a Package and returns a configured Template.
func (*Template) BuildFile ¶
BuildFile (buildFile) is a template function that joins the SpecRoot with the given name. Useful in target specifications.
func (*Template) Empty ¶
Empty (empty) is a template function that just returns the path to an empty directory. This is useful for creating empty directories in targets (like `/etc/yourpackage/conf.d`)
func (*Template) Include ¶
Include (include) is a template function that returns the raw version of a file
func (*Template) IncludeTemplate ¶
IncludeTemplate (includeTemplate) is a template function that renders a file from disk and returns the output
func (*Template) Render ¶
Render renders the input string according to the template rules and returns a buffer. This can be read with `bytes.Buffer.String()` or `bytes.Buffer.Bytes()`
func (*Template) SpecFile ¶
SpecFile (specFile) is a template function that joins the SpecRoot with the given name. Useful in target specifications.