1
1
Fork 0
mirror of https://github.com/goreleaser/nfpm synced 2024-06-08 00:06:13 +02:00

feat: Add option for RPM compression type (#63)

* feat: Add option for RPM compression type

See #62

* test: acceptance test for rpm compression types
This commit is contained in:
Adrian Wennberg 2019-08-23 14:49:04 +01:00 committed by Carlos Alexandro Becker
parent 76d7d4f3ca
commit c17636c028
9 changed files with 115 additions and 2 deletions

View File

@ -115,6 +115,22 @@ func TestMinDeb(t *testing.T) {
}
}
func TestRPMCompression(t *testing.T) {
compressFormats := []string{"gzip", "xz", "lzma"}
for _, format := range compressFormats {
format := format
t.Run(format, func(t *testing.T) {
t.Parallel()
accept(t, acceptParms{
Name: fmt.Sprintf("%s_compression_rpm", format),
Conf: fmt.Sprintf("%s.compression.yaml", format),
Format: "rpm",
Dockerfile: fmt.Sprintf("%s.rpm.compression.dockerfile", format),
})
})
}
}
type acceptParms struct {
Name string
Conf string

View File

@ -0,0 +1,17 @@
name: "foo"
arch: "amd64"
platform: "linux"
version: "v1.2.3"
maintainer: "Foo Bar"
description: |
Foo bar
Multiple lines
vendor: "foobar"
homepage: "https://foobar.org"
license: "MIT"
files:
../testdata/fake: "/usr/local/bin/fake"
config_files:
../testdata/whatever.conf: "/etc/foo/whatever.conf"
rpm:
compression: "gzip"

View File

@ -0,0 +1,11 @@
FROM fedora
ARG package
COPY ${package} /tmp/foo.rpm
RUN test "gzip" = "$(rpm -qp --qf '%{PAYLOADCOMPRESSOR}' /tmp/foo.rpm)"
RUN rpm -ivh /tmp/foo.rpm
RUN test -e /usr/local/bin/fake
RUN test -f /etc/foo/whatever.conf
RUN echo wat >> /etc/foo/whatever.conf
RUN rpm -e foo
RUN test -f /etc/foo/whatever.conf.rpmsave
RUN test ! -f /usr/local/bin/fake

View File

@ -0,0 +1,17 @@
name: "foo"
arch: "amd64"
platform: "linux"
version: "v1.2.3"
maintainer: "Foo Bar"
description: |
Foo bar
Multiple lines
vendor: "foobar"
homepage: "https://foobar.org"
license: "MIT"
files:
../testdata/fake: "/usr/local/bin/fake"
config_files:
../testdata/whatever.conf: "/etc/foo/whatever.conf"
rpm:
compression: "lzma"

View File

@ -0,0 +1,11 @@
FROM fedora
ARG package
COPY ${package} /tmp/foo.rpm
RUN test "lzma" = "$(rpm -qp --qf '%{PAYLOADCOMPRESSOR}' /tmp/foo.rpm)"
RUN rpm -ivh /tmp/foo.rpm
RUN test -e /usr/local/bin/fake
RUN test -f /etc/foo/whatever.conf
RUN echo wat >> /etc/foo/whatever.conf
RUN rpm -e foo
RUN test -f /etc/foo/whatever.conf.rpmsave
RUN test ! -f /usr/local/bin/fake

17
acceptance/testdata/xz.compression.yaml vendored Normal file
View File

@ -0,0 +1,17 @@
name: "foo"
arch: "amd64"
platform: "linux"
version: "v1.2.3"
maintainer: "Foo Bar"
description: |
Foo bar
Multiple lines
vendor: "foobar"
homepage: "https://foobar.org"
license: "MIT"
files:
../testdata/fake: "/usr/local/bin/fake"
config_files:
../testdata/whatever.conf: "/etc/foo/whatever.conf"
rpm:
compression: "xz"

View File

@ -0,0 +1,11 @@
FROM fedora
ARG package
COPY ${package} /tmp/foo.rpm
RUN test "xz" = "$(rpm -qp --qf '%{PAYLOADCOMPRESSOR}' /tmp/foo.rpm)"
RUN rpm -ivh /tmp/foo.rpm
RUN test -e /usr/local/bin/fake
RUN test -f /etc/foo/whatever.conf
RUN echo wat >> /etc/foo/whatever.conf
RUN rpm -e foo
RUN test -f /etc/foo/whatever.conf.rpmsave
RUN test ! -f /usr/local/bin/fake

View File

@ -134,8 +134,9 @@ type Overridables struct {
}
type RPM struct {
Group string `yaml:"group,omitempty"`
Prefix string `yaml:"prefix,omitempty"`
Group string `yaml:"group,omitempty"`
Prefix string `yaml:"prefix,omitempty"`
Compression string `yaml:"compression,omitempty"`
}
// Scripts contains information about maintainer scripts for packages

View File

@ -319,6 +319,18 @@ const specTemplate = `
%define __os_install_post %{_dbpath}/brp-compress
%define _arch {{ .Info.Arch }}
%define _bindir {{ .Info.Bindir }}
{{- if eq .Info.RPM.Compression "gzip"}}
%define _source_payload w9.gzdio
%define _binary_payload w9.gzdio
{{- end}}
{{- if eq .Info.RPM.Compression "xz"}}
%define _source_payload w6.xzdio
%define _binary_payload w6.xzdio
{{- end}}
{{- if eq .Info.RPM.Compression "lzma"}}
%define _source_payload w6.lzdio
%define _binary_payload w6.lzdio
{{- end}}
Name: {{ .Info.Name }}
Summary: {{ first_line .Info.Description }}