mirror of
https://github.com/goreleaser/nfpm
synced 2024-05-04 19:16:14 +02:00
feat: add zstd compression support for deb and rpm (#611)
This commit is contained in:
parent
47e48a17a0
commit
d56fbe2958
|
@ -135,7 +135,7 @@ func TestUpgrade(t *testing.T) {
|
||||||
func TestRPMCompression(t *testing.T) {
|
func TestRPMCompression(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
format := "rpm"
|
format := "rpm"
|
||||||
compressFormats := []string{"gzip", "xz", "lzma"}
|
compressFormats := []string{"gzip", "xz", "lzma", "zstd"}
|
||||||
for _, arch := range formatArchs[format] {
|
for _, arch := range formatArchs[format] {
|
||||||
for _, compFormat := range compressFormats {
|
for _, compFormat := range compressFormats {
|
||||||
func(t *testing.T, testCompFormat, testArch string) {
|
func(t *testing.T, testCompFormat, testArch string) {
|
||||||
|
@ -164,7 +164,7 @@ func TestRPMCompression(t *testing.T) {
|
||||||
func TestDebCompression(t *testing.T) {
|
func TestDebCompression(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
format := "deb"
|
format := "deb"
|
||||||
compressFormats := []string{"gzip", "xz", "none"}
|
compressFormats := []string{"gzip", "xz", "zstd", "none"}
|
||||||
for _, arch := range formatArchs[format] {
|
for _, arch := range formatArchs[format] {
|
||||||
for _, compFormat := range compressFormats {
|
for _, compFormat := range compressFormats {
|
||||||
func(t *testing.T, testCompFormat, testArch string) {
|
func(t *testing.T, testCompFormat, testArch string) {
|
||||||
|
@ -173,13 +173,20 @@ func TestDebCompression(t *testing.T) {
|
||||||
if testArch == "ppc64le" && os.Getenv("NO_TEST_PPC64LE") == "true" {
|
if testArch == "ppc64le" && os.Getenv("NO_TEST_PPC64LE") == "true" {
|
||||||
t.Skip("ppc64le arch not supported in pipeline")
|
t.Skip("ppc64le arch not supported in pipeline")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
target := "compression"
|
||||||
|
if testCompFormat == "zstd" {
|
||||||
|
// we can remove this exception as soon as the debian image supports zstd
|
||||||
|
target = "zstdcompression"
|
||||||
|
}
|
||||||
|
|
||||||
accept(t, acceptParms{
|
accept(t, acceptParms{
|
||||||
Name: fmt.Sprintf("%s_compression_%s", testCompFormat, testArch),
|
Name: fmt.Sprintf("%s_compression_%s", testCompFormat, testArch),
|
||||||
Conf: fmt.Sprintf("deb.%s.compression.yaml", testCompFormat),
|
Conf: fmt.Sprintf("deb.%s.compression.yaml", testCompFormat),
|
||||||
Format: format,
|
Format: format,
|
||||||
Docker: dockerParams{
|
Docker: dockerParams{
|
||||||
File: fmt.Sprintf("%s.dockerfile", format),
|
File: fmt.Sprintf("%s.dockerfile", format),
|
||||||
Target: "compression",
|
Target: target,
|
||||||
Arch: testArch,
|
Arch: testArch,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
|
@ -21,6 +21,7 @@ import (
|
||||||
"github.com/goreleaser/nfpm/v2/deprecation"
|
"github.com/goreleaser/nfpm/v2/deprecation"
|
||||||
"github.com/goreleaser/nfpm/v2/files"
|
"github.com/goreleaser/nfpm/v2/files"
|
||||||
"github.com/goreleaser/nfpm/v2/internal/sign"
|
"github.com/goreleaser/nfpm/v2/internal/sign"
|
||||||
|
"github.com/klauspost/compress/zstd"
|
||||||
gzip "github.com/klauspost/pgzip"
|
gzip "github.com/klauspost/pgzip"
|
||||||
"github.com/ulikunitz/xz"
|
"github.com/ulikunitz/xz"
|
||||||
)
|
)
|
||||||
|
@ -312,6 +313,12 @@ func createDataTarball(info *nfpm.Info) (dataTarBall, md5sums []byte,
|
||||||
return nil, nil, 0, "", err
|
return nil, nil, 0, "", err
|
||||||
}
|
}
|
||||||
name = "data.tar.xz"
|
name = "data.tar.xz"
|
||||||
|
case "zstd":
|
||||||
|
dataTarballWriteCloser, err = zstd.NewWriter(&dataTarball)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, 0, "", err
|
||||||
|
}
|
||||||
|
name = "data.tar.zst"
|
||||||
case "none":
|
case "none":
|
||||||
dataTarballWriteCloser = nopCloser{Writer: &dataTarball}
|
dataTarballWriteCloser = nopCloser{Writer: &dataTarball}
|
||||||
name = "data.tar"
|
name = "data.tar"
|
||||||
|
|
|
@ -22,6 +22,7 @@ import (
|
||||||
"github.com/goreleaser/nfpm/v2"
|
"github.com/goreleaser/nfpm/v2"
|
||||||
"github.com/goreleaser/nfpm/v2/files"
|
"github.com/goreleaser/nfpm/v2/files"
|
||||||
"github.com/goreleaser/nfpm/v2/internal/sign"
|
"github.com/goreleaser/nfpm/v2/internal/sign"
|
||||||
|
"github.com/klauspost/compress/zstd"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"github.com/xi2/xz"
|
"github.com/xi2/xz"
|
||||||
)
|
)
|
||||||
|
@ -1080,6 +1081,7 @@ func TestCompressionAlgorithms(t *testing.T) {
|
||||||
{"", "data.tar.gz"}, // test current default
|
{"", "data.tar.gz"}, // test current default
|
||||||
{"xz", "data.tar.xz"},
|
{"xz", "data.tar.xz"},
|
||||||
{"none", "data.tar"},
|
{"none", "data.tar"},
|
||||||
|
{"zstd", "data.tar.zst"},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, testCase := range testCases {
|
for _, testCase := range testCases {
|
||||||
|
@ -1237,6 +1239,10 @@ func inflate(tb testing.TB, nameOrType string, data []byte) []byte {
|
||||||
r, err := xz.NewReader(dataReader, 0)
|
r, err := xz.NewReader(dataReader, 0)
|
||||||
require.NoError(tb, err)
|
require.NoError(tb, err)
|
||||||
inflateReadCloser = io.NopCloser(r)
|
inflateReadCloser = io.NopCloser(r)
|
||||||
|
case "zst":
|
||||||
|
r, err := zstd.NewReader(dataReader)
|
||||||
|
require.NoError(tb, err)
|
||||||
|
inflateReadCloser = &zstdReadCloser{r}
|
||||||
case "tar", "": // no compression
|
case "tar", "": // no compression
|
||||||
inflateReadCloser = io.NopCloser(dataReader)
|
inflateReadCloser = io.NopCloser(dataReader)
|
||||||
default:
|
default:
|
||||||
|
@ -1413,3 +1419,13 @@ func TestBadProvides(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, string(bts), w.String())
|
require.Equal(t, string(bts), w.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type zstdReadCloser struct {
|
||||||
|
*zstd.Decoder
|
||||||
|
}
|
||||||
|
|
||||||
|
func (zrc *zstdReadCloser) Close() error {
|
||||||
|
zrc.Decoder.Close()
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
|
@ -173,6 +173,20 @@ RUN echo wat >> /etc/foo/whatever.conf
|
||||||
RUN dpkg -r foo
|
RUN dpkg -r foo
|
||||||
RUN test ! -f /usr/bin/fake
|
RUN test ! -f /usr/bin/fake
|
||||||
|
|
||||||
|
# ---- zstdcompression test ----
|
||||||
|
# we can use the regular compression image as
|
||||||
|
# soon as zstd is supported on debian
|
||||||
|
FROM ubuntu AS zstdcompression
|
||||||
|
ARG package
|
||||||
|
RUN echo "${package}"
|
||||||
|
COPY ${package} /tmp/foo.deb
|
||||||
|
RUN dpkg -i /tmp/foo.deb
|
||||||
|
RUN test -e /usr/bin/fake
|
||||||
|
RUN test -f /etc/foo/whatever.conf
|
||||||
|
RUN echo wat >> /etc/foo/whatever.conf
|
||||||
|
RUN dpkg -r foo
|
||||||
|
RUN test ! -f /usr/bin/fake
|
||||||
|
|
||||||
# ---- upgrade test ----
|
# ---- upgrade test ----
|
||||||
FROM test_base AS upgrade
|
FROM test_base AS upgrade
|
||||||
ARG oldpackage
|
ARG oldpackage
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
name: "foo"
|
||||||
|
arch: "${BUILD_ARCH}"
|
||||||
|
platform: "linux"
|
||||||
|
version: "v1.2.3"
|
||||||
|
maintainer: "Foo Bar"
|
||||||
|
description: |
|
||||||
|
Foo bar
|
||||||
|
Multiple lines
|
||||||
|
vendor: "foobar"
|
||||||
|
homepage: "https://foobar.org"
|
||||||
|
license: "MIT"
|
||||||
|
contents:
|
||||||
|
- src: ./testdata/fake
|
||||||
|
dst: /usr/bin/fake
|
||||||
|
- src: ./testdata/whatever.conf
|
||||||
|
dst: /etc/foo/whatever.conf
|
||||||
|
type: config
|
||||||
|
deb:
|
||||||
|
compression: "zstd"
|
|
@ -0,0 +1,19 @@
|
||||||
|
name: "foo"
|
||||||
|
arch: "${BUILD_ARCH}"
|
||||||
|
platform: "linux"
|
||||||
|
version: "v1.2.3"
|
||||||
|
maintainer: "Foo Bar"
|
||||||
|
description: |
|
||||||
|
Foo bar
|
||||||
|
Multiple lines
|
||||||
|
vendor: "foobar"
|
||||||
|
homepage: "https://foobar.org"
|
||||||
|
license: "MIT"
|
||||||
|
contents:
|
||||||
|
- src: ./testdata/fake
|
||||||
|
dst: /usr/bin/fake
|
||||||
|
- src: ./testdata/whatever.conf
|
||||||
|
dst: /etc/foo/whatever.conf
|
||||||
|
type: config
|
||||||
|
rpm:
|
||||||
|
compression: "zstd"
|
|
@ -298,8 +298,8 @@ rpm:
|
||||||
# This will expand any env var you set in the field, e.g. packager: ${PACKAGER}
|
# This will expand any env var you set in the field, e.g. packager: ${PACKAGER}
|
||||||
packager: GoReleaser <staff@goreleaser.com>
|
packager: GoReleaser <staff@goreleaser.com>
|
||||||
|
|
||||||
# Compression algorithm (gzip (default), lzma or xz).
|
# Compression algorithm (gzip (default), zstd, lzma or xz).
|
||||||
compression: lzma
|
compression: zstd
|
||||||
|
|
||||||
# The package is signed if a key_file is set
|
# The package is signed if a key_file is set
|
||||||
signature:
|
signature:
|
||||||
|
@ -349,8 +349,8 @@ deb:
|
||||||
breaks:
|
breaks:
|
||||||
- some-package
|
- some-package
|
||||||
|
|
||||||
# Compression algorithm (gzip (default), xz or none).
|
# Compression algorithm (gzip (default), zstd, xz or none).
|
||||||
compression: xz
|
compression: zstd
|
||||||
|
|
||||||
# The package is signed if a key_file is set
|
# The package is signed if a key_file is set
|
||||||
signature:
|
signature:
|
||||||
|
|
Loading…
Reference in New Issue