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

New API + use bin-wrapper (bundle in all arch without any concern) + global install #89

Closed
wants to merge 26 commits into from

Conversation

JGAntunes
Copy link
Member

[WIP]
This should close #78, it's still a work in progress but let me know what you think so far.

There are still some issues though and further testing is needed. Also somehow the ipfs init command hangs for version 0.4.2, still have to look at what's going on with it.

@JGAntunes
Copy link
Member Author

Ok, looks like the 0.4.2 issue is a known one ipfs/kubo#2748

"ipfs-api": "^4.1.0",
"multiaddr": "^2.0.0",
"rimraf": "^2.4.5",
"run-series": "^1.1.4",
"shutdown": "^0.2.4",
"subcomandante": "^1.0.5"
"subcomandante": "^1.0.5",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we still need this module with bin-wrapper?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, because despite having a run method (which is poorly named in my opinion) this will only act like a search for the binary and run a test command to check everything is ok (usually --version or version in our case), not considering any outputs and such. So we still need something to run the command itself and, as we already use subcomandante, I assume it's probably the best choice.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just filed an issue with node-core about not cleaning up spawned processes. So maybe in a near future we don't need it anymore :)
nodejs/node#7951

@daviddias
Copy link
Member

This is awesome @JGAntunes :D

Yeah, the issue with 0.4.2 exists, it has been fixed for 0.4.3, we just have to wait for that release. This module hasn't have any documentation so far, would you like to give a stab at it too? It will help us make sure we are fulfilling the right interface needs, @haadcode and @dignifiedquire will probably want to review the interface too.

