Help us shape the future of Go! Take the 2026 Go Developer Survey

nfpm

package module
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: May 29, 2020 License: MIT Imports: 12 Imported by: 27

README

GoReleaser Logo

NFPM

NFPM is Not FPM - a simple deb and rpm packager written in Go.

Release Software License GitHub Actions Codecov branch Go Report Card Go Doc

Why

While fpm is great, for me it is a bummer that it depends on Ruby, tar and probably other software.

I wanted something that could be used as a binary and/or as a lib on go-software, so I hacked this together and it works!

Goals

  • be simple to use
  • provide packaging for the most common linux packaging systems (at very least deb and rpm)
  • be distributed as a single binary
  • reproducible results
    • depend on the fewer external things as possible
    • generate packages based on yaml files (maybe also json and toml?)
  • be possible to use it as a lib in other go projects (namely goreleaser itself)
  • support complex packages and power users

Usage

The first steps are to run nfpm init to initialize a config file and edit the generated file according to your needs:

nfpm init

The next step is to run nfpm pkg --target mypkg.deb. NFPM will guess which packager to use based on the target file extension.

nfpm pkg

And that's it!

Usage as a docker image

You can run it with docker as well:

docker run --rm \
  -v $PWD:/tmp/pkg \
  goreleaser/nfpm pkg --config /tmp/pkg/foo.yml --target /tmp/pkg/foo.rpm

That's it!

Usage as lib

You can look at the code of nfpm itself to see how to use it as a library, or, take a look at the nfpm pipe on GoReleaser.

Attention: GoReleaser deb packager only compiles with go1.10+.

Status

  • both deb and rpm packaging are working but there are some missing features.

Special thanks

Thanks to the fpm authors for fpm, which inspires nfpm a lot.

Donate

Donations are very much appreciated! You can donate/sponsor on the main goreleaser opencollective! It's easy and will surely help the developers at least buy some ☕️ or 🍺!

Stargazers over time

goreleaser/nfpm stargazers over time


Would you like to fix something in the documentation? Feel free to open an issue.

Documentation

Overview

Package nfpm provides ways to package programs in some linux packaging formats.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(format string, p Packager)

Register a new packager for the given format.

func Validate added in v0.6.3

func Validate(info *Info) error

Validate the given Info and returns an error if it is invalid.

Types

type Config added in v0.8.0

type Config struct {
	Info      `yaml:",inline"`
	Overrides map[string]Overridables `yaml:"overrides,omitempty"`
}

Config contains the top level configuration for packages.

func Parse added in v0.8.0

func Parse(in io.Reader) (config Config, err error)

Parse decodes YAML data from an io.Reader into a configuration struct.

func ParseFile added in v0.8.0

func ParseFile(path string) (config Config, err error)

ParseFile decodes YAML data from a file path into a configuration struct.

func (*Config) Get added in v0.8.0

func (c *Config) Get(format string) (info *Info, err error)

Get returns the Info struct for the given packager format. Overrides for the given format are merged into the final struct.

func (*Config) Validate added in v0.8.0

func (c *Config) Validate() error

Validate ensures that the config is well typed.

type Deb added in v0.13.0

type Deb struct {
	Scripts         DebScripts `yaml:"scripts,omitempty"`
	VersionMetadata string     `yaml:"metadata,omitempty"`
}

Deb is custom configs that are only available on deb packages.

type DebScripts added in v0.13.0

type DebScripts struct {
	Rules string `yaml:"rules,omitempty"`
}

DebScripts is scripts only available on deb packages.

type ErrFieldEmpty added in v1.3.0

type ErrFieldEmpty struct {
	// contains filtered or unexported fields
}

ErrFieldEmpty happens when some required field is empty.

func (ErrFieldEmpty) Error added in v1.3.0

func (e ErrFieldEmpty) Error() string

type ErrNoPackager added in v1.3.0

type ErrNoPackager struct {
	// contains filtered or unexported fields
}

ErrNoPackager happens when no packager is registered for the given format.

func (ErrNoPackager) Error added in v1.3.0

