rallly icon indicating copy to clipboard operation
rallly copied to clipboard

Build fails on arm

Open Eirikr70 opened this issue 2 years ago • 10 comments

The Dockerfile fails on arm. First problem : schema.prisma is not on the same directory as the other files : you should copy it from prisma/schema.prisma. But then where should it be copied to ? /usr/src/app or /usr/src/app/prisma ? Then yarn install fails with the following messages

[1/4] Resolving packages...
[2/4] Fetching packages...
info There appears to be trouble with your network connection. Retrying...
[3/4] Linking dependencies...
warning "react-hot-toast > [email protected]" has unmet peer dependency "csstype@^3.0.10".
warning " > [email protected]" has unmet peer dependency "i18next@>= 19.0.0".
[4/4] Building fresh packages...
$ prisma generate
Error: Unknown binaryTarget linux-arm64-openssl-undefined and no custom engine files were provided
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
The command '/bin/sh -c yarn --production' returned a non-zero code: 1
ERROR: Service 'rallly' failed to build : Build failed

Any clue ?

Eirikr70 avatar May 18 '22 18:05 Eirikr70

Hi there, pretty sure this is all just one issue. I don't have an ARM machine to test this one. If anyone can look into what changes need to be made to get the build working on ARM machines I would welcome a PR.

This issue might be a good starting point.

lukevella avatar May 19 '22 08:05 lukevella

Sorry I just realized the issue with the prisma file being moved after seeing #176. It's been fixed in https://github.com/lukevella/rallly/commit/d538fb8c2d2ececc01cdf9c49d5ac28942511190

lukevella avatar May 19 '22 09:05 lukevella

Hi, I tried again with the prisma file copied to the right place. I also tried building with docker buildx build --platform linux/amd64 -t partnerx . although I don't understand what it does. I got this log

[+] Building 23.3s (5/13)                                                                                                                                            
 => [internal] load build definition from Dockerfile                                                                                                            0.1s
 => => transferring dockerfile: 441B                                                                                                                            0.0s
 => [internal] load .dockerignore                                                                                                                               0.1s
 => => transferring context: 89B                                                                                                                                0.0s
 => [internal] load metadata for docker.io/library/node:alpine                                                                                                  1.5s
 => [1/9] FROM docker.io/library/node:alpine@sha256:0677e437543d10f6cb050d92c792a14e5eb84340e3d5b4c25a88baa723d8a4ae                                           21.5s
 => => resolve docker.io/library/node:alpine@sha256:0677e437543d10f6cb050d92c792a14e5eb84340e3d5b4c25a88baa723d8a4ae                                            0.0s
 => => sha256:9f58095cfeb62814052ec7e46555e6c19c4130153259890eaf07c9e57ec1f676 6.62kB / 6.62kB                                                                  0.0s
 => => sha256:df9b9388f04ad6279a7410b85cedfdcb2208c0a003da7ab5613af71079148139 2.81MB / 2.81MB                                                                  0.5s
 => => sha256:b81098a2906573284e24c76f0b8f760ccbe813d0fd72f2465af087fd2e698bac 46.75MB / 46.75MB                                                                6.7s
 => => sha256:0677e437543d10f6cb050d92c792a14e5eb84340e3d5b4c25a88baa723d8a4ae 1.43kB / 1.43kB                                                                  0.0s
 => => sha256:8a7f5435fd83f6d1dbdeff2decad2275b2550d28cacf7acd653d2cbaee957965 1.16kB / 1.16kB                                                                  0.0s
 => => sha256:d18e917c779edec81408c8f226db7281356435fba2f3d713012ab7e0f4c9e0b1 2.35MB / 2.35MB                                                                  0.9s
 => => extracting sha256:df9b9388f04ad6279a7410b85cedfdcb2208c0a003da7ab5613af71079148139                                                                       0.4s
 => => sha256:8c3de7fd67d7627fc68f9f94bf899c222a3ff9086da092a09f7ab296d2dee9cd 452B / 452B                                                                      0.8s
 => => extracting sha256:b81098a2906573284e24c76f0b8f760ccbe813d0fd72f2465af087fd2e698bac                                                                       6.1s
 => => extracting sha256:d18e917c779edec81408c8f226db7281356435fba2f3d713012ab7e0f4c9e0b1                                                                       0.3s
 => => extracting sha256:8c3de7fd67d7627fc68f9f94bf899c222a3ff9086da092a09f7ab296d2dee9cd                                                                       0.0s
 => [internal] load build context                                                                                                                               0.7s
 => => transferring context: 9.34MB                                                                                                                             0.7s
 => ERROR [2/9] RUN mkdir -p /usr/src/app                                                                                                                       7.4s
------                                                                                                                                                               
 > [2/9] RUN mkdir -p /usr/src/app:
#0 0.507 exec /bin/sh: exec format error
------
error: failed to solve: executor failed running [/bin/sh -c mkdir -p /usr/src/app]: exit code: 1

Eirikr70 avatar May 19 '22 20:05 Eirikr70

Hi there, pretty sure this is all just one issue. I don't have an ARM machine to test this one. If anyone can look into what changes need to be made to get the build working on ARM machines I would welcome a PR.

This issue might be a good starting point.

You can build arm-images on amd64 by giving docker the --platform argument, like @Eirikr70 did in the comment above.

mawoka-myblock avatar Jun 17 '22 21:06 mawoka-myblock

You can build arm-images on amd64 by giving docker the --platform argument, like @Eirikr70 did in the comment above.

