I am having trouble deploying a Python FastAPI API in a Docker image to a cloud instance. I am using an M1 Mac, which has an ARM architecture. From what I know, Google Cloud Run instances are built on Linux machines with x86_64 architecture, so my container fails to deploy.
I have seen two solutions to this problem, but both have drawbacks. The first solution is to use the -platform flag when building my Docker image. This will build an image for a different architecture, but it will also make the image very large (my image is normally approx. 200MB but building for a different platform makes it 5+ GB) and take a long time to build (almost 20 minutes). This is not practical or portable, and it would be difficult to implement into a CI/CD pipeline. It should be noted that my API has some heavy Python dependencies like PyTorch, so it is already large from that standpoint.
The second solution is to use Google Compute Engine (GCE) instead of Google Cloud Run. GCE allows me to specify the architecture of the virtual machine instance, so I could choose an ARM instance. However, using an ARM instance like the TAU line with GCE requires me to use Google Kubernetes Engine (GKE). GKE is designed for multi-container workloads, and it would be very expensive to use for a single-container API.
I am looking for a solution to this problem. I would like to be able to deploy my API to Google Cloud without having to use a large, slow container or an expensive GKE cluster.
Thank you for your time and attention to this matter.
First, I tried deploying an ARM-built Docker image on Cloud Run. This failed as the instance could not find the required binaries. Then, I used docker build --platform linux/amd64 and also tried the same with docker buildx build... but, like i mentioned above, these take ages and create massive images.
As for GCE and GKE, I just browsed the deployment page on the Cloud Console looking for solutions.