Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Buildpack builds for Node cloudevents template fail on second run if no node_modules exist #1131

Closed
jramcast opened this issue Jul 20, 2022 · 9 comments
Milestone

Comments

@jramcast
Copy link

We are experiencing this problem with Node.js functions generated from the cloudevents template.

The kn func build command generates a working Node.js image in the first execution. However, in subsequent executions, the build command generates a failing image. When we run the second image with kn func run, we get this error:

Function started on port 8080
⛔ Error: Cannot find module 'cloudevents'
Require stack:
- /workspace/index.js
- /layers/paketo-buildpacks_npm-install/launch-modules/node_modules/faas-js-runtime/bin/cli.js

We also noticed that this problem only happens if we have not previously run npm ci locally, meaning that the node_modules dir does not exist.
In this case, the output of the 2nd time we run kn func build -v got our attention, specially those cached layers:

Paketo NPM Install Buildpack 0.10.1
  Resolving installation process
    Process inputs:
      node_modules      -> "Not found"
      npm-cache         -> "Not found"
      package-lock.json -> "Found"

    Selected NPM build process: 'npm ci'

  Reusing cached layer /layers/paketo-buildpacks_npm-install/build-modules
  Reusing cached layer /layers/paketo-buildpacks_npm-install/launch-modules

However, if we run npm ci before running kn func build, then the selected NPM build process changes to npm rebuild and the generated image works.

Versions

  • OpenShift Serverless: 1.23
  • kn: v1.2.0
  • kn func: v0.24.0

Steps to reproduce

  • kn func create -l node -t cloudevents foo
  • kn func build -p foo
  • kn func run -p foo // Works fine
  • Modify index.js
  • kn func build -p foo
  • kn func run -p foo // Fails
@matejvasek
Copy link
Contributor

/cc @lance

@lance
Copy link
Member

lance commented Jul 20, 2022

This appears to be an issue with the Paketo Node.js builder. I don't know exactly what the problem is at the moment, but I have been able to reproduce it with the following steps.

kn func create -l node -t cloudevents foo
cd foo
pack build --builder gcr.io/paketo-buildpacks/builder:base quay.io/lanceball/foo
docker run --rm -it -p 8080:8080 quay.io/lanceball/foo # works fine
# Modify index.js
pack build --builder gcr.io/paketo-buildpacks/builder:base quay.io/lanceball/foo
docker run --rm -it -p 8080:8080 quay.io/lanceball/foo # Fails with the same error noted above using func

I will keep poking around.

@lance
Copy link
Member

lance commented Jul 20, 2022

I have now reproduced the issue without using func at all. Here is the project

package.json

{
  "name": "bar",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "node index.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "cloudevents": "^6.0.2"
  }
}

index.js

var http = require('http');
const { CloudEvent } = require('cloudevents');

//create a server object:
http.createServer(function (req, res) {
  res.write('Hello World!');
  res.end();
}).listen(8080);

Create these two files in a directory and run the following steps.

pack build --builder gcr.io/paketo-buildpacks/builder:base quay.io/lanceball/bar
docker run --rm -it -p 8080:8080 quay.io/lanceball/bar # works fine
# Modify index.js
pack build --builder gcr.io/paketo-buildpacks/builder:base quay.io/lanceball/bar
docker run --rm -it -p 8080:8080 quay.io/lanceball/bar # Fails with the same error noted above

@lance
Copy link
Member

lance commented Jul 20, 2022

@jramcast thanks for reporting this issue. I have dug into it a bit and determined that the root cause is a bug in the paketo npm-install buildpack, and have opened an issue there. In the meantime, it seems that the bug only occurs when there is no node_modules folder locally. Perhaps for the time being, you can include an npm ci in your local workflow. Sorry about the inconvenience.

@lance lance changed the title Wrong container image is built from Node.js cloud events template Buildpack builds for Node cloudevents template fail on second run if no node_modules exist Jul 20, 2022
@jramcast
Copy link
Author

@lance thanks for the quick response. Yes, installing the dependencies fixed the issue for us.

@salaboy
Copy link
Member

salaboy commented Jul 21, 2022

@jramcast @lance can we close this issue now ?

@lance
Copy link
Member

lance commented Jul 21, 2022

@salaboy I'd like to keep it open to track as a known issue until the paketobuildpacks/npm-install buildpack provides a fix.

@lance lance added the MVP label Jul 28, 2022
@lance lance added this to the 1.0.0 Release milestone Jul 28, 2022
@lance lance moved this to Icebox in Func Roadmap Jul 28, 2022
@lance
Copy link
Member

lance commented Aug 15, 2022

A PR has been submitted for a fix of this today paketo-buildpacks/npm-install#393

@lance
Copy link
Member

lance commented Aug 23, 2022

The latest release of the Node.js buildpack from Paketo contains a fix for this. Closing. https://github.com/paketo-buildpacks/nodejs/releases/tag/v0.23.0

@lance lance closed this as completed Aug 23, 2022
Repository owner moved this from Icebox to In Design in Func Roadmap Aug 23, 2022
@lance lance moved this from In Design to Done in Func Roadmap Aug 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants