Documentation ¶
Index ¶
- Variables
- func FindMaintainer() (string, bool)
- func Ignored(dir string) ([]string, error)
- func Initialize(dir string) error
- func IsInitialized(dir string) bool
- func Push(pushFile, pkg string, slctr string) error
- type BuildOpts
- type BuildRequest
- type Packager
- type PackagerStrategy
- type Pkg
- func (p *Pkg) BuildCommand() *exec.Cmd
- func (p *Pkg) BuildFile() string
- func (p *Pkg) Ctrl() *control.Control
- func (p *Pkg) CtrlDir(paths ...string) string
- func (p *Pkg) CtrlFile() string
- func (p *Pkg) CtrlFiles() []string
- func (p *Pkg) DebFile() string
- func (p *Pkg) Dir(paths ...string) string
- func (p *Pkg) DocPath() string
- func (p *Pkg) Excludes() []string
- func (p *Pkg) IgnoreFile() string
- func (p *Pkg) IgnoreList() []string
- func (p *Pkg) Initialized() bool
- func (p *Pkg) PushFile() string
- func (p *Pkg) Size() (string, error)
Constants ¶
This section is empty.
Variables ¶
var CalculateMD5Sums = func(br *BuildRequest) error { outfile := (&Pkg{dir: br.tmp}).CtrlDir("md5sums") sums, err := md5walk.Walk(br.tmp) if err != nil { return fmt.Errorf("failed to generate md5sums: %s", err) } f, err := os.OpenFile(outfile, os.O_WRONLY|os.O_CREATE, 0755) if err != nil { return fmt.Errorf("failed to write md5sums: %s", err) } _, err = sums.Write(f) return err }
CalculateMD5Sums is a packaging step that calculates the file sums
var CalculateSize = func(br *BuildRequest) error { b, err := file.DirSize(br.tmp, br.pkg.Excludes()) if err != nil { return fmt.Errorf("failed to calculate package size: %s", err) } br.pkg.ctrl.Size = strconv.Itoa(b / 1024) br.pkg.ctrl.WriteFile((&Pkg{dir: br.tmp}).CtrlFile()) br.pkg.ctrl.WriteFile(br.pkg.CtrlFile()) return nil }
CalculateSize of a directory using du, excluding any given paths
var CleanRoot = func(br *BuildRequest) error { list, err := file.ListFilesIn(br.tmp) if err != nil { return fmt.Errorf("failed to find root files: %s", err) } docpath := filepath.Join(br.tmp, "usr", "share", "doc", br.pkg.ctrl.Name) if err := os.MkdirAll(docpath, 0755); err != nil { return fmt.Errorf("failed to create the doc path %s: %s", docpath, err) } return file.MoveFiles(list, docpath) }
CleanRoot is a packaging step to clean the root folder of the package so that the target root file system is not polluted
var Debug = false
Debug is the default debug mode for the build options when they are not explicity specified with the BuildWithOpts() call
var DpkgDebBuild = func(br *BuildRequest) error { if br.debpath == "" { br.debpath = br.pkg.Dir("pkg") } if err := os.MkdirAll(br.debpath, 0755); err != nil { return fmt.Errorf("failed to make package dir at %s: %s", br.debpath, err) } if err := os.Chmod(br.pkg.dir, 0755); err != nil { return fmt.Errorf("failed to set the proper perms on the control dir") } for _, fpath := range br.pkg.CtrlFiles() { if err := os.Chmod(fpath, 0755); err != nil { return fmt.Errorf("failed to set the proper perms on the control file %s", fpath) } } br.debpath = filepath.Join(br.debpath, br.pkg.ctrl.Filename()) cmd := exec.Command("/usr/bin/fakeroot", "dpkg-deb", "-b", br.tmp, br.debpath) if br.Debug { cmd.Stderr = os.Stderr cmd.Stdout = os.Stderr } if err := cmd.Run(); err != nil { return fmt.Errorf("failed to build package %s from %s: %s", br.debpath, br.tmp, err) } return nil }
DpkgDebBuild is a packaging step that builds the package using dpkg-deb
var PrintPackageTree = func(br *BuildRequest) error { if !Debug { return nil } os.Stderr.WriteString("\nResultant Package Tree\n") os.Stderr.WriteString("-------------------------------------------------\n") for _, fn := range file.Glob(br.tmp, "**") { os.Stderr.WriteString(strings.Replace(fn, br.tmp+"/", "", -1) + "\n") } os.Stderr.WriteString("-------------------------------------------------\n\n") return nil }
var StageFiles = func(br *BuildRequest) error { var err error br.tmp, err = ioutil.TempDir("/tmp", "go-ian") if err != nil { return fmt.Errorf("couldn't make tmp dir: %s", err) } args := []string{"-rav"} for _, s := range br.pkg.Excludes() { if s == "" { continue } args = append(args, fmt.Sprintf("--exclude=%s", s)) } args = append(args, br.pkg.Dir()+"/", br.tmp) cmd := exec.Command("/usr/bin/rsync", args...) if br.Debug { os.Stderr.WriteString("\nStaging files to " + br.tmp + "\n") os.Stderr.WriteString("-------------------------------------------------\n") tell.Debugf("running: %s", str.CommandString(cmd)) cmd.Stderr = os.Stderr cmd.Stdout = os.Stderr } err = cmd.Run() if br.Debug { os.Stderr.WriteString("-------------------------------------------------\n\n") } return err }
StageFiles is a packaging step that stages the package files to a temporary directory to work from
Functions ¶
func FindMaintainer ¶
func Initialize ¶
Initialize will turn the given directory into an ian repo
func IsInitialized ¶
IsInitialized determines if the directory is already initialized
Types ¶
type BuildRequest ¶
type BuildRequest struct { Debug bool // contains filtered or unexported fields }
BuildRequest is like a context object for packager strategies to make us of and share knowledge
func (*BuildRequest) CleanUp ¶
func (br *BuildRequest) CleanUp()
CleanUp is run at the end of the package build to clean up any leftover resources
type Packager ¶
type Packager []PackagerStrategy
Packager is a collection of packaging steps/strategies that can be used together to build a package
func DefaultPackager ¶
func DefaultPackager() (p Packager)
DefaultPackager returns a preconfigured packager using the default packaging steps/strategies
func (Packager) Build ¶
Build will create a debian package from the given control file and directory. It does this by using rsync to copy the repo to a temp dir, excluded unwanted files and moving any files in the root of the package to a /usr/share/doc folder. Then it calculates the package size, file checksums and calls dpkg-deb to build the package. The path to the package and an error (if any) is returned.
type PackagerStrategy ¶
type PackagerStrategy func(br *BuildRequest) error
PackagerStrategy is a function that represents a strategy or stage in the packaging process
type Pkg ¶
type Pkg struct {
// contains filtered or unexported fields
}
Pkg represents a ian debian package with helpers for various operations around managing a debian package with ian
func NewPackage ¶
NewPackage returns a new Pkg object with the control file contained within, when given a directory
func (*Pkg) BuildCommand ¶
BuildCommand returns the command to run in order to run the packages build script
func (*Pkg) CtrlDir ¶
CtrlDir returns the path to the control dir in the given directory. Optional extra paths will result in getting a path inside the control dir e.g. to the postinst file
func (*Pkg) DebFile ¶
DebFile returns the filepath to where the debian package should be placed after building it
func (*Pkg) Dir ¶
Dir returns the path to the repo root directory. Optional extra paths will result in getting a path inside the dir
func (*Pkg) IgnoreFile ¶
IgnoreFile returns the path to the packages ignore file
func (*Pkg) IgnoreList ¶
IgnoreList will use the ignore file from the package to generate a list of ignored file patterns. If there is no ignore file then an empty slice is returned
func (*Pkg) Initialized ¶
Initialized will return true if the package has been initialized