func (e ErrNoPackager) Error() string

type FileToCopy added in v1.3.0

type FileToCopy struct {
	Source      string
	Destination string
	Config      bool
}

FileToCopy describes the source and destination of one file to copy into a package and whether it is a config file.

type Info

type Info struct {
	Overridables `yaml:",inline"`
	Name         string `yaml:"name,omitempty"`
	Arch         string `yaml:"arch,omitempty"`
	Platform     string `yaml:"platform,omitempty"`
	Epoch        string `yaml:"epoch,omitempty"`
	Version      string `yaml:"version,omitempty"`
	Release      string `yaml:"release,omitempty"`
	Prerelease   string `yaml:"prerelease,omitempty"`
	Section      string `yaml:"section,omitempty"`
	Priority     string `yaml:"priority,omitempty"`
	Maintainer   string `yaml:"maintainer,omitempty"`
	Description  string `yaml:"description,omitempty"`
	Vendor       string `yaml:"vendor,omitempty"`
	Homepage     string `yaml:"homepage,omitempty"`
	License      string `yaml:"license,omitempty"`
	Bindir       string `yaml:"bindir,omitempty"` // Deprecated: this does nothing. TODO: remove.
	Target       string `yaml:"-"`
}

Info contains information about a single package.

func WithDefaults

func WithDefaults(info *Info) *Info

WithDefaults set some sane defaults into the given Info.

func (*Info) FilesToCopy added in v1.3.0

func (info *Info) FilesToCopy() ([]FileToCopy, error)

FilesToCopy lists all of the real files to be copied into the package.

type Overridables added in v0.8.0

type Overridables struct {
	Replaces     []string          `yaml:"replaces,omitempty"`
	Provides     []string          `yaml:"provides,omitempty"`
	Depends      []string          `yaml:"depends,omitempty"`
	Recommends   []string          `yaml:"recommends,omitempty"`
	Suggests     []string          `yaml:"suggests,omitempty"`
	Conflicts    []string          `yaml:"conflicts,omitempty"`
	Files        map[string]string `yaml:"files,omitempty"`
	ConfigFiles  map[string]string `yaml:"config_files,omitempty"`
	EmptyFolders []string          `yaml:"empty_folders,omitempty"`
	Scripts      Scripts           `yaml:"scripts,omitempty"`
	RPM          RPM               `yaml:"rpm,omitempty"`
	Deb          Deb               `yaml:"deb,omitempty"`
}

Overridables contain the field which are overridable in a package.

type Packager

type Packager interface {
	Package(info *Info, w io.Writer) error
}

Packager represents any packager implementation.

func Get

func Get(format string) (Packager, error)

Get a packager for the given format.

type RPM added in v0.13.0

type RPM struct {
	Group       string `yaml:"group,omitempty"`
	Compression string `yaml:"compression,omitempty"`
}

RPM is custom configs that are only available on RPM packages.

type Scripts added in v0.7.0

type Scripts struct {
	PreInstall  string `yaml:"preinstall,omitempty"`
	PostInstall string `yaml:"postinstall,omitempty"`
	PreRemove   string `yaml:"preremove,omitempty"`
	PostRemove  string `yaml:"postremove,omitempty"`
}

Scripts contains information about maintainer scripts for packages.

Directories

Path Synopsis
Package acceptance contains acceptance tests
Package acceptance contains acceptance tests
cmd
nfpm command
Package main contains the main nfpm cli source code.
Package main contains the main nfpm cli source code.
Package deb implements nfpm.Packager providing .deb bindings.
Package deb implements nfpm.Packager providing .deb bindings.
Package glob provides file globbing for use in nfpm.Packager implementations
Package glob provides file globbing for use in nfpm.Packager implementations
internal
helpers
Package helpers provides common helper methods
Package helpers provides common helper methods
Package rpm implements nfpm.Packager providing .rpm bindings using google/rpmpack.
Package rpm implements nfpm.Packager providing .rpm bindings using google/rpmpack.

Jump to

Keyboard shortcuts

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