Npm install taking a long time during deploy

Hi everybody!

Just started using Sage, although I’ve been a fan of Roots for a long time.

I’m using Bedrock and just got my deployment setup and, as you might guess, npm install is taking quite a long time (~150s). Is this what everyone else is seeing? If so, are there any tips to make this quicker?

I just found npm_lazy which looks like it might help a lot, but just wanted to see if perhaps there was a better solution, or I was doing something wrong?

Here’s what my deploy looks like:

INFO[0558ed4a] Finished in 1.050 seconds with exit status 0 (successful).
INFOUploading /tmp/example.com/git-ssh.sh 100.0%
INFO[f9f3688a] Running /usr/bin/env chmod +x /tmp/example.com/git-ssh.sh on example.com
INFO[f9f3688a] Finished in 0.079 seconds with exit status 0 (successful).
INFO[41095685] Running /usr/bin/env mkdir -pv /home/user/deployments/example.com/shared /home/user/deployments/example.com/releases on example.com
INFO[41095685] Finished in 0.076 seconds with exit status 0 (successful).
INFO[7aa6dff3] Running /usr/bin/env mkdir -pv /home/user/deployments/example.com/shared/web/app/uploads on example.com
INFO[7aa6dff3] Finished in 0.077 seconds with exit status 0 (successful).
INFO[613642b1] Running /usr/bin/env mkdir -pv /home/user/deployments/example.com/shared on example.com
INFO[613642b1] Finished in 0.076 seconds with exit status 0 (successful).
INFOThe repository mirror is at /home/user/deployments/example.com/repo
INFO[4d1e34f1] Running /usr/bin/env git remote update on example.com
INFO[4d1e34f1] Finished in 0.457 seconds with exit status 0 (successful).
INFO[1ed526bb] Running /usr/bin/env mkdir -p /home/user/deployments/example.com/releases/20150226215335 on example.com
INFO[1ed526bb] Finished in 0.074 seconds with exit status 0 (successful).
INFO[75d6bc06] Running /usr/bin/env git archive staging | tar -x -C /home/user/deployments/example.com/releases/20150226215335 on example.com
INFO[75d6bc06] Finished in 0.083 seconds with exit status 0 (successful).
INFO[0ceb7e1c] Running /usr/bin/env echo "f3566a3" >> REVISION on example.com
INFO[0ceb7e1c] Finished in 0.076 seconds with exit status 0 (successful).
INFO[dd24ec3d] Running /usr/bin/env mkdir -pv /home/user/deployments/example.com/releases/20150226215335 on example.com
INFO[dd24ec3d] Finished in 0.078 seconds with exit status 0 (successful).
INFO[1d779207] Running /usr/bin/env ln -s /home/user/deployments/example.com/shared/.env /home/user/deployments/example.com/releases/20150226215335/.env on example.com
INFO[1d779207] Finished in 0.076 seconds with exit status 0 (successful).
INFO[5dbd7a2b] Running /usr/bin/env mkdir -pv /home/user/deployments/example.com/releases/20150226215335/web/app on example.com
INFO[5dbd7a2b] Finished in 0.075 seconds with exit status 0 (successful).
INFO[0e503583] Running /usr/bin/env rm -rf /home/user/deployments/example.com/releases/20150226215335/web/app/uploads on example.com
INFO[0e503583] Finished in 0.075 seconds with exit status 0 (successful).
INFO[7e9db844] Running /usr/bin/env ln -s /home/user/deployments/example.com/shared/web/app/uploads /home/user/deployments/example.com/releases/20150226215335/web/app/uploads on example.com
INFO[7e9db844] Finished in 0.078 seconds with exit status 0 (successful).
INFO[185c3884] Running /usr/bin/env composer install --no-dev --prefer-dist --no-interaction --quiet --optimize-autoloader on example.com
INFO[185c3884] Finished in 2.802 seconds with exit status 0 (successful).
INFO[cf882150] Running /usr/bin/env npm install on example.com
INFO[cf882150] Finished in 146.881 seconds with exit status 0 (successful).
INFO[9baac6b9] Running /usr/bin/env npm run-script build on example.com
INFO[9baac6b9] Finished in 18.180 seconds with exit status 0 (successful).
INFO[479a95f2] Running /usr/bin/env rm -rf /home/user/deployments/example.com/current on example.com
INFO[479a95f2] Finished in 0.080 seconds with exit status 0 (successful).
INFO[16757269] Running /usr/bin/env ln -s /home/user/deployments/example.com/releases/20150226215335 /home/user/deployments/example.com/current on example.com
INFO[16757269] Finished in 0.078 seconds with exit status 0 (successful).
INFOKeeping 5 of 5 deployed releases on example.com
INFONo old releases (keeping newest 5) on example.com
INFO[83138577] Running /usr/bin/env echo "Branch staging (at f3566a3) deployed as release 20150226215335 by aaemnnosttv" >> /home/user/deployments/example.com/revisions.log on example.com
INFO[83138577] Finished in 0.070 seconds with exit status 0 (successful).```

Copy over the node_modules and bower_components directories between releases during the deploy to help speed things up

Check out https://github.com/peterjmit/capistrano-copy-files for a nice Gem to help copy files. It was created for this exact purpose.

1 Like

Thanks for the tips! That gem looks nice, I’ll be sure to check that out.

I added a few lines to my build task to copy the files just using execute which brought down that time quite a bit.

Copying those two takes ~ 13s and npm install now takes ~15s, so much better indeed!

1 Like