sharp icon indicating copy to clipboard operation
sharp copied to clipboard

Run benchmarks in a Dockerfile?

Open erf opened this issue 2 years ago • 7 comments

What are you trying to achieve?

I'm wondering if you have thought about running the benchmarks in a Docker container?

This way you would not have to install all the dependencies on your local machine and you would have a consistent test environment.

I was able to create a Docker image with alpine for sharp, but having some problems with the benchmark dependencies (i'm a Docker newbie)

Have you searched for similar feature requests? Yes

erf avatar Sep 16 '21 22:09 erf

Hi, yes, this is a good idea. It might be as simple as a shell script that assumes the presence of docker, spins up a container and invokes commands within it. We'd probably want to use volumes to avoid overlay filesystems.

lovell avatar Sep 17 '21 09:09 lovell

I'm trying to build a Dockerfile, but having a few issues..

The mapnik dependency seem somewhat difficult to build, so i put it on hold for now, commenting out the code..

Then i found the relative path to sharp in bench.js to be troublesome when building the Docker image. So instead i added a devDependencies to sharp. I'm able to build the image, but when running the container i get the following error:

Error relocating /usr/lib/libpango-1.0.so.0: g_memdup2: symbol not found

I tried to add the pango-dev dependency with no result.

It would probably be best to use the local version of sharp if possible. You would probably copy the local folder and call npm install there and then depend on that. I tried to do this in the Dockerfile but ended up commenting out the code. Not too familiar with those Docker commands yet.

I've made a branch bench-docker with a WIP commit if you want to have a look.

Help / ideas would be appreciated :)

erf avatar Sep 17 '21 12:09 erf

I noticed when i try to reference the local sharp folder in the Docker container i get the following error:

/app/test/bench # node perf.js

Something went wrong installing the "sharp" module

Cannot find module '../build/Release/sharp-linuxmusl-arm64v8.node'
Require stack:
- /app/lib/sharp.js
- /app/lib/constructor.js
- /app/lib/index.js
- /app/test/bench/perf.js

Possible solutions:
- Install with the --verbose flag and look for errors: "npm install --ignore-scripts=false --verbose sharp"
- Install for the current runtime: "npm install --platform=linux --arch=arm64 sharp"
- Consult the installation documentation: https://sharp.pixelplumbing.com/install
/app/test/bench #

I see in the build/Release folder there is sharp-darwin-x64.node

Any idea how to fix this?

erf avatar Sep 21 '21 10:09 erf

It looks like you're using x64 macOS at install time but ARM64 musl-based Linux at runtime. As suggested in the possible solutions in the error message, you can specify the runtime at npm install time via:

npm install --platform=linuxmusl --arch=arm64

https://sharp.pixelplumbing.com/install#cross-platform

Alternatively, run npm install inside the container.

lovell avatar Sep 21 '21 13:09 lovell

I do a RUN command in the Dockerfile should that not build an IMAGE for the correct platform defined in FROM, that is Linux and darwin?

I also did try: RUN npm install --arch=arm64 --platform=linuxmusl in the Dockerfile, but i still builds a sharp-darwin-x64.node

BTW: I'm using macOS Montorey (beta 6)

UPDATE: I noticed that the build folder is not created in the container after i add it to .dockerignore

erf avatar Sep 21 '21 14:09 erf

You'll probably need to add node_modules to .dockerignore.

lovell avatar Sep 21 '21 18:09 lovell

Already doing that. See docker_bench branch for the current state

erf avatar Sep 21 '21 18:09 erf

Commit https://github.com/lovell/sharp/commit/953a94885bf4b99ae537728ac9d5d4637df67a8a adds a Dockerfile and small shell script to install dependencies, build sharp for the current branch then run the performance tests. I'll use this next time I update the results in the documentation.

Thank you for the original suggestion!

lovell avatar Sep 01 '22 14:09 lovell