italia / publiccode-parser-go

publiccode.yml parser library and validator in Go
European Union Public License 1.2
15 stars 6 forks source link

Dockerfile does not build with arm64 arch #201

Open libremente opened 2 months ago

libremente commented 2 months ago

The current docker image is not compatible with arm64 and the Dockerfile does not build on that same arch. I believe it could be nice to have a multi-platform version to easily run the image also on ARM arch.

I had to switch to the following configuration to make it build:

diff --git a/Dockerfile b/Dockerfile
index f5f2251..1344eaf 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -4,9 +4,9 @@
 #

 # Accept the Go version for the image to be set as a build argument.
-ARG GO_VERSION=1.18-alpine
+ARG GO_VERSION=1.23-alpine

-FROM docker.io/golang:${GO_VERSION} as build
+FROM arm64v8/golang:${GO_VERSION} as build

 WORKDIR /go/src

@@ -14,7 +14,7 @@ COPY . .

 RUN cd publiccode-parser && go build -ldflags="-s -w"

-FROM docker.io/alpine:3
+FROM arm64v8/alpine:3

LMK if you want a PR for a multi-platform build (maybe also via GHA?) or it's a non-issue for you. Thanks!

bfabio commented 4 weeks ago

Dockerfile was meant just for development, as in having a recent enough go compiler.

I'm wondering if we even need it still, given even Debian stable has a backport of go 1.21 (which is the min version anyway, not 1.18 as you correctly spotted). Even if it didn't, the development environment is just a docker run -it golang away plus go build inside it.

I'd go ahead and remove it.

If you were trying to just run the parser on arm64 instead of developing, we have precompiled binaries here: https://github.com/italia/publiccode-parser-go/releases

On the other hand, an arm64 version of the image on Dockerhub is a good idea, in that case the relevant files are Dockerfile.goreleaser and .goreleaser.yml, that's the way we generate the production images.

We need to take a look at this https://goreleaser.com/cookbooks/multi-platform-docker-images/, I personally am not really familiar with the process but it looks feasible.

So:

  1. Trash Dockerfile
  2. Make a multiplatform Docker image or/and multiple images for other platforms

wdyt?