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 BuildHost option to RPM packages #914

Merged
merged 1 commit into from
Mar 13, 2025
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions nfpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ type ArchLinuxScripts struct {
// RPM is custom configs that are only available on RPM packages.
type RPM struct {
Arch string `yaml:"arch,omitempty" json:"arch,omitempty" jsonschema:"title=architecture in rpm nomenclature"`
BuildHost string `yaml:"buildhost,omitempty" json:"buildhost,omitempty" jsonschema:"title=host name of the build environment, default=os.Hostname()"`
Scripts RPMScripts `yaml:"scripts,omitempty" json:"scripts,omitempty" jsonschema:"title=rpm-specific scripts"`
Group string `yaml:"group,omitempty" json:"group,omitempty" jsonschema:"title=package group,example=Unspecified"`
Summary string `yaml:"summary,omitempty" json:"summary,omitempty" jsonschema:"title=package summary"`
Expand Down
9 changes: 6 additions & 3 deletions rpm/rpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,12 @@ func buildRPMMeta(info *nfpm.Info) (*rpmpack.RPMMetaData, error) {
return nil, err
}

hostname, err := os.Hostname()
if err != nil {
return nil, err
hostname := info.RPM.BuildHost
if hostname == "" {
hostname, err = os.Hostname()
if err != nil {
return nil, err
}
}

return &rpmpack.RPMMetaData{
Expand Down
9 changes: 7 additions & 2 deletions rpm/rpm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ func exampleInfo() *nfpm.Info {
PostRemove: "../testdata/scripts/postremove.sh",
},
RPM: nfpm.RPM{
Group: "foo",
Prefixes: []string{"/opt"},
Group: "foo",
BuildHost: "barhost",
Prefixes: []string{"/opt"},
Scripts: nfpm.RPMScripts{
PreTrans: "../testdata/scripts/pretrans.sh",
PostTrans: "../testdata/scripts/posttrans.sh",
Expand Down Expand Up @@ -139,6 +140,10 @@ func TestRPM(t *testing.T) {
require.NoError(t, err)
require.Equal(t, "foo", group)

buildhost, err := rpm.Header.GetString(rpmutils.BUILDHOST)
require.NoError(t, err)
require.Equal(t, "barhost", buildhost)

summary, err := rpm.Header.GetString(rpmutils.SUMMARY)
require.NoError(t, err)
require.Equal(t, "Foo does things", summary)
Expand Down
4 changes: 4 additions & 0 deletions www/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,10 @@ rpm:
# This will expand any env var you set in the field, e.g. packager: ${PACKAGER}
packager: GoReleaser <[email protected]>

# The hostname of the machine the rpm was built with. If ommited os.Hostname()
# will be used.
buildhost: buildserver1

# Compression algorithm (gzip (default), zstd, lzma or xz).
compression: zstd

Expand Down
Loading