Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add nfpm meta mackages #1620

Merged
merged 3 commits into from Jun 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 10 additions & 6 deletions internal/pipe/nfpm/nfpm.go
Expand Up @@ -133,12 +133,15 @@ func create(ctx *context.Context, fpm config.NFPM, format, arch string, binaries
for k, v := range overridden.Files {
files[k] = v
}
var log = log.WithField("package", name+"."+format).WithField("arch", arch)
for _, binary := range binaries {
src := binary.Path
dst := filepath.Join(fpm.Bindir, binary.Name)
log.WithField("src", src).WithField("dst", dst).Debug("adding binary to package")
files[src] = dst
// FPM meta package should not contain binaries at all
if !fpm.Meta {
var log = log.WithField("package", name+"."+format).WithField("arch", arch)
for _, binary := range binaries {
src := binary.Path
dst := filepath.Join(fpm.Bindir, binary.Name)
log.WithField("src", src).WithField("dst", dst).Debug("adding binary to package")
files[src] = dst
}
}
log.WithField("files", files).Debug("all archive files")

Expand Down Expand Up @@ -206,6 +209,7 @@ func create(ctx *context.Context, fpm config.NFPM, format, arch string, binaries
"Builds": binaries,
"ID": fpm.ID,
"Format": format,
"Files": files,
},
})
return nil
Expand Down
90 changes: 90 additions & 0 deletions internal/pipe/nfpm/nfpm_test.go
Expand Up @@ -362,3 +362,93 @@ func TestSeveralNFPMsWithTheSameID(t *testing.T) {
}
require.EqualError(t, Pipe{}.Default(ctx), "found 2 nfpms with the ID 'a', please fix your config")
}

func TestMeta(t *testing.T) {
folder, err := ioutil.TempDir("", "archivetest")
require.NoError(t, err)
var dist = filepath.Join(folder, "dist")
require.NoError(t, os.Mkdir(dist, 0755))
require.NoError(t, os.Mkdir(filepath.Join(dist, "mybin"), 0755))
var binPath = filepath.Join(dist, "mybin", "mybin")
_, err = os.Create(binPath)
require.NoError(t, err)
var ctx = context.New(config.Project{
ProjectName: "mybin",
Dist: dist,
NFPMs: []config.NFPM{
{
ID: "someid",
Bindir: "/usr/bin",
Builds: []string{"default"},
Formats: []string{"deb", "rpm"},
Description: "Some description",
License: "MIT",
Maintainer: "me@me",
Vendor: "asdf",
Homepage: "https://goreleaser.github.io",
Meta: true,
NFPMOverridables: config.NFPMOverridables{
FileNameTemplate: defaultNameTemplate + "-{{ .Release }}-{{ .Epoch }}",
PackageName: "foo",
Dependencies: []string{"make"},
Recommends: []string{"svn"},
Suggests: []string{"bzr"},
Conflicts: []string{"git"},
EmptyFolders: []string{"/var/log/foobar"},
Release: "10",
Epoch: "20",
Files: map[string]string{
"./testdata/testfile.txt": "/usr/share/testfile.txt",
},
ConfigFiles: map[string]string{
"./testdata/testfile.txt": "/etc/nope.conf",
},
Replacements: map[string]string{
"linux": "Tux",
},
},
Overrides: map[string]config.NFPMOverridables{
"rpm": {
ConfigFiles: map[string]string{
"./testdata/testfile.txt": "/etc/nope-rpm.conf",
},
},
},
},
},
})
ctx.Version = "1.0.0"
ctx.Git = context.GitInfo{CurrentTag: "v1.0.0"}
for _, goos := range []string{"linux", "darwin"} {
for _, goarch := range []string{"amd64", "386"} {
ctx.Artifacts.Add(&artifact.Artifact{
Name: "mybin",
Path: binPath,
Goarch: goarch,
Goos: goos,
Type: artifact.Binary,
Extra: map[string]interface{}{
"ID": "default",
},
})
}
}
require.NoError(t, Pipe{}.Run(ctx))
var packages = ctx.Artifacts.Filter(artifact.ByType(artifact.LinuxPackage)).List()
require.Len(t, packages, 4)
for _, pkg := range packages {
var format = pkg.ExtraOr("Format", "").(string)
require.NotEmpty(t, format)
require.Equal(t, pkg.Name, "mybin_1.0.0_Tux_"+pkg.Goarch+"-10-20."+format)
require.Equal(t, pkg.ExtraOr("ID", ""), "someid")
}
require.Len(t, ctx.Config.NFPMs[0].Files, 1, "should not modify the config file list")

// ensure that no binaries added
for _, pkg := range packages {
files := pkg.ExtraOr("Files", map[string]string{}).(map[string]string)
for _, dest := range files {
require.NotEqual(t, "/usr/bin/mybin", dest, "binary file should not be added")
}
}
}
1 change: 1 addition & 0 deletions pkg/config/config.go
Expand Up @@ -286,6 +286,7 @@ type NFPM struct {
Description string `yaml:",omitempty"`
License string `yaml:",omitempty"`
Bindir string `yaml:",omitempty"`
Meta bool `yaml:",omitempty"` // make package without binaries - only deps
}

// NFPMScripts is used to specify maintainer scripts.
Expand Down
5 changes: 5 additions & 0 deletions www/docs/customization/nfpm.md
Expand Up @@ -95,6 +95,11 @@ nfpms:
# Defaults to empty.
release: 1

# Makes a meta package - an empty package that contains only supporting files and dependencies.
# When set to `true`, the `builds` option is ignored.
# Defaults to false.
meta: true

# Empty folders that should be created and managed by the packager
# implementation.
# Default is empty.
Expand Down