hammer

package
v0.0.0-...-b371572 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2016 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

func NewFPM

func NewFPM(p *Package) (*FPM, error)

NewFPM does all necessary setup to run an FPM instance

func (*FPM) PackageFor

func (f *FPM) PackageFor(outType string) (string, error)

PackageFor runs the packaging process on a given out type ("rpm", for instance). It returns a string of the command combined output.

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.

func NewLoader

func NewLoader(root string) *Loader

NewLoader returns a Loader with default values set

func (*Loader) Load

func (l *Loader) Load() ([]*Package, error)

Load finds all the packages below Root in the filesystem

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

func NewPackageFromYAML(content []byte) (*Package, error)

NewPackageFromYAML loads a package from YAML if it can

func (*Package) Build

func (p *Package) Build() error

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

func (p *Package) BuildAndPackage() error

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

func (p *Package) Cleanup() error

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

func (p *Package) ExpandRecursive(parent *Package) error

ExpandRecursive fills in inheritance for the Multi field

func (*Package) Package

func (p *Package) Package() error

Package drives the FPM instance created during Setup to package the output of the Build step.

func (*Package) Render

func (p *Package) Render(tmpl string) (bytes.Buffer, error)

Render maybe renders a template string in the context of this package.

func (*Package) SetCache

func (p *Package) SetCache(cache cache.Cache)

SetCache sets the cache for the package

func (*Package) SetLogger

func (p *Package) SetLogger(logger *logrus.Logger)

SetLogger sets the package logger from a plain logrus Logger, and sets a "name" field before accepting it.

func (*Package) SetTemplate

func (p *Package) SetTemplate(tmpl *Template)

SetTemplate sets the default template renderer for the package

func (*Package) Setup

func (p *Package) Setup() error

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

func (p *Package) TotalPackages() int

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

func NewPackager(pkgs []*Package) *Packager

NewPackager returns a configured Package

func (*Packager) Build

func (p *Packager) Build(ctx context.Context, concurrency int) (success bool)

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

func (p *Packager) EnsureOutputDir(path string) error

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

func (*ProcessLogger) Subscribe

func (p *ProcessLogger) Subscribe() (stdout chan []byte, stderr chan []byte, err error)

Subscribe returns two channels for the logged command's stdout and stderr

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

func (s *Resource) Download(p *Package) ([]byte, error)

Download downloads this resource, make sure the checksum matches, and returns the bytes

func (*Resource) Name

func (s *Resource) Name(p *Package) string

Name returns the file name at the URL. So for example, "http://example.com/source.tgz" would return "source.tgz"

func (*Resource) RenderURL

func (s *Resource) RenderURL(p *Package) string

RenderURL renders the resource URL with the given package. If it fails, it just uses the raw name (useful if the URL contains odd characters)

type RollupConsumer

type RollupConsumer struct {
	Out bytes.Buffer
	Err bytes.Buffer
}

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

type Scripts map[string]string

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)

func (Scripts) Content

func (s Scripts) Content(p *Package, name string) (bytes.Buffer, error)

Content reads the given script name off disk and returns it's rendered content

func (Scripts) RenderAndWriteAll

func (s Scripts) RenderAndWriteAll(p *Package) (map[string]string, error)

RenderAndWriteAll renders all scripts and writes them to the ScriptRoot of the given Package. It returns a map of the script names to their locations on disk.

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

type Template struct {
	Package *Package
	Funcs   template.FuncMap
}

Template controls template rendering within a Package

func NewTemplate

func NewTemplate(pkg *Package) *Template

NewTemplate takes a Package and returns a configured Template.

func (*Template) BuildFile

func (t *Template) BuildFile(name string) string

BuildFile (buildFile) is a template function that joins the SpecRoot with the given name. Useful in target specifications.

func (*Template) Empty

func (t *Template) Empty() string

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

func (t *Template) Include(path string) (string, error)

Include (include) is a template function that returns the raw version of a file

func (*Template) IncludeTemplate

func (t *Template) IncludeTemplate(path string) (string, error)

IncludeTemplate (includeTemplate) is a template function that renders a file from disk and returns the output

func (*Template) Render

func (t *Template) Render(in string) (bytes.Buffer, error)

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

func (t *Template) SpecFile(name string) string

SpecFile (specFile) is a template function that joins the SpecRoot with the given name. Useful in target specifications.

func (*Template) Top

func (t *Template) Top() *Package

Top (top) is a template function that returns the top-level package (for use in conjuction with the "multi" field)

func (*Template) Variable

func (t *Template) Variable(name string) (string, error)

Variable inserts an extra variable that was passed into the template via the spec.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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