InvenTree icon indicating copy to clipboard operation
InvenTree copied to clipboard

[Docker] Image takes ages to build

Open SchrodingersGat opened this issue 1 year ago • 11 comments

  • https://github.com/inventree/InvenTree/pull/6614 has broken docker image push
  • builds are stuck on "building wheel for grpcio"
  • Related issue: https://github.com/inventree/InvenTree/issues/6291

Edit: Docker push is not broken, but it does take a significant amount of time just to build this one package

image

After much research, this seems to be related specifically to building the alpine image on ARM.

The downloads page shows lots of other precompiled wheel options but not the ones we want.

References

  • https://github.com/grpc/grpc/issues/27940
  • https://github.com/grpc/grpc/issues/34998
  • https://github.com/grpc/grpc/issues/32044
  • https://github.com/grpc/grpc/issues/27512
  • https://github.com/grpc/grpc/issues/27512
  • https://github.com/home-assistant/core/issues/56669
  • https://github.com/home-assistant/core/issues/56669
  • https://github.com/home-assistant/core/issues/40148

Potential Solutions

A) Use pre-build grpcio library

Alpine ships the py3-grpcio package which comes with the 1.54.2 version of the library pre-installed. This may sidestep our need to build the library entirely.

B) Different Base Image

Alpine / musl is a big part of the "problem" here - using a different base image would make this a much more tractable problem.

C) Compile Wheel

Can we compile a wheel for grpcio ourselves for the aarch64 architecture?

D) Consider Default Support for grpcio

Currently we use this for tracing. I do not want to split up dependencies, this is not my ideal solution. But including it here as a point of consideration.

SchrodingersGat avatar Mar 02 '24 02:03 SchrodingersGat

@matmair @wolflu05 this single library (grpcio) is the cause for our very long docker build times on GitHub Actions.

SchrodingersGat avatar Mar 04 '24 13:03 SchrodingersGat

This was the main reason I implemented the matrix build as it seems there are problems with that solution I think c) would be the next best

matmair avatar Mar 04 '24 20:03 matmair

I think for a optimal setup, we need to:

  1. use matrix builds and merge the manifest so that we don't have the issue we recently had. See https://docs.docker.com/build/ci/github-actions/multi-platform/
  2. build our own wheel and cache that
  3. use the free m1 runners for arm building

wolflu05 avatar Mar 04 '24 20:03 wolflu05

regarding 3. - I tried to get docker running on mac and it seems to be difficult. To get the M1 runner we should run MacOS 14 which seems to have problems with colima.

Also see https://github.com/actions/runner-images/issues/17

matmair avatar Mar 04 '24 20:03 matmair

Arm runners + docker seems to be a problem https://github.com/douglascamata/setup-docker-macos-action?tab=readme-ov-file#arm64-processors-m1-m2-m3-series-used-on-macos-14-images-are-unsupported; which kind of defeats the purpose

matmair avatar Mar 04 '24 20:03 matmair

I think compiling and caching our own wheel would go most of the way and certainly be a drastic improvement to our build times. That should be our priority

SchrodingersGat avatar Mar 04 '24 20:03 SchrodingersGat

Anyone have experience doing something like this in GitHub?

SchrodingersGat avatar Mar 04 '24 20:03 SchrodingersGat

Ok, thanks for referencing these. I now understand the trouble you mean. Very said that there are no Linux arm runners for free available.

wolflu05 avatar Mar 04 '24 20:03 wolflu05

I think compiling and caching our own wheel would go most of the way and certainly be a drastic improvement to our build times. That should be our priority

Looking into it. Seems simpler than getting docker to run

matmair avatar Mar 04 '24 20:03 matmair

Maybe we can use piwheels too - they are already building wheels https://www.piwheels.org/project/grpcio/

matmair avatar Mar 04 '24 23:03 matmair

@matmair isn't that for armv7 only?

SchrodingersGat avatar Mar 05 '24 12:03 SchrodingersGat