@@ -322,7 +322,7 @@ describe('external ipfs binaray', () => {
ipfsd.local((err, node) => {
if (err) throw err

assert.equal(node.exec, '/some/path')
assert.equal(node.exec, '/some/path/ipfs')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you change from assert to expect?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing 👍

@JGAntunes
Copy link
Member Author

@diasdavid as for the documentation, sure! I'll give it a look once all this stuff is sorted out.

@daviddias
Copy link
Member

Thank you :)

@@ -0,0 +1,16 @@
'use strict'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All files should be under src

@JGAntunes
Copy link
Member Author

Ok, let me know what you all think. Still missing documentation and further testing @diasdavid @dignifiedquire

@JGAntunes
Copy link
Member Author

While building some more tests I've noticed there's an issue with the way subcomandante handles the close event.
https://github.com/jbenet/node-subcomandante/blob/master/fork.js#L19
It may emit a new error when no further events are expected. This makes it practically impossible to handle it correctly as it is emitted after the close and end events and one doesn't know what to expect next.

@daviddias
Copy link
Member

@JGAntunes Do we still need to use subcomandante with bin-wrapper?

Let's make this PR work with 0.4.3-rc1, so that we can use it to test js-ipfs-api as well

Do you need help with the documentation part?

@JGAntunes
Copy link
Member Author

@diasdavid we still need something to run and exec the commands, the bin-wrapper run method only serves for the single purpose of testing the binary and not much more. Although, if we still want to use subcomandante, we need to fix the way the exit code is handled.

Alright, I'll update the binary for 0.4.3-rc1

I was waiting for some feedback on the matters above so I can start documenting stuff. If the API will remain unchanged I can start working on that right away.

config.baseUrl = 'https://dist.ipfs.io/go-ipfs/' +
config.version +
'/go-ipfs_' +
config.version + '_'
Copy link
Member

@dignifiedquire dignifiedquire Jul 27, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could use path.join

const distPage = 'https://dist.ipfs.io'
const version = config.version
config.baseUrl = path.join(distPage, 'go-ipfs', version, `go-ipfs_${version}`)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately path.join when used on URLs strips down the // to / and invalidates it. The result would be https:/dist.ipfs.io/go-ipfs/v0.4.1/go-ipfs_v0.4.1. I can leave the protocol aside, join it later and join everything else with path.join if you think that's worth it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh right, I forgot about that :( No it's not worth it then, but you could instead do [..].join('/')

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, true! I was also thinking on using template strings, something like:

const version = config.version
config.baseUrl = `https://dist.ipfs.io/go-ipfs/${version}/go-ipfs_${version}_`

Do you prefer this or the Array.join?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the just template strings is actually much more readable in this case :)

@daviddias
Copy link
Member

@JGAntunes you can run any command with bin-wrapper -- https://www.npmjs.com/package/bin-wrapper#runcmd-callback -- too, running run('daemon', () =>) will keep the daemon process till it is closed. Check how Akasha did it https://github.com/AkashaProject/ipfs-connector/blob/master/src/IpfsConnector.js

@dignifiedquire
Copy link
Member

@diasdavid we just need to ensure that it closes the process when the parent process dies (which is why node-subcommandante exists in the first place)

@JGAntunes
Copy link
Member Author

@diasdavid if you check the bin-wrapper source code the run method will only run as a binary check, it is not appropriate to run complex commands such as those needed here https://github.com/kevva/bin-wrapper/blob/master/index.js#L123. It will basically check the exit code of the command and that's it, nothing more.

I've already looked at how Akasha did it and if you look at it they also don't use bin-wrapper run to run anything at all besides the binary check - https://github.com/AkashaProject/ipfs-connector/blob/edd901e5b4bff9ed2783f44cb82797f49d68d54b/src/IpfsBin.js#L24. For the commands they still rely on a regular childProcess.spawn - https://github.com/AkashaProject/ipfs-connector/blob/master/src/IpfsConnector.js#L112

@daviddias
Copy link
Member

@JGAntunes got it, thank you :)

@daviddias
Copy link
Member

I was waiting for some feedback on the matters above so I can start documenting stuff. If the API will remain unchanged I can start working on that right away.

We need to at least:

  • spawn daemon - spawn a deamon with a repo from a 'path'
  • spawn daemon and get a js-ipfs-api object that is connected to it
  • spawn disposable daemon (optional config) - a daemon with a fresh repo
  • spawn disposable daemon and get a js-ipfs-api object that is connected to it

@haadcode
Copy link
Member

We also need:

  • make sure the daemon process gets killed in all cases
  • daemon respects IPFS_PATH env variable (ie. spawn a daemon using repo from IPGS_PATH)

@JGAntunes
Copy link
Member Author

This PR should fix the issues around node-subcomandate jbenet/node-subcomandante#5. FYI @dignifiedquire @diasdavid

@dignifiedquire
Copy link
Member

@JGAntunes can you please add the aegir@6 update to this PR

@dignifiedquire
Copy link
Member

@JGAntunes as soon as sindresorhus/execa#53 is merged and released I suggest using that instead of subcomandante to spawn and control the daemon. It's a much nicer and well maintained module.

@JGAntunes
Copy link
Member Author

Hey folks, sorry for being kind of away towards the end of this week. @dignifiedquire will update the aegir module during this weekend and make the change to execa once your PR is merged 👍 I'll also try to give it a go on the documentation.

@dignifiedquire
Copy link
Member

Thank you @JGAntunes for the great work here. We have updated go-ipfs-dep to include a lot of the things we learned from here and more, so we don't need to implement all the binary handling here :)
The internal improvements of using execa and your exec.js I have pulled in manually in 7b09529

Again thank you for all the work and keeping with us.

In terms of the actual interface changes I think we will want to go with the ideas here: ipfs/js-ipfs#556
as we are attempting to unify the interfaces between spawning a js and a go daemon.

@daviddias daviddias added the status/deferred Conscious decision to pause or backlog label Dec 22, 2016
@daviddias
Copy link
Member

Merged #140, closing this one. @JGAntunes again thank you for helping out with these issues and my apologies for the huge lag from PR to actually getting something merged in, this module is highly sensible as it touches running processes at the OS level and so improvements have to happen slowly (execa vs subcomandante), as for the remaining features added, as @dignifiedquire noted, they were added to npm-go-ipfs-dep, which is now capable of picking the right dist through a package.json value.

Again, thank you <3

@daviddias daviddias closed this Dec 23, 2016
@daviddias daviddias removed the status/deferred Conscious decision to pause or backlog label Dec 23, 2016
@JGAntunes
Copy link
Member Author

Np folks, glad I could help out anyway 👍

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

Successfully merging this pull request may close these issues.

Upgrade js-ipfsd-ctl to use bin-wrapper
5 participants