contribsys / faktory

Language-agnostic persistent background job server
https://contribsys.com/faktory/
Other
5.73k stars 227 forks source link

arm64 variant of Docker image? #342

Closed aviflax closed 2 years ago

aviflax commented 3 years ago

Docker image from Docker hub, 1.5.0 (sha256:6cd4409d1ee45745835252549a3c8353cc7c84f0d5b79d921f71f58255f25ddc)

N/A

N/A

$ docker run --rm -it -p 127.0.0.1:7419:7419 -p 127.0.0.1:7420:7420 --platform linux/amd64 contribsys/faktory:latest /faktory -b :7419 -w :7420 -e development
qemu: uncaught target signal 11 (Segmentation fault) - core dumped

No

Yes


Hi, I’m trying to run Faktory locally on my M1 (arm64) Mac via Docker, and I get the above error message. As per docker/for-mac#5123 this is related to the Docker image being built specifically for amd64. Docker uses qemu to emulate amd64 but it doesn’t always work. That issue was closed with the guidance that the best way to support arm64 hosts is to build and publish arm64 variants of the image.

So, I’d just like to suggest that you might want to consider doing so. It might make it easier for people using M1 Macs to try out Faktory.

That said, Docker itself does not yet officially support M1 Macs (it’s a preview release) so I totally understand if you want to wait for the dust to settle a bit.

Thanks!

aviflax commented 3 years ago

Just in case anyone else coming across this issue might find this useful, I can report that installing Faktory on an M1 Mac via Homebrew seems to succeed:

$ brew install contribsys/faktory/faktory
...
$ faktory
Faktory 1.5.0
Copyright © 2021 Contributed Systems LLC
Licensed under the GNU Public License 3.0
I 2021-03-07T02:28:32.631Z Initializing redis storage at /Users/avip/.faktory/db, socket /Users/avip/.faktory/db/redis.sock
I 2021-03-07T02:28:32.644Z Web server now listening at localhost:7420
I 2021-03-07T02:28:32.644Z PID 13999 listening at localhost:7419, press Ctrl-C to stop

Which is excellent!

ezkl commented 3 years ago

@mperham If you're interested in shipping docker images for multiple architectures, this article is a good primer on image manifests and the buildx toolchain.

I just built and ran an arm64 faktory binary and docker image on my M1 Mac Mini using a modified Makefile and Dockerfile. Pretty hacky, but here's a diff:

diff --git a/Dockerfile b/Dockerfile
index 9499324..3731525 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,6 +1,7 @@
 FROM alpine:3.13
+ARG ARCH=amd64
 RUN apk add --no-cache redis ca-certificates socat
-COPY ./faktory /
+COPY ./faktory-$ARCH /faktory

 RUN mkdir -p /root/.faktory/db
 RUN mkdir -p /var/lib/faktory/db
diff --git a/Makefile b/Makefile
index 7f244fc..a7e10e0 100644
--- a/Makefile
+++ b/Makefile
@@ -57,6 +57,21 @@ dimg: xbuild ## Make a Docker image for the current version
        --tag contribsys/faktory:latest \
        .

+dimg-amd64: xbuild ## Make a Docker image for the current version (linux/amd64)
+   #eval $(shell docker-machine env default)
+   docker build \
+       --platform linux/amd64 \
+       --build-arg ARCH=amd64 \
+       --tag contribsys/faktory:$(VERSION)-amd64 \
+       .
+
+dimg-arm64: xbuild ## Make a Docker image for the current version (linux/arm64)
+   docker build\
+       --platform linux/arm64 \
+       --build-arg ARCH=arm64 \
+       --tag contribsys/faktory:$(VERSION)-arm64 \
+       .
+
 drun: ## Run Faktory in a local Docker image, see also "make dimg"
    docker run --rm -it -e "FAKTORY_SKIP_PASSWORD=true" \
        -v faktory-data:/var/lib/faktory \
@@ -96,9 +111,12 @@ cover:
    open coverage.html

 xbuild: clean generate
-   @GOOS=linux GOARCH=amd64 go build -o $(NAME) cmd/faktory/daemon.go
+   @GOOS=linux GOARCH=amd64 go build -o $(NAME)-amd64 cmd/faktory/daemon.go
+   @GOOS=linux GOARCH=arm64 go build -o $(NAME)-arm64 cmd/faktory/daemon.go
    # brew install upx
-   upx -qq ./faktory
+   upx -qq ./faktory-amd64
+   upx -qq ./faktory-arm64

 build: clean generate
    go build -o $(NAME) cmd/faktory/daemon.go
@@ -129,7 +147,7 @@ work: ## Run a simple Ruby worker, see also "make run"

 clean: ## Clean the project, set it up for a new build
    @rm -rf tmp
-   @rm -f main faktory templates.go
+   @rm -f main faktory-amd64 faktory-arm64 templates.go
    @rm -rf packaging/output
    @mkdir -p packaging/output/upstart
    @mkdir -p packaging/output/systemd

Let me know if you'd like me to clean this up and put together a PR.

mperham commented 3 years ago

@ezkl Having a PR would be wonderful. Docker is not something I'm an expert with so configuring multi-arch was a bit daunting when I looked into it recently. I'd love your help!

mperham commented 3 years ago

It should be noted that there are ARM-native macOS binaries for v1.5.1 already for anyone who wants to run it directly:

https://github.com/contribsys/faktory/releases/tag/v1.5.1-1

and of course installing via Homebrew will build the Faktory binary for your own arch.

stackptr commented 2 years ago

@mperham is this still an issue? I see linux/arm64 images in both the public registry and for Faktory-Ent. I was experiencing the qemu segfault described when using an image built from a previous version of the Faktory Enterprise image, but after bumping to 1.5.5 there are no apparent issues on an M1/arm64 device.