openfaas / faas-cli

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

Distribute on npm for ease of use #645

Closed alexellis closed 4 years ago

alexellis commented 5 years ago

I noticed that the CloudFlare team are distributing their new Rust binary via npm, and It think we could do the same.

Expected Behaviour

Distribute via npm in addition to curl and brew

Current Behaviour

Mac: curl/brew Linux curl (possibly Linux Brew??) Windows: manually go to downloads page

Possible Solution

Look into how CF use Axios to do a HTTP get of the right binary. Perhaps we can execute our get shell script, or copy parts of it into Node.js?

https://github.com/cloudflare/wrangler/blob/master/npm/package.json

At the end we'd have:

npm i -g @openfaas/cli

Would love to see some people get together and make this happen, or have a go at it.

doowb commented 5 years ago

I'll take a shot at this. I'm familiar with npm, node, the GitHub API and getting content from GitHub using axios.

burtonr commented 5 years ago

@doowb let me know if you need any help or testing! Here, or on Slack

alexellis commented 5 years ago

Would be great if you could collaborate together. Any chance of cobbling together a PoC by Friday?

doowb commented 5 years ago

Any chance of cobbling together a PoC by Friday?

I don't think that'll be a problem.

doowb commented 5 years ago

@burtonr PTAL when you have a chance: https://github.com/doowb/faas-cli/tree/npm-postinstall

I've only tested this on Mac OSX (darwin) so far and I don't have Windows specific logic in there yet, but it's installing and moving the files to the correct place.

BTW... the way I'm testing this is to install it using the absolute file path in a random node project with a package.json:

npm install /path/to/openfaas/faas-cli/npm

You should also be able to try from any directory and install globally:

npm install -g /path/to/openfaas/faas-cli/npm
burtonr commented 5 years ago

@doowb How about opening a PR so we can look at the code and comment more specifically there.

That said, I did try this a couple of different ways, but neither was successful. Not an issue since this is the first round of work. I run Linux (Pop!_os/Ubuntu) with a Windows VM (for when I have to)

I found a small mis-type in the getSuffix() function. It should look like this:

if (type === 'Linux') {
    if (arch === 'x64') {
      return ''
    }
    if (arch === 'arch64') {
      return '-arm64'
    }
    if (arch === 'armv61' || arch === 'armv71') {
      return '-armhf'
    }
  }

but even with that fix, there is the permissions issue with attempting to write to /usr/local/bin/... need to have a look at that

doowb commented 5 years ago

Thanks for trying it out on Linux. I'll submit the PR so it's easier to work against.

there is the permissions issue

I was trying different ways to run npm install as root, but even when doing sudo npm install, the uid was never 0.

doowb commented 5 years ago

@burtonr I updated the PR:

The last item is the one that I didn't pick up on when I was looking at the wrangler files and should be the key for allowing the cli to be installed on any system. This also means that a lot of the bash script logic could be skipped to allow npm to do it's job.

Let me know if you have any questions or feedback.

Thanks.

alexellis commented 4 years ago

/close: released

alexellis commented 4 years ago

/lock