openfaas / faas-cli

Official CLI for OpenFaaS
https://www.openfaas.com/
Other
798 stars 224 forks source link

npm installation is broken #740

Closed alexellis closed 4 years ago

alexellis commented 4 years ago

Expected Behaviour

This should work:

npm install @openfaas/faas-cli

Current Behaviour

kosmos:tmp alex$ npm install @openfaas/faas-cli

> @openfaas/faas-cli@0.11.3 postinstall /private/tmp/node_modules/@openfaas/faas-cli
> node -e 'require("./install.js").init()'

Download failed! name is not defined
npm WARN enoent ENOENT: no such file or directory, open '/private/tmp/package.json'
npm WARN tmp No description
npm WARN tmp No repository field.
npm WARN tmp No README data
npm WARN tmp No license field.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @openfaas/faas-cli@0.11.3 postinstall: `node -e 'require("./install.js").init()'`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the @openfaas/faas-cli@0.11.3 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/alex/.npm/_logs/2019-12-19T13_59_27_269Z-debug.log

Possible Solution

@burtonr @doowb can you look at the changes made in https://github.com/openfaas/faas-cli/pull/723 and suggest a fix please?

burtonr commented 4 years ago

It looks like on this line, the name should be changed to binaryName https://github.com/openfaas/faas-cli/blob/master/npm/install.js#L20

alexellis commented 4 years ago

Which instance of "name"?

let release = releases.find(release => release.name === name);

burtonr commented 4 years ago

Current line:

    let release = releases.find(release => release.name === name);

should be:

    let release = releases.find(release => release.name === binaryName);
alexellis commented 4 years ago

How did the unit tests pass if this is not right?

alexellis commented 4 years ago

I get the same error (404) after the patch

[alex@nuc tmp]$ npm install @openfaas/faas-cli

> @openfaas/faas-cli@0.11.3-1 postinstall /tmp/node_modules/@openfaas/faas-cli
> node -e 'require("./install.js").init()'

Download failed! Request failed with status code 404
npm WARN enoent ENOENT: no such file or directory, open '/tmp/package.json'
npm WARN tmp No description
npm WARN tmp No repository field.
npm WARN tmp No README data
npm WARN tmp No license field.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @openfaas/faas-cli@0.11.3-1 postinstall: `node -e 'require("./install.js").init()'`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the @openfaas/faas-cli@0.11.3-1 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/alex/.npm/_logs/2019-12-19T14_12_38_941Z-debug.log
alexellis commented 4 years ago

Not sure why we get the releases then iterate? Without authentication this can fail and use up the GitHub API rate-limit. We can just run HEAD against the latest release HTML page and read the result. We do this for getting kubeseal and in the get.sh script.

burtonr commented 4 years ago

I see. There's a problem with the packaging.

no such file or directory, open '/tmp/package.json'

Part of the install process is to read the package.json file from the local directory. It's one thing to know that it works with the repository (faas-cli) cloned locally and running the script, it's another to ensure that the package is created and shared properly.

If @doowb doesn't get to it first, I will take care of this over weekend.

The testing will need to include publish and install, and not limited to run running the script.

alexellis commented 4 years ago

Can you migrate the test to use mocha please?

https://mochajs.org/#getting-started

I've made a fix for the time being and re-published. It also uses the HTML page now instead of the API which is rate-limited.

burtonr commented 4 years ago

@alexellis not sure if there was still an issue with the actual installation after your fix. I did try it on my system, and it worked perfectly. That said, I did update the tests to use the Mocha library on PR #743 for your review.