47chapters / letsgo

Starter Kit for Starting Startups
MIT License
58 stars 10 forks source link

AWS App Runner issue due to mismatching arch when building docker image in Apple silicon #14

Closed mauricioschneider closed 10 months ago

mauricioschneider commented 10 months ago

When running yarn ops deploy -a all, the App Runner service for the API fails with the following logs:

App Runner event logs

 [AppRunner] Deployment with ID : x started. Triggering event : SERVICE_CREATE
 [AppRunner] Deployment Artifact: [Repo Type: ECR], [Image URL: x.dkr.ecr.us-west-2.amazonaws.com/letsgo-main-api], [Image Tag: 60f617e3ad194880]
 [AppRunner] Pulling image x.dkr.ecr.us-west-2.amazonaws.com/letsgo-main-api from ECR repository.
 [AppRunner] Successfully pulled your application image from ECR.
 [AppRunner] Provisioning instances and deploying image for publicly accessible service.
 [AppRunner] Performing health check on protocol `HTTP` [Path: '/v1/health'], [Port: '8080'].
 [AppRunner] Your application stopped or failed to start. See logs for more information.  Container exit code: 1
 [AppRunner] Deployment with ID : x failed.

Application logs

exec /usr/local/bin/docker-entrypoint.sh: exec format error

I'm running letsgo on an Macbook Pro M3 Max, and according to this SO post, it's related to mismatching architecture used to build the docker image vs the one where the docker image will run. Here's a more in-depth explanation.

mauricioschneider commented 10 months ago

Besides changing the FROM in the Dockerfile, it's possible to use a environment variable, export DOCKER_DEFAULT_PLATFORM=linux/amd64.

mauricioschneider commented 10 months ago

After changing the first line of api/Dockerfile to FROM --platform=linux/amd64 node:18-alpine AS base, the deployment of the image to App Runner is successful.

mauricioschneider commented 10 months ago

The line above should be used in all Dockerfile copies in api, web, and worker.

tjanczuk commented 10 months ago

Good catch, fix coming.