mdneuzerling / lambdr

Run R containers on AWS Lambda
https://lambdr.mdneuzerling.com
Other
131 stars 12 forks source link

Handling architecture differences #23

Closed jimjam-slam closed 1 year ago

jimjam-slam commented 1 year ago

Hey David! Some colleagues and I are looking at migrating some R functions to Lambda using {lambdr}. One sticking point we're hitting on is architectures: the Docker image needs to be built before it goes to ECR, and two of us are on Apple Silicon Macs (so building arm64), while the other's on an Intel Mac (x86).

Do you know if there's a way to build a multi-architecture image and send that to ECR?

Right now when I build it gets stuck installing R (since the architecture is hardcoded into the Dockerfile—but perhaps it could check that?):

6 8.954 Cannot add package R-4.2.2-1-1.x86_64.rpm to transaction. Not a compatible architecture: x86_64
#6 8.955 Error: Nothing to do
------
executor failed running [/bin/sh -c yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm   && wget https://cdn.rstudio.com/r/centos-7/pkgs/R-${R_VERSION}-1-1.x86_64.rpm   && yum -y install R-${R_VERSION}-1-1.x86_64.rpm   && rm R-${R_VERSION}-1-1.x86_64.rpm]: exit code: 1

Or perhaps it's better to have a GitHub Action build and upload the Docker image, so that we're all on one architecture?

jimjam-slam commented 1 year ago

Having thought about this more, building and uploading with GitHub Actions is definitely the way t9 go 😅

mdneuzerling commented 1 year ago

Hi James,

I know you've found a solution, but you can also build x86 Docker images on an M1 Mac --- that's exactly what I do. You will need to use buildx and add --platform=linux/amd64 to your build command.

Alternatively, you could try building your ARM images and hosting them with Graviton. I have no idea if that would work, since I haven't tried it myself.

jimjam-slam commented 1 year ago

Oooh, okay! Can you pass the platform currently being built into the Dockerfile (eg. to download the correct R version)?