sharp
sharp copied to clipboard
Run benchmarks in a Dockerfile?
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
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.
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 :)
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?
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.
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
You'll probably need to add node_modules
to .dockerignore
.
Already doing that. See docker_bench branch for the current state
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!