Skip to content

Commit

Permalink
Merge pull request #22 from goreleaser/arch
Browse files Browse the repository at this point in the history
fix: arch map for debian/rpm packages
  • Loading branch information
caarlos0 committed Mar 23, 2018
2 parents 9626479 + 5b49758 commit abbeff9
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 45 deletions.
14 changes: 12 additions & 2 deletions acceptance/deb_acceptance_test.go
Expand Up @@ -3,9 +3,19 @@ package acceptance
import "testing"

func TestSimpleDeb(t *testing.T) {
accept(t, "simple_deb", "simple.yaml", "deb", "deb.dockerfile")
t.Run("amd64", func(t *testing.T) {
accept(t, "simple_deb", "simple.yaml", "deb", "deb.dockerfile")
})
t.Run("i386", func(t *testing.T) {
accept(t, "simple_deb_386", "simple.386.yaml", "deb", "deb.386.dockerfile")
})
}

func TestComplexDeb(t *testing.T) {
accept(t, "complex_deb", "complex.yaml", "deb", "deb.dockerfile")
t.Run("amd64", func(t *testing.T) {
accept(t, "complex_deb", "complex.yaml", "deb", "deb.dockerfile")
})
t.Run("i386", func(t *testing.T) {
accept(t, "complex_deb_386", "complex.386.yaml", "deb", "deb.386.dockerfile")
})
}
14 changes: 12 additions & 2 deletions acceptance/rpm_acceptance_test.go
Expand Up @@ -3,9 +3,19 @@ package acceptance
import "testing"

func TestSimpleRPM(t *testing.T) {
accept(t, "simple_rpm", "simple.yaml", "rpm", "rpm.dockerfile")
t.Run("amd64", func(t *testing.T) {
accept(t, "simple_rpm", "simple.yaml", "rpm", "rpm.dockerfile")
})
t.Run("i386", func(t *testing.T) {
accept(t, "simple_rpm_386", "simple.386.yaml", "rpm", "rpm.386.dockerfile")
})
}

func TestComplexRPM(t *testing.T) {
accept(t, "complex_rpm", "complex.yaml", "rpm", "rpm.dockerfile")
t.Run("amd64", func(t *testing.T) {
accept(t, "complex_rpm", "complex.yaml", "rpm", "rpm.dockerfile")
})
t.Run("i386", func(t *testing.T) {
accept(t, "complex_rpm_386", "complex.386.yaml", "rpm", "rpm.386.dockerfile")
})
}
23 changes: 23 additions & 0 deletions acceptance/testdata/complex.386.yaml
@@ -0,0 +1,23 @@
name: "foo"
arch: "386"
platform: "linux"
version: "v1.2.3"
maintainer: "Foo Bar"
depends:
- bash
provides:
- fake
replaces:
- foo
suggests:
- zsh
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"
10 changes: 10 additions & 0 deletions acceptance/testdata/deb.386.dockerfile
@@ -0,0 +1,10 @@
FROM i386/ubuntu
ARG package
COPY ${package} /tmp/foo.deb
RUN dpkg -i /tmp/foo.deb && \
test -e /usr/local/bin/fake && \
test -f /etc/foo/whatever.conf && \
echo wat >> /etc/foo/whatever.conf && \
dpkg -r foo && \
test -f /etc/foo/whatever.conf && \
test ! -f /usr/local/bin/fake
10 changes: 10 additions & 0 deletions acceptance/testdata/rpm.386.dockerfile
@@ -0,0 +1,10 @@
FROM i386/centos:6
ARG package
COPY ${package} /tmp/foo.rpm
RUN rpm -ivh /tmp/foo.rpm && \
test -e /usr/local/bin/fake && \
test -f /etc/foo/whatever.conf && \
echo wat >> /etc/foo/whatever.conf && \
rpm -e foo && \
test -f /etc/foo/whatever.conf.rpmsave && \
test ! -f /usr/local/bin/fake
15 changes: 15 additions & 0 deletions acceptance/testdata/simple.386.yaml
@@ -0,0 +1,15 @@
name: "foo"
arch: "386"
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"
10 changes: 10 additions & 0 deletions deb/deb.go
Expand Up @@ -24,6 +24,12 @@ func init() {
nfpm.Register("deb", Default)
}

