Skip to content

Commit e42ce46

Browse files
author
onshorechet
committed
feat: Add BuildHost option to RPM packages
This commit adds the BuildHost option to the RPM specific configurations. If the build host is not provided it will default to os.Hostname() which is the previous behavior. This allows reproduce-able builds when the build environment spans multiple hosts.
1 parent 00e6b7e commit e42ce46

File tree

5 files changed

+783
-766
lines changed

5 files changed

+783
-766
lines changed

nfpm.go

+1
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ type ArchLinuxScripts struct {
377377
// RPM is custom configs that are only available on RPM packages.
378378
type RPM struct {
379379
Arch string `yaml:"arch,omitempty" json:"arch,omitempty" jsonschema:"title=architecture in rpm nomenclature"`
380+
BuildHost string `yaml:"buildhost,omitempty" json:"buildhost,omitempty" jsonschema:"title=host name of the build environment, default=os.Hostname()"`
380381
Scripts RPMScripts `yaml:"scripts,omitempty" json:"scripts,omitempty" jsonschema:"title=rpm-specific scripts"`
381382
Group string `yaml:"group,omitempty" json:"group,omitempty" jsonschema:"title=package group,example=Unspecified"`
382383
Summary string `yaml:"summary,omitempty" json:"summary,omitempty" jsonschema:"title=package summary"`

rpm/rpm.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,12 @@ func buildRPMMeta(info *nfpm.Info) (*rpmpack.RPMMetaData, error) {
235235
return nil, err
236236
}
237237

238-
hostname, err := os.Hostname()
239-
if err != nil {
240-
return nil, err
238+
hostname := info.RPM.BuildHost
239+
if hostname == "" {
240+
hostname, err = os.Hostname()
241+
if err != nil {
242+
return nil, err
243+
}
241244
}
242245

243246
return &rpmpack.RPMMetaData{

rpm/rpm_test.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,9 @@ func exampleInfo() *nfpm.Info {
8080
PostRemove: "../testdata/scripts/postremove.sh",
8181
},
8282
RPM: nfpm.RPM{
83-
Group: "foo",
84-
Prefixes: []string{"/opt"},
83+
Group: "foo",
84+
BuildHost: "barhost",
85+
Prefixes: []string{"/opt"},
8586
Scripts: nfpm.RPMScripts{
8687
PreTrans: "../testdata/scripts/pretrans.sh",
8788
PostTrans: "../testdata/scripts/posttrans.sh",
@@ -139,6 +140,10 @@ func TestRPM(t *testing.T) {
139140
require.NoError(t, err)
140141
require.Equal(t, "foo", group)
141142

143+
buildhost, err := rpm.Header.GetString(rpmutils.BUILDHOST)
144+
require.NoError(t, err)
145+
require.Equal(t, "barhost", buildhost)
146+
142147
summary, err := rpm.Header.GetString(rpmutils.SUMMARY)
143148
require.NoError(t, err)
144149
require.Equal(t, "Foo does things", summary)

www/docs/configuration.md

+4
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,10 @@ rpm:
351351
# This will expand any env var you set in the field, e.g. packager: ${PACKAGER}
352352
packager: GoReleaser <[email protected]>
353353

354+
# The hostname of the machine the rpm was built with. If ommited os.Hostname()
355+
# will be used.
356+
buildhost: buildserver1
357+
354358
# Compression algorithm (gzip (default), zstd, lzma or xz).
355359
compression: zstd
356360

0 commit comments

Comments
 (0)