npm / ndm

ndm allows you to deploy OS-specific service-wrappers directly from npm-packages.
ISC License
180 stars 22 forks source link

ndm <cmd> <npm-package> #39

Closed seanewest closed 10 years ago

seanewest commented 10 years ago

I would love to be able to ship an npm package (with a service.json) that can be installed as a service, right away, like so:

npm install -g <my-package>
ndm generate <my-package>

Same goes for start/stop etc.

Currently one has to create a wrapper around services that are dependencies. I can understand this setup in a devops environment where you want to package together and distribute services, and in addition with specific args for ports etc.

But I think it would also be cool if in addition there was a more basic use case where you could just start an individual service directly from the npm package, without creating a wrapper at all.

If I'm not mistaken to pull this off you would need to allow top-level scripts in the service.json, right next to the top-level args and env.

I'd be more than willing to send a PR if this sounds like something that could get merged.

bcoe commented 10 years ago

I love this idea, and have had it on my mind as well. Would happily merge a PR.

bcoe commented 10 years ago

@seanewest perhaps, for this use-case, ndm could interview the user for environment variables while generating the scripts directly from the package?

seanewest commented 10 years ago

Yeah I think thats a good idea to interview automatically when generating a global package

How does this sound:

:boom: treat the globally installed package just like a single node-packaged service, where we basically pull all of the bin/scripts/env/args from the package.json, which could include hints for the interview process.

:boom: packages can optionally include a service.json. I was assuming no sub-services like an ndm wrapper though.

:boom: commands supported (at least for now?): generate start stop restart. Technically there could be a namespace collision with ndm start <service-name> and ndm start <package-name> when you are in the folder of an ndm wrapper but I was thinking we could just allow that.

Edit: I accidentally deleted this message and reposted it. Had to inspect the html in devtools to get the message back!

bcoe commented 10 years ago

@seanewest this sounds like exactly what I was picturing. Any thoughts about how we'll figure out where the global npm modules are installed? I bet we can include a dependency from the npm-cli to introspect this.

seanewest commented 10 years ago

I was just figuring we could use <prefix>/lib/node_modules no?

As in the following code:

var npm = require('npm')
var path = require('path')
var pkg = 'myservice' //as in ndm <cmd> myservice

npm.load(function (er, npm) {
  var prefix = npm.config.get('prefix')
  var pkg_path = path.join(prefix, 'lib', 'node_modules', pkg)
  console.log(pkg_path)
})
bcoe commented 10 years ago

That seems nice and simple.

On Sunday, July 27, 2014, seanewest notifications@github.com wrote:

I was just figuring we could use /lib/node_modules no?

As in the following code:

var npm = require('npm')var path = require('path')var pkg = 'myservice' //as in ndm myservice npm.load(function (er, npm) { var prefix = npm.config.get('prefix') var pkg_path = path.join(prefix, 'lib', 'node_modules', pkg) console.log(pkg_path)})

— Reply to this email directly or view it on GitHub https://github.com/npm/ndm/issues/39#issuecomment-50286296.

bcoe commented 10 years ago

@seanewest I like the idea that ndm start service would first look for a local service.json, and then fall back to looking in the global packages directory, a couple questions:

I could see this being a simpler flow.

bcoe commented 10 years ago

@seanewest I think that this, https://github.com/npm/ndm/pull/47/files, gets things part of the way towards what you're looking for.

I needed this myself to make it easier to deploy services directly from packages.

seanewest commented 10 years ago

Awesome! That helps a lot. Sorry I haven't been able to work on this, I can take a crack at it this weekend.

On Wednesday, July 30, 2014, Benjamin E. Coe notifications@github.com wrote:

@seanewest https://github.com/seanewest I think that this, https://github.com/npm/ndm/pull/47/files, gets things part of the way towards what you're looking for.

I needed this myself to make it easier to deploy services directly from packages.

— Reply to this email directly or view it on GitHub https://github.com/npm/ndm/issues/39#issuecomment-50660488.

rmg commented 10 years ago

What about adding ndm as a dependency and using an API to allow module authors to write an install command/sub-command? It sounds like feature/scope creep, but I think it would actually help curb such creep by letting module authors handle their special cases on their own without requiring extensions to ndm that nobody has thought of yet.

bcoe commented 10 years ago

@rmg I like the simplicity of this. A module author could:

  1. include ndm as a dependency.
  2. add start, stop, restart, install, uninstall bins.
  3. pop a service.json in the module that allows for interviewing about ENV variables.

and, boom self-installable service. I think we actually have everything we need to do this already, although we might want to write some tests around the use-case + documentation.

rmg commented 10 years ago

Then the module author could use ndm programatically in their custom installer so they could do extra things like create users, files, directories, whatever, as part of the interview/install process without ndm needing to add explicit support for such actions.