cloudfoundry / nodejs-buildpack

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

Recognize yarn.lock to identify modules already locally provided #288

Closed LsKoder closed 3 years ago

LsKoder commented 3 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? cf.exe version 6.34.1+bbdf814.2018-04-10

What version of the buildpack you are using? buildpack_sdk-for-nodejs_v4.6-20210305-2036.zip

If you were attempting to accomplish a task, what was it you were attempting to do? Deploy App using local node-modules folder (Vendoring App Dependencies) because some dependencies are remotely fetched locally from private repository and they could not be fetched into deploy process. It could be done with both npm install and yarn install Documentation

What did you expect to happen? Running yarn install before cf push MYAPP, it should recognize node_modules/ and yarn.lock, then avoid to fetch dependencies from git (they are already on node_modules)

What was the actual behavior? If I use node install, it works: node_modules/ and package-lock.json are identified and dependencies are automatically resolved. If I use yarn install, it doesn't work: node_modules/ and yarn.lock are not identified and it tries to solve dependency failing (log at the end of this description)

Can you provide a sample app? Nope, It's on private repository but very easy to reproduce. Just create a simple project with a private dependency (e.g. "myProject": "git+ssh://git@github.ibm.com/myOrg/myProject.git#master") Then run yarn install and cf push.

Please confirm where necessary:

ibmcloud app push -b sdk-for-nodejs MYAPP ... Downloading build artifacts cache... Downloading app package... Downloaded app package (20.8M) Downloaded build artifacts cache (132.4M) -----> IBM SDK for Node.js Buildpack v4.6-20210305-2036 Based on Cloud Foundry Node.js Buildpack 1.7.44 -----> Installing binaries engines.node (package.json): ^14.16.0 engines.npm (package.json): unspecified (use default) Attempting to install: 14.16.0 -----> Installing node 14.16.0 Copy [/tmp/buildpacks/ee11c9ac6f9756faa6e0de6c8307a568/dependencies/cf43697bd67888596fd83c3cb7e4378e/node_14.16.0_linux_x64_cflinuxfs3_a194ec21.tgz] Using default npm version: 6.14.11 -----> Installing yarn 1.22.10 Copy [/tmp/buildpacks/ee11c9ac6f9756faa6e0de6c8307a568/dependencies/b7482b661544755fef03e2ceeb19057a/yarn_1.22.10_linux_noarch_any-stack_0057c1c9.tgz] Installed yarn 1.22.10 ... Building dependencies Installing node modules (yarn.lock) Running yarn in online mode To run yarn in offline mode, see: https://yarnpkg.com/blog/2016/11/24/offline-mirror yarn install v1.22.10 [1/4] Resolving packages... [2/4] Fetching packages... error Command failed. Exit code: 128 Command: git Arguments: ls-remote --tags --heads ssh://git@github.ibm.com/myOrg/myApp.git Directory: /tmp/app Output: Host key verification failed. fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command. ERROR Unable to build dependencies: exit status 128 Failed to compile droplet: Failed to run all supply scripts: exit status 14

If npm install is used instead of yarn install it works and log mentions:

-----> Building dependencies Prebuild detected (node_modules already exists) Rebuilding any native modules body-parser@1.19.0 /tmp/app/node_modules/body-parser bytes@3.1.0 /tmp/app/node_modules/bytes content-type@1.0.4 /tmp/app/node_modules/content-type ...

cf-gitbot commented 3 years ago

We have created an issue in Pivotal Tracker to manage this:

https://www.pivotaltracker.com/story/show/177496789

The labels on this github issue will be updated when the story is started.

sophiewigmore commented 3 years ago

Hi there @LsKoder! Are you still having problems with this? Check out the Yarn Offline part of the same docs. For Node.js buildpack versions 1.5.28 and beyond you must provide an npm-packages-offline-cache directory as described there. This should get your build to run in offline mode.

I am going to close out this issue for now, since I believe this should solve the issue you're seeing. If it doesn't, feel free to re-open this issue.

camelpunch commented 2 years ago

We ran into this, and our workaround was:

Then, enable yarn offline cache. When cf pushing, the tarballs go up but the node_modules don't. It'd be nice if the buildpack supported node_modules for yarn, though.

LsKoder commented 2 years ago

I followed your suggestions and configured Yarn Offline Mode using npm-packages-offline-cache. Thanks!