cloudfoundry / nodejs-buildpack

Cloud Foundry buildpack for Node.js
http://docs.cloudfoundry.org/buildpacks/
Apache License 2.0
169 stars 382 forks source link

Unable to install packages using Sharp #461

Closed CN91 closed 2 years ago

CN91 commented 2 years ago

What version of Cloud Foundry and CF CLI are you using? (i.e. What is the output of running cf curl /v2/info && cf version? { "name": "VMware Tanzu Application Service", "build": "2.12.12-build.1", "support": "https://support.pivotal.io", "version": 0, "description": "https://docs.pivotal.io/pivotalcf/2-12/pcf-release-notes/runtime-rn.html", "min_cli_version": "6.23.0", "min_recommended_cli_version": "6.23.0", "api_version": "2.171.0", "osbapi_version": "2.15", }

note I removed unneeded information.

What version of the buildpack you are using? Nodejs Buildpack version 1.7.69 npm info using npm@8.5.0 npm info using node@v16.14.2 stack: https://github.com/cloudfoundry/cflinuxfs3

If you were attempting to accomplish a task, what was it you were attempting to do? Installing a Strapi / Directus application with an underlying Sharp - dependency

What did you expect to happen? Install succesfully while using provided prebuilds with environment settings (e.g. NPM_CONFIG_TARBALL / NPM_CONFIG_SHARP_LOCAL_PREBUILDS NPM_CONFIG_SHARP_LIBVIPS_LOCAL_PREBUILDS )

I was expecting that the environment would use the set configurations when running npm install.

What was the actual behavior?

On loading it set the npm environment variables:

2022-06-18T19:28:51.16+0200 [STG/0] OUT        Visit http://docs.cloudfoundry.org/buildpacks/node/index.html#vendoring
   2022-06-18T19:28:51.16+0200 [STG/0] OUT        NPM_CONFIG_LOGLEVEL=verbose
   2022-06-18T19:28:51.16+0200 [STG/0] OUT        NPM_CONFIG_REGISTRY=<INTERNAL>
   2022-06-18T19:28:51.16+0200 [STG/0] OUT        NPM_CONFIG_SHARP_INSTALL_FORCE=true
   2022-06-18T19:28:51.16+0200 [STG/0] OUT        NPM_CONFIG_SHARP_LIBVIPS_LOCAL_PREBUILDS=tmp/app/prebuilds
   2022-06-18T19:28:51.16+0200 [STG/0] OUT        NPM_CONFIG_SHARP_LOCAL_PREBUILDS=tmp/app/prebuilds
   2022-06-18T19:28:51.16+0200 [STG/0] OUT        NPM_CONFIG_TARBALL=tmp/app/node/headers/node-v16.14.2-headers.tar.gz
   2022-06-18T19:28:51.16+0200 [STG/0] OUT        NODE_ENV=production
   2022-06-18T19:28:51.16+0200 [STG/0] OUT        NODE_HOME=/tmp/contents932963960/deps/0/node
   2022-06-18T19:28:51.16+0200 [STG/0] OUT        NODE_MODULES_CACHE=true
   2022-06-18T19:28:51.16+0200 [STG/0] OUT        NODE_VERBOSE=false
   2022-06-18T19:28:51.16+0200 [STG/0] OUT        NPM_CONFIG_PRODUCTION=true
   2022-06-18T19:28:51.16+0200 [STG/0] OUT -----> Building dependencies
   2022-06-18T19:28:51.16+0200 [STG/0] OUT        Installing node modules (package.json + package-lock.json)

When running into the command installing sharp it ran into this issue: https://github.com/lovell/sharp/issues/1882

It would be great if this package/ buildpack could be made libvips compatible.

Can you provide a sample app?

package.json

{
  "name": "strapi-ts",
  "private": true,
  "version": "0.1.0",
  "description": "A Strapi application",
  "scripts": {
    "develop": "strapi develop",
    "start": "strapi start",
    "build": "strapi build",
    "strapi": "strapi"
  },
  "dependencies": {
    "@strapi/plugin-i18n": "4.3.0-beta.1",
    "@strapi/plugin-users-permissions": "4.3.0-beta.1",
    "@strapi/strapi": "4.3.0-beta.1",
    "cfenv": "^1.2.4",
    "pg": "8.6.0"
  },
  "author": {
    "name": "A Strapi developer"
  },
  "strapi": {
    "uuid": "a8a91ca3-149d-40e1-90e3-e0a7284e876e"
  },
  "engines": {
    "node": "16.x.x",
    "npm": "8.x.x"
  },
  "license": "MIT"
}

manifest.yml

---
applications:
  - name: strapi
    # path: ./dist
    memory: 128M
    command: node server.js
    buildpacks:
      - nodejs_buildpack
    env:
        NPM_CONFIG_REGISTRY: <internal.nexus>
        NPM_CONFIG_SHARP_INSTALL_FORCE: true
        NPM_CONFIG_SHARP_LOCAL_PREBUILDS: tmp/app/prebuilds
        NPM_CONFIG_SHARP_LIBVIPS_LOCAL_PREBUILDS: tmp/app/prebuilds
        NPM_CONFIG_TARBALL: tmp/app/node/headers/node-v16.14.2-headers.tar.gz
        NPM_CONFIG_LOGLEVEL: verbose
    health-check-type: http
    health-check-http-endpoint: /health

folder setup

├── prebuilds
│   ├── v8.12.2/libvips-8.12.2-linux-x64.tar.br
│   └── v0.30.6/sharp-v0.30.5-napi-v5-linux-x64.tar.gz
├── node
│   ├── headers/node-v16.14.2-headers.tar.gz
├── src
├── package.json
├── server.js
├── manifest.yml
└── README.md

Note: our cf installation is on a closed environment, so if you try to reproduce it needs to be in a setting where there is no acces to the www. All the npm packages are available through an internal package manager.

Please confirm where necessary:

CN91 commented 2 years ago

Eventually made it work:

.npmrc

sharp_libvips_local_prebuilds = /tmp/app/binaries/libvips/
sharp_local_prebuilds = /tmp/app/binaries/sharp/v0.30.6/
tarball = /tmp/app/binaries/node_headers/node-v16.14.2-headers.tar.gz