Unfortunately, it doesn't seem to be sufficient.

Eirikr70 avatar Jun 18 '22 00:06 Eirikr70

seems to be an isssue with Prisma

 #12 267.6 [4/4] Building fresh packages...
 #12 283.5 $ prisma generate
 #12 289.1 Error: Unknown binaryTarget linux-arm64-openssl-undefined and no custom engine files were provided
 #12 289.2 error Command failed with exit code 1.

Workflow log

https://github.com/Just5KY/rallly/runs/6948789404?check_suite_focus=true

Multi-arch github workflow file

https://github.com/Just5KY/rallly/blob/main/.github/workflows/docker.yml

just5ky avatar Jun 18 '22 14:06 just5ky

I managed to build it successfully on arm64, please have a look at this patch: https://gist.github.com/gdnmhr/30aac9379a2d76251f10d722f02d40cd

Prisma seems to need the target to be specified for arm. Furthermore, it needs openssl and libc to be present wich seem not to be there by default. The libc provided by alpine did not work for me, therefore I used slim as base image...

I don't know if this breaks building on x86, maybe someone else can test this.

gdnmhr avatar Jul 04 '22 18:07 gdnmhr

I managed to build it successfully on arm64, please have a look at this patch: https://gist.github.com/gdnmhr/30aac9379a2d76251f10d722f02d40cd

Prisma seems to need the target to be specified for arm. Furthermore, it needs openssl and libc to be present wich seem not to be there by default. The libc provided by alpine did not work for me, therefore I used slim as base image...

I don't know if this breaks building on x86, maybe someone else can test this.

If we'd apply this fix, normal, non arm-builds, would fail

mawoka-myblock avatar Jul 05 '22 07:07 mawoka-myblock

I was able to build a multi-arch image (linux/arm64,linux/amd64) using GitHub Actions by adding binaryTargets = ["native"] to schema.prisma (and using node:slim as base).

gdnmhr avatar Jul 28 '22 11:07 gdnmhr

I was able to build a multi-arch image (linux/arm64,linux/amd64) using GitHub Actions by adding binaryTargets = ["native"] to schema.prisma (and using node:slim as base).

Yes, I am able to build it too https://hub.docker.com/r/justsky/rally/tags also had to add some more dependencies, followed your older comment and added those too

just5ky avatar Jul 28 '22 14:07 just5ky

@lukevella you can make the changes to add arm64 support https://github.com/Just5KY/rallly https://hub.docker.com/r/justsky/rally/tags

just5ky avatar Jan 09 '23 22:01 just5ky

Hi folks, so is changing the base image necessary or is it enough to add binaryTargets = ["native"] to schema.prisma. I'm keen to close this issue so if you have a fix for this that also maintains support for other architectures it would be very welcome.

lukevella avatar Jan 11 '23 10:01 lukevella

@lukevella Should work without changing base image. See my fork, I'm using a modified version of your dockerfile Just added "native" in prisma and added 3 npm packages.

just5ky avatar Jan 11 '23 12:01 just5ky

I just pushed #387. Can anyone tell me whether this works on an arm machine?

Please checkout the arm-support branch.

To build and run the local project with docker compose:

docker compose -f docker-compose.yml -f docker-compose.local.yml build
docker compose -f docker-compose.yml -f docker-compose.local.yml up

I'll wait to hear back before proceeding with this.

lukevella avatar Jan 11 '23 17:01 lukevella

@lukevella I can confirm it does work on arm64 using the arm-support branch, tested on a RaspberryPi 4.

gdnmhr avatar Jan 11 '23 18:01 gdnmhr

@lukevella I can confirm it does work on arm64 using the arm-support branch, tested on a RaspberryPi 4.

Amazing! Thank you. In case there are any other issues relating to arm support feel free to reopen this issue.

lukevella avatar Jan 11 '23 18:01 lukevella

@lukevella you could consider building and pushing images for arm64 using QEMU. This workflow should do the job:

name: Build and publish Docker image
on:
  push:
    branches:
      - main
  workflow_dispatch:

jobs:
  publish:
    name: Build and publish Docker image
    runs-on: ubuntu-latest
    steps:
      - name: Log in to Docker Hub
        uses: docker/login-action@v2
        with:
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}

      - name: Check out repository code
        uses: actions/checkout@v3

      - name: Set up QEMU
        uses: docker/setup-qemu-action@v2

      - name: Set up Docker Buildx
        id: buildx
        uses: docker/setup-buildx-action@v2

      - name: Build and publish image
        uses: docker/build-push-action@v3
        with:
          platforms: linux/arm64,linux/amd64
          push: true
          tags: |
            ${{ secrets.DOCKER_USERNAME }}/rallly:latest
            ${{ secrets.DOCKER_USERNAME }}/rallly:${{ github.sha }}

gdnmhr avatar Jan 11 '23 18:01 gdnmhr

Yeah, that how I am building mine.. See here: https://github.com/Just5KY/rallly/blob/latest/.github/workflows/justsky.yml

just5ky avatar Jan 11 '23 18:01 just5ky

@lukevella you could consider building and pushing images for arm64 using QEMU.

That makes sense! Thanks for pointing that out 👍

lukevella avatar Jan 11 '23 18:01 lukevella

Thanks, everyone for your help with this. I noticed that the workflow is taking much longer to build a multi-platform image (over an hour). I've opened #391 to try to address this. If anyone knows why or how this can be improved please let me know there.

lukevella avatar Jan 12 '23 10:01 lukevella