Repository: goreleaser/nfpm
Pull request #56 (2019-06-20 07:30:34)

add support for build rpm packages for aarch64
Signed-off-by: Christoph Hartmann <chris@lollyrock.com>

Rhel/Fedora use `aarch64` instead of `arm64`.

Reference:
- https://fedoraproject.org/wiki/Architectures/ARM#Introduction

codecov-io: # [Codecov](https://codecov.io/gh/goreleaser/nfpm/pull/56?src=pr&el=h1) Report
> Merging [#56](https://codecov.io/gh/goreleaser/nfpm/pull/56?src=pr&el=desc) into [master](https://codecov.io/gh/goreleaser/nfpm/commit/8fedf987c4eed529bc8a216ca2a0193e4da480c0?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `n/a`.

[![Impacted file tree graph](https://codecov.io/gh/goreleaser/nfpm/pull/56/graphs/tree.svg?width=650&token=9QKGIxn7wg&height=150&src=pr)](https://codecov.io/gh/goreleaser/nfpm/pull/56?src=pr&el=tree)

```diff
@@           Coverage Diff           @@
##           master      #56   +/-   ##
=======================================
  Coverage   71.39%   71.39%           
=======================================
  Files           5        5           
  Lines         493      493           
=======================================
  Hits          352      352           
  Misses         87       87           
  Partials       54       54
```


| [Impacted Files](https://codecov.io/gh/goreleaser/nfpm/pull/56?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [rpm/rpm.go](https://codecov.io/gh/goreleaser/nfpm/pull/56/diff?src=pr&el=tree#diff-cnBtL3JwbS5nbw==) | `72.61% <ø> (ø)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/goreleaser/nfpm/pull/56?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/goreleaser/nfpm/pull/56?src=pr&el=footer). Last update [8fedf98...d9c3598](https://codecov.io/gh/goreleaser/nfpm/pull/56?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

chris-rock: @caarlos0 Of course, I was not sure what you would need. Is there any prior art that I should follow?
caarlos0: > @caarlos0 Of course, I was not sure what you would need. Is there any prior art that I should follow?

there is an [acceptance](https://github.com/goreleaser/nfpm/tree/master/acceptance) folder with some tests for both rpm and deb... I'm not sure we can simulate this with docker, but in case we do that's the "real tests"

for the  `archToRPM` specifically I think there are some tests on `rpm_test.go`

Thanks for the contribution!
chris-rock: @caarlos0 I apologize it took so long. I added acceptance tests for arm64 (deb + rpm)
caarlos0: awesome, thanks!

Patch:
diff --git a/.travis.yml b/.travis.yml
index fc0b9d1..c8bca05 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,4 +1,6 @@
-addons:
+# acceptance does not work with current default trusty
+dist: xenial
+addons:     
   apt:
     packages:
     - rpm
@@ -6,6 +8,8 @@ language: go
 go: '1.12.x'
 services:
   - docker
+before_install:
+  - sudo docker run --privileged linuxkit/binfmt:v0.7
 install:
   - make setup
 before_script:
diff --git a/rpm/rpm.go b/rpm/rpm.go
index 7331782..d40195e 100644
--- a/rpm/rpm.go
+++ b/rpm/rpm.go
@@ -37,14 +37,20 @@ type RPM struct{}
 var archToRPM = map[string]string{
 	"amd64": "x86_64",
 	"386":   "i386",
+	"arm64": "aarch64",
 }
 
-// Package writes a new RPM package to the given writer using the given info
-func (*RPM) Package(info nfpm.Info, w io.Writer) error {
+func ensureValidArch(info nfpm.Info) nfpm.Info {
 	arch, ok := archToRPM[info.Arch]
 	if ok {
 		info.Arch = arch
 	}
+	return info
+}
+
+// Package writes a new RPM package to the given writer using the given info
+func (*RPM) Package(info nfpm.Info, w io.Writer) error {
+	info = ensureValidArch(info)
 	info.Version = strings.Replace(info.Version, "-", "_", -1)
 	_, err := exec.LookPath("rpmbuild")
 	if err != nil {


Test patch:
diff --git a/acceptance/acceptance_test.go b/acceptance/acceptance_test.go
index 48eaf33..15f2b3c 100644
--- a/acceptance/acceptance_test.go
+++ b/acceptance/acceptance_test.go
@@ -49,6 +49,15 @@ func TestSimple(t *testing.T) {
 				Dockerfile: fmt.Sprintf("%s.ppc64le.dockerfile", format),
 			})
 		})
+		t.Run("arm64", func(t *testing.T) {
+			t.Parallel()
+			accept(t, acceptParms{
+				Name:       fmt.Sprintf("simple_%s_arm64", format),
+				Conf:       "simple.arm64.yaml",
+				Format:     format,
+				Dockerfile: fmt.Sprintf("%s.arm64.dockerfile", format),
+			})
+		})
 	}
 }
 
diff --git a/acceptance/testdata/deb.arm64.dockerfile b/acceptance/testdata/deb.arm64.dockerfile
new file mode 100644
index 0000000..683e89c
--- /dev/null
+++ b/acceptance/testdata/deb.arm64.dockerfile
@@ -0,0 +1,10 @@
+FROM arm64v8/ubuntu
+ARG package
+COPY ${package} /tmp/foo.deb
+RUN dpkg -i /tmp/foo.deb
+RUN test -e /usr/local/bin/fake
+RUN test -f /etc/foo/whatever.conf
+RUN echo wat >> /etc/foo/whatever.conf
+RUN dpkg -r foo
+RUN test -f /etc/foo/whatever.conf
+RUN test ! -f /usr/local/bin/fake
diff --git a/acceptance/testdata/rpm.arm64.dockerfile b/acceptance/testdata/rpm.arm64.dockerfile
new file mode 100644
index 0000000..24550c4
--- /dev/null
+++ b/acceptance/testdata/rpm.arm64.dockerfile
@@ -0,0 +1,10 @@
+FROM arm64v8/centos
+ARG package
+COPY ${package} /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
diff --git a/acceptance/testdata/simple.arm64.yaml b/acceptance/testdata/simple.arm64.yaml
new file mode 100644
index 0000000..0ad2bec
--- /dev/null
+++ b/acceptance/testdata/simple.arm64.yaml
@@ -0,0 +1,15 @@
+name: "foo"
+arch: "arm64"
+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/rpm/rpm_test.go b/rpm/rpm_test.go
index 0dce7e6..a0950f5 100644
--- a/rpm/rpm_test.go
+++ b/rpm/rpm_test.go
@@ -189,3 +189,13 @@ func TestParseRpmbuildVersionError(t *testing.T) {
 		})
 	}
 }
+
+func TestRPMMultiArch(t *testing.T) {
+	info := exampleInfo()
+
+	for k := range archToRPM {
+		info.Arch = k
+		info = ensureValidArch(info)
+		assert.Equal(t, archToRPM[k], info.Arch)
+	}
+}