Skip to content

Commit

Permalink
feat: add zstd compression support for deb and rpm (#611)
Browse files Browse the repository at this point in the history
  • Loading branch information
erikgeiser authored Jan 30, 2023
1 parent 47e48a1 commit d56fbe2
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 7 deletions.
13 changes: 10 additions & 3 deletions acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func TestUpgrade(t *testing.T) {
func TestRPMCompression(t *testing.T) {
t.Parallel()
format := "rpm"
compressFormats := []string{"gzip", "xz", "lzma"}
compressFormats := []string{"gzip", "xz", "lzma", "zstd"}
for _, arch := range formatArchs[format] {
for _, compFormat := range compressFormats {
func(t *testing.T, testCompFormat, testArch string) {
Expand Down Expand Up @@ -164,7 +164,7 @@ func TestRPMCompression(t *testing.T) {
func TestDebCompression(t *testing.T) {
t.Parallel()
format := "deb"
compressFormats := []string{"gzip", "xz", "none"}
compressFormats := []string{"gzip", "xz", "zstd", "none"}
for _, arch := range formatArchs[format] {
for _, compFormat := range compressFormats {
func(t *testing.T, testCompFormat, testArch string) {
Expand All @@ -173,13 +173,20 @@ func TestDebCompression(t *testing.T) {
if testArch == "ppc64le" && os.Getenv("NO_TEST_PPC64LE") == "true" {
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{
Name: fmt.Sprintf("%s_compression_%s", testCompFormat, testArch),
Conf: fmt.Sprintf("deb.%s.compression.yaml", testCompFormat),
Format: format,
Docker: dockerParams{
File: fmt.Sprintf("%s.dockerfile", format),
Target: "compression",
Target: target,
Arch: testArch,
},
})
Expand Down
7 changes: 7 additions & 0 deletions deb/deb.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/goreleaser/nfpm/v2/deprecation"
"github.com/goreleaser/nfpm/v2/files"
"github.com/goreleaser/nfpm/v2/internal/sign"
"github.com/klauspost/compress/zstd"
gzip "github.com/klauspost/pgzip"
"github.com/ulikunitz/xz"
)
Expand Down Expand Up @@ -312,6 +313,12 @@ func createDataTarball(info *nfpm.Info) (dataTarBall, md5sums []byte,
return nil, nil, 0, "", err
}
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":
dataTarballWriteCloser = nopCloser{Writer: &dataTarball}
name = "data.tar"
Expand Down
16 changes: 16 additions & 0 deletions deb/deb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/goreleaser/nfpm/v2"
"github.com/goreleaser/nfpm/v2/files"
"github.com/goreleaser/nfpm/v2/internal/sign"
"github.com/klauspost/compress/zstd"
"github.com/stretchr/testify/require"
"github.com/xi2/xz"
)
Expand Down Expand Up @@ -1080,6 +1081,7 @@ func TestCompressionAlgorithms(t *testing.T) {
{"", "data.tar.gz"}, // test current default
{"xz", "data.tar.xz"},
{"none", "data.tar"},
{"zstd", "data.tar.zst"},
}

for _, testCase := range testCases {
Expand Down Expand Up @@ -1237,6 +1239,10 @@ func inflate(tb testing.TB, nameOrType string, data []byte) []byte {
r, err := xz.NewReader(dataReader, 0)
require.NoError(tb, err)
inflateReadCloser = io.NopCloser(r)
case "zst":
r, err := zstd.NewReader(dataReader)
require.NoError(tb, err)
inflateReadCloser = &zstdReadCloser{r}
case "tar", "": // no compression
inflateReadCloser = io.NopCloser(dataReader)
default:
Expand Down Expand Up @@ -1413,3 +1419,13 @@ func TestBadProvides(t *testing.T) {
require.NoError(t, err)
require.Equal(t, string(bts), w.String())
}

type zstdReadCloser struct {
*zstd.Decoder
}

func (zrc *zstdReadCloser) Close() error {
zrc.Decoder.Close()

return nil
}
14 changes: 14 additions & 0 deletions testdata/acceptance/deb.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,20 @@ RUN echo wat >> /etc/foo/whatever.conf
RUN dpkg -r foo
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 ----
FROM test_base AS upgrade
ARG oldpackage
Expand Down
19 changes: 19 additions & 0 deletions testdata/acceptance/deb.zstd.compression.yaml
Original file line number Diff line number Diff line change
@@ -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"
19 changes: 19 additions & 0 deletions testdata/acceptance/rpm.zstd.compression.yaml
Original file line number Diff line number Diff line change
@@ -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"
8 changes: 4 additions & 4 deletions www/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,8 @@ rpm:
# This will expand any env var you set in the field, e.g. packager: ${PACKAGER}
packager: GoReleaser <staff@goreleaser.com>

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

# The package is signed if a key_file is set
signature:
Expand Down Expand Up @@ -349,8 +349,8 @@ deb:
breaks:
- some-package

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

# The package is signed if a key_file is set
signature:
Expand Down

0 comments on commit d56fbe2

Please sign in to comment.