From 5193680e76a3448d268bc725fc802cf0ad4db488 Mon Sep 17 00:00:00 2001 From: Joseph Wright Date: Mon, 6 Nov 2017 05:27:44 +0000 Subject: [PATCH] feat: Allow overriding fpm destination for binaries Some packagers may want to put binaries in a location other than /usr/local/bin. This allows one to override the destination for binaries when using fpm, using the `fpm.bindir` config key. --- config/config.go | 1 + docs/100-fpm.md | 3 +++ pipeline/fpm/fpm.go | 9 +++++++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/config/config.go b/config/config.go index eeb587a1b..87d6d18a8 100644 --- a/config/config.go +++ b/config/config.go @@ -137,6 +137,7 @@ type FPM struct { Maintainer string `yaml:",omitempty"` Description string `yaml:",omitempty"` License string `yaml:",omitempty"` + Bindir string `yaml:",omitempty"` Files map[string]string `yaml:",omitempty"` // Capture all undefined fields and should be empty after loading diff --git a/docs/100-fpm.md b/docs/100-fpm.md index d1e721cf6..d5b531a7a 100644 --- a/docs/100-fpm.md +++ b/docs/100-fpm.md @@ -43,6 +43,9 @@ fpm: - svn - bash + # Override default /usr/local/bin destination for binaries + bindir: /usr/bin + # Files or directories to add to your package (beyond the binary). # Keys are source paths to get the files from. # Values are the destination locations of the files in the package. diff --git a/pipeline/fpm/fpm.go b/pipeline/fpm/fpm.go index 97becb096..09149751e 100644 --- a/pipeline/fpm/fpm.go +++ b/pipeline/fpm/fpm.go @@ -75,8 +75,13 @@ func create(ctx *context.Context, format, folder, arch string, binaries []contex log.WithField("file", file).WithField("workdir", dir).Info("creating fpm archive") var options = basicOptions(ctx, dir, format, arch, file) + bindir := "/usr/local/bin" + if ctx.Config.FPM.Bindir != "" { + bindir = ctx.Config.FPM.Bindir + } + for _, binary := range binaries { - // This basically tells fpm to put the binary in the /usr/local/bin + // This basically tells fpm to put the binary in the bindir, e.g. /usr/local/bin // binary=/usr/local/bin/binary log.WithField("path", binary.Path). WithField("name", binary.Name). @@ -84,7 +89,7 @@ func create(ctx *context.Context, format, folder, arch string, binaries []contex options = append(options, fmt.Sprintf( "%s=%s", binary.Path, - filepath.Join("/usr/local/bin", binary.Name), + filepath.Join(bindir, binary.Name), )) }