var goarchToDebian = map[string]string{
"386": "i386",
"arm": "armhf",
"mipsle": "mipsel",
}

// Default deb packager
var Default = &Deb{}

Expand All @@ -32,6 +38,10 @@ type Deb struct{}

// Package writes a new deb package to the given writer using the given info
func (*Deb) Package(info nfpm.Info, deb io.Writer) (err error) {
arch, ok := goarchToDebian[info.Arch]
if ok {
info.Arch = arch
}
dataTarGz, md5sums, instSize, err := createDataTarGz(info)
if err != nil {
return err
Expand Down
86 changes: 47 additions & 39 deletions deb/deb_test.go
Expand Up @@ -13,52 +13,60 @@ import (

var update = flag.Bool("update", false, "update .golden files")

var info = nfpm.WithDefaults(nfpm.Info{
Name: "foo",
Arch: "amd64",
Depends: []string{
"bash",
},
Recommends: []string{
"git",
},
Suggests: []string{
"bash",
},
Replaces: []string{
"svn",
},
Provides: []string{
"bzr",
},
Conflicts: []string{
"zsh",
},
Description: "Foo does things",
Priority: "extra",
Maintainer: "Carlos A Becker <pkg@carlosbecker.com>",
Version: "v1.0.0",
Section: "default",
Homepage: "http://carlosbecker.com",
Vendor: "nope",
Files: map[string]string{
"../testdata/fake": "/usr/local/bin/fake",
"../testdata/whatever.conf": "/usr/share/doc/fake/fake.txt",
},
ConfigFiles: map[string]string{
"../testdata/whatever.conf": "/etc/fake/fake.conf",
},
})
func exampleInfo() nfpm.Info {
return nfpm.WithDefaults(nfpm.Info{
Name: "foo",
Arch: "amd64",
Depends: []string{
"bash",
},
Recommends: []string{
"git",
},
Suggests: []string{
"bash",
},
Replaces: []string{
"svn",
},
Provides: []string{
"bzr",
},
Conflicts: []string{
"zsh",
},
Description: "Foo does things",
Priority: "extra",
Maintainer: "Carlos A Becker <pkg@carlosbecker.com>",
Version: "v1.0.0",
Section: "default",
Homepage: "http://carlosbecker.com",
Vendor: "nope",
Files: map[string]string{
"../testdata/fake": "/usr/local/bin/fake",
"../testdata/whatever.conf": "/usr/share/doc/fake/fake.txt",
},
ConfigFiles: map[string]string{
"../testdata/whatever.conf": "/etc/fake/fake.conf",
},
})
}

func TestDeb(t *testing.T) {
var err = Default.Package(info, ioutil.Discard)
assert.NoError(t, err)
for _, arch := range []string{"386", "amd64"} {
t.Run(arch, func(t *testing.T) {
info := exampleInfo()
info.Arch = arch
var err = Default.Package(info, ioutil.Discard)
assert.NoError(t, err)
})
}
}

func TestControl(t *testing.T) {
var w bytes.Buffer
assert.NoError(t, writeControl(&w, controlData{
Info: info,
Info: exampleInfo(),
InstalledSize: 10,
}))
var golden = "testdata/control.golden"
Expand Down
10 changes: 8 additions & 2 deletions rpm/rpm.go
Expand Up @@ -24,6 +24,11 @@ func init() {
nfpm.Register("rpm", Default)
}

var goarchToRPM = map[string]string{
"amd64": "x86_64",
"386": "i386",
}

// Default deb packager
var Default = &RPM{}

Expand All @@ -32,8 +37,9 @@ type RPM struct{}

// Package writes a new RPM package to the given writer using the given info
func (*RPM) Package(info nfpm.Info, w io.Writer) error {
if info.Arch == "amd64" {
info.Arch = "x86_64"
arch, ok := goarchToRPM[info.Arch]
if ok {
info.Arch = arch
}
_, err := exec.LookPath("rpmbuild")
if err != nil {
Expand Down

0 comments on commit abbeff9

Please sign in to comment.