1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-10 03:47:03 +02:00
goreleaser/pipeline/fpm/fpm.go

106 lines
2.7 KiB
Go
Raw Normal View History

2017-04-14 20:39:32 +02:00
// Package fpm implements the Pipe interface providing FPM bindings.
2017-01-30 01:55:32 +02:00
package fpm
import (
"errors"
"log"
"os/exec"
"path/filepath"
"github.com/goreleaser/goreleaser/context"
2017-01-30 02:01:26 +02:00
"golang.org/x/sync/errgroup"
2017-01-30 01:55:32 +02:00
)
2017-01-30 02:33:08 +02:00
var goarchToUnix = map[string]string{
"386": "i386",
"amd64": "x86_64",
2017-01-30 01:55:32 +02:00
}
// ErrNoFPM is shown when fpm cannot be found in $PATH
var ErrNoFPM = errors.New("fpm not present in $PATH")
// Pipe for fpm packaging
type Pipe struct{}
// Description of the pipe
func (Pipe) Description() string {
return "Creating Linux packages with fpm"
}
// Run the pipe
func (Pipe) Run(ctx *context.Context) error {
2017-01-30 02:01:26 +02:00
if len(ctx.Config.FPM.Formats) == 0 {
log.Println("No output formats configured, skipping")
return nil
}
2017-01-30 11:53:05 +02:00
_, err := exec.LookPath("fpm")
if err != nil {
2017-01-30 01:55:32 +02:00
return ErrNoFPM
}
2017-01-30 02:33:08 +02:00
2017-01-30 01:55:32 +02:00
var g errgroup.Group
for _, format := range ctx.Config.FPM.Formats {
2017-01-30 02:33:08 +02:00
for _, goarch := range ctx.Config.Build.Goarch {
if ctx.Archives["linux"+goarch] == "" {
2017-01-30 01:55:32 +02:00
continue
}
2017-01-30 02:33:08 +02:00
archive := ctx.Archives["linux"+goarch]
2017-01-30 18:53:21 +02:00
arch := goarchToUnix[goarch]
2017-01-30 01:55:32 +02:00
g.Go(func() error {
2017-01-30 18:53:21 +02:00
return create(ctx, format, archive, arch)
2017-01-30 01:55:32 +02:00
})
}
}
return g.Wait()
}
2017-01-30 02:33:08 +02:00
func create(ctx *context.Context, format, archive, arch string) error {
2017-03-26 02:31:16 +02:00
var path = filepath.Join(ctx.Config.Dist, archive)
2017-01-30 01:55:32 +02:00
var file = path + ".deb"
2017-03-23 02:06:37 +02:00
var name = ctx.Config.Build.Binary
2017-01-30 01:55:32 +02:00
log.Println("Creating", file)
var options = []string{
2017-02-01 19:40:27 +02:00
"--input-type", "dir",
"--output-type", format,
"--name", name,
"--version", ctx.Version,
"--architecture", arch,
"--chdir", path,
"--package", file,
2017-01-30 01:55:32 +02:00
"--force",
}
if ctx.Config.FPM.Options.Vendor != "" {
options = append(options, "--vendor", ctx.Config.FPM.Options.Vendor)
}
if ctx.Config.FPM.Options.URL != "" {
options = append(options, "--url", ctx.Config.FPM.Options.URL)
}
if ctx.Config.FPM.Options.Maintainer != "" {
options = append(options, "--maintainer", ctx.Config.FPM.Options.Maintainer)
}
if ctx.Config.FPM.Options.Description != "" {
options = append(options, "--description", ctx.Config.FPM.Options.Description)
}
if ctx.Config.FPM.Options.License != "" {
options = append(options, "--license", ctx.Config.FPM.Options.License)
}
2017-01-30 02:33:08 +02:00
for _, dep := range ctx.Config.FPM.Dependencies {
2017-02-01 19:40:27 +02:00
options = append(options, "--depends", dep)
2017-01-30 01:55:32 +02:00
}
2017-02-01 19:40:27 +02:00
for _, conflict := range ctx.Config.FPM.Conflicts {
options = append(options, "--conflicts", conflict)
}
2017-01-30 11:54:40 +02:00
// This basically tells fpm to put the binary in the /usr/local/bin
// binary=/usr/local/bin/binary
2017-01-30 01:55:32 +02:00
options = append(options, name+"="+filepath.Join("/usr/local/bin", name))
2017-01-30 02:33:08 +02:00
2017-02-01 19:40:27 +02:00
if out, err := exec.Command("fpm", options...).CombinedOutput(); err != nil {
2017-01-30 12:17:15 +02:00
return errors.New(string(out))
2017-01-30 01:55:32 +02:00
}
ctx.AddArtifact(file)
2017-01-30 01:55:32 +02:00
return nil
}