lovell / sharp

High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP, AVIF and TIFF images. Uses the libvips library.
https://sharp.pixelplumbing.com
Apache License 2.0
29.27k stars 1.3k forks source link

Problem with sharp in Docker on Windows 11 machine #3932

Closed exotexot closed 10 months ago

exotexot commented 10 months ago

Hello I want to run a dockerised version of Strapi using the Dockerfile provided at the beginning of their docs https://docs.strapi.io/dev-docs/installation/docker

FROM node:18-alpine
# Installing libvips-dev for sharp Compatibility
RUN apk update && apk add --no-cache build-base gcc autoconf automake zlib-dev libpng-dev nasm bash vips-dev git
ARG NODE_ENV=development
ENV NODE_ENV=${NODE_ENV}

WORKDIR /opt/
COPY package.json package-lock.json ./
RUN npm install -g node-gyp
RUN npm config set fetch-retry-maxtimeout 600000 -g && npm install
ENV PATH /opt/node_modules/.bin:$PATH

WORKDIR /opt/app
COPY . .
RUN chown -R node:node /opt/app
USER node
RUN ["npm", "run", "build"]
EXPOSE 1337
CMD ["npm", "run", "develop"]
npx envinfo

  System:
    OS: Windows 11 10.0.22631
    CPU: (32) x64 AMD Ryzen 9 7945HX with Radeon Graphics
    Memory: 20.80 GB / 31.20 GB
  Binaries:
    Node: 20.10.0 - C:\Program Files\nodejs\node.EXE
    npm: 10.2.3 - C:\Program Files\nodejs\npm.CMD
  Managers:
    pip3: 23.2.1 - C:\Python312\Scripts\pip3.EXE
  Utilities:
    Curl: 8.4.0 - C:\Windows\system32\curl.EXE
  Virtualization:
    Docker: 24.0.7 - C:\Program Files\Docker\Docker\resources\bin\docker.EXE
  SDKs:
    Android SDK:
      API Levels: 33, 34
      Build Tools: 33.0.1, 34.0.0
      System Images: android-34 | Google APIs Intel x86_64 Atom
  IDEs:
    Android Studio: AI-222.4459.24.2221.10121639
    VSCode: 1.85.1 - C:\Users\nsynk\AppData\Local\Programs\Microsoft VS Code\bin\code.CMD
    Visual Studio: 17.8.34330.188 (Visual Studio Community 2022)
  Languages:
    Python: 3.12.1
  Databases:
    SQLite: 3.42.0 - C:\Users\nsynk\AppData\Local\Android\Sdk\platform-tools\sqlite3.EXE
  Browsers:
    Edge: Chromium (120.0.2210.91)
    Internet Explorer: 11.0.22621.1

Error:

 docker compose build --no-cache
[+] Building 92.0s (10/14)                                                                               docker:default
 => [hwx-strapi internal] load .dockerignore                                                                       0.0s
 => => transferring context: 115B                                                                                  0.0s
 => [hwx-strapi internal] load build definition from Dockerfile                                                    0.0s
 => => transferring dockerfile: 622B                                                                               0.0s
 => [hwx-strapi internal] load metadata for docker.io/library/node:18-alpine                                       0.9s
 => CACHED [hwx-strapi  1/10] FROM docker.io/library/node:18-alpine@sha256:b1a0356f7d6b86c958a06949d3db3f7fb27f95  0.0s
 => [hwx-strapi internal] load build context                                                                       0.0s
 => => transferring context: 3.53kB                                                                                0.0s
 => [hwx-strapi  2/10] RUN apk update && apk add --no-cache build-base gcc autoconf automake zlib-dev libpng-dev   7.8s
 => [hwx-strapi  3/10] WORKDIR /server/                                                                            0.0s
 => [hwx-strapi  4/10] COPY package.json package-lock.json ./                                                      0.0s
 => [hwx-strapi  5/10] RUN npm install -g node-gyp                                                                 3.5s
 => ERROR [hwx-strapi  6/10] RUN npm config set fetch-retry-maxtimeout 600000 -g && npm install                   79.8s
------
 > [hwx-strapi  6/10] RUN npm config set fetch-retry-maxtimeout 600000 -g && npm install:
