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

Put node_modules in linked_dirs? #7

Closed
vendruscolo opened this issue Mar 7, 2014 · 17 comments
Closed

Put node_modules in linked_dirs? #7

vendruscolo opened this issue Mar 7, 2014 · 17 comments

Comments

@vendruscolo
Copy link

As the title suggests, what do you think about it?
The main advantage would be to speed up deploys, and as I see bundler plugin does a similar thing (although Bundler supports saving to a different path natively, npm will always install to ./node_modules).

I don't know if this is possible from the npm plugin itself (I have little Ruby and capistrano internals knowledge), but we can at least give a hint to users in the read me.

At the moment I simply added

set :linked_dirs, %w{node_modules}

in deploy.rb and it works perfectly.

Thanks.

@swalkinshaw
Copy link
Member

I actually had this as a recommendation in the README a long time ago. See f4224f5.

I think it was removed because of this npm bug npm/npm#1727 which has since been resolved. There may have been another reason but not that I can remember.

One downside to having node_modules in shared/ is you'd have to manually (by default) run npm install again on a rollback. If you think about it, node_modules aren't really shared since they're tied to a specific release (their versions at least). It's wasteful, and a bit slower, but it might be more proper to not share them.

@vendruscolo
Copy link
Author

Uh, I didn't think of rollbacks, you're right. How is that managed for capistrano/bundler? It runs bundle update after rollbacks? I'm curious.

Anyway, for my use case I think I'll keep node_modules symlinked because I use node just to compile assets, and dependencies will almost never change.

@swalkinshaw
Copy link
Member

Looks like it isn't managed at all by the bundler plugin. They only run bundle install on deploy:updated which doesn't happen in the rollback flow.

Seems like they should also hook into deploy:reverted to fix that. That extra hook would also work for this npm plugin too, but as I said, I'm not sure about doing this by default.

@vendruscolo
Copy link
Author

Having faster deploys is sure a nice to have feature.

If there aren't other edge cases, I'd go for it (also for Bundler, Composer and others). We could gain faster deploys (the downside is that rollbacks will become slower because they have to run npm install again).
Maybe we can add an option so the user can enable and disable it...?

@akshah123
Copy link

I would like to vote for faster deploys as well. Having to install the same packages over is problematic on production servers as that can take up a lot of resources affecting actual production workload.

@swalkinshaw
Copy link
Member

I'm still going to think about this, but just note that you can easily do this yourself for now with:

set :linked_dirs, %w{node_modules}

And if you want rollbacks to be auto just add:

before 'deploy:reverted', 'npm:install'

@akshah123
Copy link

@swalkinshaw Thanks for the update. Somehow I missed that. For now, I will def go with this workaround. Just a quick question, does the set command overwrite the list or does it push it?

@swalkinshaw
Copy link
Member

@akshah123 it would override it, you want to add in node_modules if you already have anything in there:

set :linked_dirs, %w{logs node_modules}

@akshah123
Copy link

Cool. Anybody else looking at this, I used following so that it would push instead. This is so that it doesn't play foul with any other modules such as rails.

# Default value for linked_dirs is []
linked_dirs = Set.new(fetch(:linked_dirs, [])) # https://github.com/capistrano/rails/issues/52
linked_dirs.merge(%w{node_modules})
set :linked_dirs, linked_dirs.to_a

@peterjmit
Copy link

I am lacking documentation, but I wrote this library to address exactly this problem https://github.com/capistrano/copy-files.

Instead of sharing dependencies, it can copy a directory from a previous release, into the new release

@swalkinshaw
Copy link
Member

npm maintains a local cache and there's the extension above which would make deploy faster. So I'm closing this.

@c0
Copy link

c0 commented Mar 13, 2015

@swalkinshaw npm's cache doesn't include anything compiled. For example, node-sass compiles libsass on each of our deploys (even though the src is cached).

@swalkinshaw
Copy link
Member

@c0 never knew that, thanks. But even so there's an extension to manage this: https://github.com/capistrano/copy-files

@milushov
Copy link

@c0 good pint, so what you can suggest for speed up npm install during deployment? How can I skip compilation with capistrano/copy-files for node-sass for example?

@h0jeZvgoxFepBQ2C
Copy link

+1 I would also like to know..

@dmitry
Copy link

dmitry commented Oct 20, 2016

I think it's a good idea to reopen and discuss on this issue and document all this stuff in the readme.

@andyexeter
Copy link

@milushov @lichtamberg to skip compilation in node-sass you just need to use copy-files to copy the node_modules directory from the previous release:

set :copy_files, ['node_modules']

You may also want to prune the directory before npm install gets called:

before 'npm:install', 'npm:prune'

@capistrano capistrano locked and limited conversation to collaborators Jan 24, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants