Score:0

Error to build AWS Lambda Node 14arm64 with Sharp on a Docker image

jp flag

I'm changing a node setup from node 14 x64 to node 14 arm64 in an Amazon ECR (Docker) entry.

It build with no problem when I use this image: FROM aws/lambda/nodejs:14 and this command to install sharp RUN npm install --platform=linux sharp

Now I need to use Node 14 arm64 image, but it launches this error while building with Sharp JS (Linux arm 64):

Dockerfile:

FROM public.ecr.aws/lambda/nodejs:14-arm64

# Exec commands
COPY index.js package.json ${LAMBDA_TASK_ROOT}
COPY fonts ${LAMBDA_TASK_ROOT}/fonts/
COPY src ${LAMBDA_TASK_ROOT}/src/

# Commands
RUN npm cache clean --force
RUN rm -rf node_modules
RUN npm install --arch=arm64 --platform=linux sharp

CMD ["index.handler"]

Build command:

docker build -t my-project-v1 .
docker tag my-project-v1:latest {ACCOUNT}.dkr.ecr.us-east-1.amazonaws.com/my-project-v1:latest
docker push {ACCOUNT}.dkr.ecr.us-east-1.amazonaws.com/my-project-v1:latest

Error:

=> ERROR [6/8] RUN npm install                                                                                                                  7.3s
------                                                                                                                                                
 > [6/8] RUN npm install:                                                                                                                             
#10 2.231 npm WARN deprecated [email protected]: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.       
#10 2.249 npm WARN deprecated [email protected]: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.                                                                       
#10 6.947                                                                                                                                             
#10 6.947 > [email protected] install /var/task/node_modules/sharp
#10 6.947 > (node install/libvips && node install/dll-copy && prebuild-install) || (node install/can-compile && node-gyp rebuild && node install/dll-copy)
#10 6.947 
#10 7.046 sharp: Installation error: Use with glibc 2.26 requires manual installation of libvips >= 8.11.3
#10 7.046 sharp: Please see https://sharp.pixelplumbing.com/install for required dependencies
#10 7.172 npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.3.2 (node_modules/chokidar/node_modules/fsevents):
#10 7.173 npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"arm64"})
#10 7.174 
#10 7.234 npm ERR! code ELIFECYCLE
#10 7.235 npm ERR! errno 1
#10 7.242 npm ERR! [email protected] install: `(node install/libvips && node install/dll-copy && prebuild-install) || (node install/can-compile && node-gyp rebuild && node install/dll-copy)`
#10 7.242 npm ERR! Exit status 1
#10 7.243 npm ERR! 
#10 7.244 npm ERR! Failed at the [email protected] install script.
#10 7.244 npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
#10 7.261 
#10 7.262 npm ERR! A complete log of this run can be found in:
#10 7.262 npm ERR!     /root/.npm/_logs/2022-01-10T13_28_10_709Z-debug.lo
Score:2
cn flag

The error message said that the problem is related with libvips: sharp: Installation error: Use with glibc 2.26 requires manual installation of libvips >= 8.11.3. Searching in the official sharp documentation I found that on machines other than Linux x64 (like in your case: Linux arm64), you should ignore global libvips updating the SHARP_IGNORE_GLOBAL_LIBVIPS environment variable:

npm install
SHARP_IGNORE_GLOBAL_LIBVIPS=1 npm install --arch=x64 --platform=linux sharp

so, you should update your Dockerfile to the following:

FROM public.ecr.aws/lambda/nodejs:14-arm64

# Exec commands
COPY index.js package.json ${LAMBDA_TASK_ROOT}
COPY fonts ${LAMBDA_TASK_ROOT}/fonts/
COPY src ${LAMBDA_TASK_ROOT}/src/

# Commands
RUN npm cache clean --force
RUN rm -rf node_modules

## update the dockerfile with the following lines:
RUN npm install
RUN SHARP_IGNORE_GLOBAL_LIBVIPS=1 npm install --arch=x64 --platform=linux sharp

CMD ["index.handler"]
Matheus Pereira avatar
jp flag
I tried this, but the error is the same. I think that `public.ecr.aws/lambda/nodejs:14-arm64` image haven't support to sharp library yet because `amazon/aws-lambda-nodejs:14` image is perfect with sharp x64.
Luiz Lelis avatar
cn flag
using the same `dockerfile` that you shown above, I was able to reproduce the error and also to fix it with `SHARP_IGNORE_GLOBAL_LIBVIPS=1`. Are you sure that the error showed in `stdout` is the same?
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.