I recently received a MacBook Pro M2 and am running into issues when I cdk deploy
from it. There's a numpy
import issue specifically relating to its "C-extensions".
Original error was: No module named 'numpy.core._multiarray_umath.
I see thjat once cdk deploy
kicks off, Docker Desktop has the very first layer as "ARCHITECTURE arm64". I'm guessing this is at least partly why the build runs into issues once it actually tries to run on the x64 AWS architecture. Am I plain unable to do a build like this locally?
I tried a few different versions of numpy to import. I deployed the same code from a coworker's x64 laptop and it ran successfully.
SOLVED
Going along the lines of the zessx' comment below I ended up solving the problem by addingexport DOCKER_DEFAULT_PLATFORM="linux/amd64"
to my zsh profile.
Docker will try to use image fitting your local architecture. The new Apple M1/M2 are using an ARM64 architecture, therefore Docker will search for ARM64 images, by default.
In your case, when running cdk deploy
you are probably building an image in the backend. This image will be build with an ARM64 arch, but is expected to run on an AMD64 arch.
You have several ways to ensure you're building your images for the right arch.
--platform
flag with your Docker commandsdocker build -t $IMAGE --platform linux/amd64 .
docker push ${AWS_ACCOUNT}.dkr.ecr.${AWS_REGION}.amazonaws.com/${IMAGE}
--platform
flag in your DockerfilesFROM ruby:latest as development
RUN …
FROM --platform=linux/amd64 ruby:latest as production
RUN …
Then, you can specify which target to build in the Docker command:
docker build -t $IMAGE --target production .
DOCKER_DEFAULT_PLATFORM
environment variableexport DOCKER_DEFAULT_PLATFORM="linux/amd64"
You can also add this line in your .bashrc
/.zshrc
, but keep in mind you would then use AMD64 emulation all the time, even for your local projects, where native ARM64 images are available. I would not recommend this.