26.29 npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
26.31 npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
26.31 npm WARN deprecated source-map-url@0.4.1: See https://github.com/lydell/source-map-url#deprecated
26.34 npm WARN deprecated source-map-resolve@0.5.3: See https://github.com/lydell/source-map-resolve#deprecated
26.78 npm WARN deprecated mailcomposer@3.12.0: This project is unmaintained
26.82 npm WARN deprecated buildmail@3.10.0: This project is unmaintained
29.32 npm WARN deprecated @koa/router@10.1.1: **IMPORTANT 10x+ PERFORMANCE UPGRADE**: Please upgrade to v12.0.1+ as we have fixed an issue with debuglog causing 10x slower router benchmark performance, see https://github.com/koajs/router/pull/173
30.64 npm WARN deprecated formidable@1.2.6: Please upgrade to latest, formidable@v2 or formidable@v3! Check these notes: https://bit.ly/2ZEqIau
79.67 npm ERR! code 1
79.67 npm ERR! path /server/node_modules/sharp
79.67 npm ERR! command failed
79.67 npm ERR! command sh -c (node install/libvips && node install/dll-copy && prebuild-install) || (node install/can-compile && node-gyp rebuild && node install/dll-copy)
79.67 npm ERR! sharp: Detected globally-installed libvips v8.15.0
79.67 npm ERR! sharp: Building from source via node-gyp
79.67 npm ERR!
79.67 npm ERR! make: Entering directory '/server/node_modules/sharp/build'
79.67 npm ERR!   CC(target) Release/obj.target/nothing/../node-addon-api/nothing.o
79.67 npm ERR! rm -f Release/obj.target/../node-addon-api/nothing.a Release/obj.target/../node-addon-api/nothing.a.ar-file-list; mkdir -p `dirname Release/obj.target/../node-addon-api/nothing.a`
79.67 npm ERR! ar crs Release/obj.target/../node-addon-api/nothing.a @Release/obj.target/../node-addon-api/nothing.a.ar-file-list
79.67 npm ERR!   COPY Release/nothing.a
79.67 npm ERR!   TOUCH Release/obj.target/libvips-cpp.stamp
79.67 npm ERR!   CXX(target) Release/obj.target/sharp-linuxmusl-x64/src/common.o
79.67 npm ERR!   CXX(target) Release/obj.target/sharp-linuxmusl-x64/src/metadata.o
79.67 npm ERR!   CXX(target) Release/obj.target/sharp-linuxmusl-x64/src/stats.o
79.67 npm ERR!   CXX(target) Release/obj.target/sharp-linuxmusl-x64/src/operations.o
79.67 npm ERR!   CXX(target) Release/obj.target/sharp-linuxmusl-x64/src/pipeline.o
79.67 npm ERR! make: Leaving directory '/server/node_modules/sharp/build'
79.67 npm ERR! gyp info it worked if it ends with ok
79.67 npm ERR! gyp info using node-gyp@10.0.1
79.67 npm ERR! gyp info using node@18.19.0 | linux | x64
79.67 npm ERR! gyp info find Python using Python version 3.11.6 found at "/usr/bin/python3"
79.67 npm ERR! gyp http GET https://unofficial-builds.nodejs.org/download/release/v18.19.0/node-v18.19.0-headers.tar.gz
79.67 npm ERR! gyp http 200 https://unofficial-builds.nodejs.org/download/release/v18.19.0/node-v18.19.0-headers.tar.gz
79.67 npm ERR! gyp http GET https://unofficial-builds.nodejs.org/download/release/v18.19.0/SHASUMS256.txt
79.67 npm ERR! gyp http 200 https://unofficial-builds.nodejs.org/download/release/v18.19.0/SHASUMS256.txt
79.67 npm ERR! gyp info spawn /usr/bin/python3
79.67 npm ERR! gyp info spawn args [
79.67 npm ERR! gyp info spawn args '/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
79.67 npm ERR! gyp info spawn args 'binding.gyp',
79.67 npm ERR! gyp info spawn args '-f',
79.67 npm ERR! gyp info spawn args 'make',
79.67 npm ERR! gyp info spawn args '-I',
79.67 npm ERR! gyp info spawn args '/server/node_modules/sharp/build/config.gypi',
79.67 npm ERR! gyp info spawn args '-I',
79.67 npm ERR! gyp info spawn args '/usr/local/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
79.67 npm ERR! gyp info spawn args '-I',
79.67 npm ERR! gyp info spawn args '/root/.cache/node-gyp/18.19.0/include/node/common.gypi',
79.67 npm ERR! gyp info spawn args '-Dlibrary=shared_library',
79.67 npm ERR! gyp info spawn args '-Dvisibility=default',
79.67 npm ERR! gyp info spawn args '-Dnode_root_dir=/root/.cache/node-gyp/18.19.0',
79.67 npm ERR! gyp info spawn args '-Dnode_gyp_dir=/usr/local/lib/node_modules/npm/node_modules/node-gyp',
79.67 npm ERR! gyp info spawn args '-Dnode_lib_file=/root/.cache/node-gyp/18.19.0/<(target_arch)/node.lib',
79.67 npm ERR! gyp info spawn args '-Dmodule_root_dir=/server/node_modules/sharp',
79.67 npm ERR! gyp info spawn args '-Dnode_engine=v8',
79.67 npm ERR! gyp info spawn args '--depth=.',
79.67 npm ERR! gyp info spawn args '--no-parallel',
79.67 npm ERR! gyp info spawn args '--generator-output',
79.67 npm ERR! gyp info spawn args 'build',
79.67 npm ERR! gyp info spawn args '-Goutput_dir=.'
79.67 npm ERR! gyp info spawn args ]
79.67 npm ERR! gyp info spawn make
79.67 npm ERR! gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
79.67 npm ERR! ../src/pipeline.cc: In member function 'virtual void PipelineWorker::OnOK()':
79.67 npm ERR! ../src/pipeline.cc:1230:30: error: aggregate 'PipelineWorker::OnOK()::stat64 st' has incomplete type and cannot be defined
79.67 npm ERR!  1230 |         struct STAT64_STRUCT st;
79.67 npm ERR!       |                              ^~
79.67 npm ERR! ../src/pipeline.cc:1231:55: error: invalid use of incomplete type 'struct PipelineWorker::OnOK()::stat64'
79.67 npm ERR!  1231 |         if (STAT64_FUNCTION(baton->fileOut.data(), &st) == 0) {
79.67 npm ERR!       |                                                       ^
79.67 npm ERR! ../src/pipeline.cc:33:23: note: forward declaration of 'struct PipelineWorker::OnOK()::stat64'
79.67 npm ERR!    33 | #define STAT64_STRUCT stat64
79.67 npm ERR!       |                       ^~~~~~
79.67 npm ERR! ../src/pipeline.cc:1230:16: note: in expansion of macro 'STAT64_STRUCT'
79.67 npm ERR!  1230 |         struct STAT64_STRUCT st;
79.67 npm ERR!       |                ^~~~~~~~~~~~~
79.67 npm ERR! make: *** [sharp-linuxmusl-x64.target.mk:167: Release/obj.target/sharp-linuxmusl-x64/src/pipeline.o] Error 1
79.67 npm ERR! gyp ERR! build error
79.67 npm ERR! gyp ERR! stack Error: `make` failed with exit code: 2
79.67 npm ERR! gyp ERR! stack at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:209:23)
79.67 npm ERR! gyp ERR! System Linux 6.5.11-linuxkit
79.67 npm ERR! gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
79.67 npm ERR! gyp ERR! cwd /server/node_modules/sharp
79.67 npm ERR! gyp ERR! node -v v18.19.0
79.67 npm ERR! gyp ERR! node-gyp -v v10.0.1
79.67 npm ERR! gyp ERR! not ok
79.67
79.67 npm ERR! A complete log of this run can be found in: /root/.npm/_logs/2024-01-05T14_11_47_666Z-debug-0.log
------
failed to solve: process "/bin/sh -c npm config set fetch-retry-maxtimeout 600000 -g && npm install" did not complete successfully: exit code: 1

The installation crashes due to sharp stuff. Any ideas whats happening?

lovell commented 10 months ago

The official Node.js Alpine-based Docker images do not support running node-gyp without additional dependencies.

https://github.com/nodejs/docker-node/blob/main/docs/BestPractices.md#node-gyp-alpine

https://github.com/nodejs/docker-node/issues/2009

Please can you report this downstream to Strapi as they need to fix their documentation.