diff --git a/acceptance/deb_acceptance_test.go b/acceptance/deb_acceptance_test.go index bc99cf04..6c7ba54b 100644 --- a/acceptance/deb_acceptance_test.go +++ b/acceptance/deb_acceptance_test.go @@ -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") + }) } diff --git a/acceptance/rpm_acceptance_test.go b/acceptance/rpm_acceptance_test.go index f0d21281..ed10d9fc 100644 --- a/acceptance/rpm_acceptance_test.go +++ b/acceptance/rpm_acceptance_test.go @@ -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") + }) } diff --git a/acceptance/testdata/complex.386.yaml b/acceptance/testdata/complex.386.yaml new file mode 100644 index 00000000..5f70b199 --- /dev/null +++ b/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" diff --git a/acceptance/testdata/deb.386.dockerfile b/acceptance/testdata/deb.386.dockerfile new file mode 100644 index 00000000..c13faa89 --- /dev/null +++ b/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 diff --git a/acceptance/testdata/rpm.386.dockerfile b/acceptance/testdata/rpm.386.dockerfile new file mode 100644 index 00000000..d72aa6f3 --- /dev/null +++ b/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 diff --git a/acceptance/testdata/simple.386.yaml b/acceptance/testdata/simple.386.yaml new file mode 100644 index 00000000..2cf5d62f --- /dev/null +++ b/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" diff --git a/deb/deb.go b/deb/deb.go index 6f6c7362..a7105ed9 100644 --- a/deb/deb.go +++ b/deb/deb.go @@ -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{} @@ -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 diff --git a/deb/deb_test.go b/deb/deb_test.go index 6dbaf6cb..7636f013 100644 --- a/deb/deb_test.go +++ b/deb/deb_test.go @@ -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 ", - 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 ", + 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" diff --git a/rpm/rpm.go b/rpm/rpm.go index 405f691b..4b156a24 100644 --- a/rpm/rpm.go +++ b/rpm/rpm.go @@ -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{} @@ -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 {