Last active
August 21, 2017 07:35
-
-
Save TheNicholasNick/7a1c68b0afc94680ccf060507db3e579 to your computer and use it in GitHub Desktop.
NPM Proxy Cache - save pulling from the internet all the time...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# For Ubuntu 16.04 vm guest where I code, windows host | |
# prefer not to have system installed node/go/erlang/elixir/etc | |
# thanks http://willcodefor.beer/setup-your-own-npm-cache-server/ for the idea! | |
sudo useradd -m -c "NPM-Proxy-Cache" npmpc | |
sudo su npmpc | |
cd | |
git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.1.0 | |
echo '. $HOME/.asdf/asdf.sh' >> ~/.bashrc | |
echo '. $HOME/.asdf/completions/asdf.bash' >> ~/.bashrc | |
source .bashrc | |
asdf plugin-add nodejs https://github.com/asdf-vm/asdf-nodejs.git | |
asdf install nodejs 6.7.0 | |
asdf global nodejs 6.7.0 | |
npm install -g forever npm-proxy-cache | |
cat <<EOT >> ~/run-npm-proxy-cache | |
#!/bin/bash | |
. $HOME/.asdf/asdf.sh | |
. $HOME/.asdf/completions/asdf.bash | |
forever /home/npmpc/.asdf/installs/nodejs/6.7.0/.npm/bin/npm-proxy-cache -e -t 600000 -h 0.0.0.0 -p 6060 | |
EOT | |
chmod 700 ~/run-npm-proxy-cache | |
/usr/bin/screen -dmS npmProxyCache bash -c "/home/npmpc/run-npm-proxy-cache; exec bash" | |
exit | |
sudo sed -i -e "/^exit 0/i\/bin/su npmpc -c \"/usr/bin/screen -dmS npmProxyCache bash -c \'/home/npmpc/run-npm-proxy-cache; exec bash\'\"" /etc/rc.local | |
npm config set proxy http://127.0.0.1:6060/ | |
npm config set https-proxy http://127.0.0.1:6060/ | |
npm config set strict-ssl false | |
# done, npm now uses the cache and when the vm restarts, the proxy is restarted. | |
# the proxy is also accessible from other vms as long as networking is configured etc | |
# can also use the proxy from windows host if I wanted to |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
so acutally measured with and without npm-proxy-cache and seems to be about the same.. | |
of course uses less data which is good, as never able to know if others in the house | |
are streaming youtube/netflix etc and will help with 4G data. keep it for now... | |
might also assist with avoiding the common "callback called more than once" error - especially with the CI/CD setup | |
>>>>>> | |
$ time ember new before-npmpc | |
installing app | |
... | |
Installed packages for tooling via npm. | |
Installed browser packages via Bower. | |
real 1m16.285s | |
user 0m55.620s | |
sys 0m15.644s | |
<<<<<< | |
>>>>>> | |
$ time ember new after-npmpc | |
installing app | |
... | |
Installed packages for tooling via npm. | |
Installed browser packages via Bower. | |
real 3m21.323s | |
user 0m55.844s | |
sys 0m22.480s | |
<<<<<< | |
>>>>>> | |
$ time ember new after-npmpc-cache-primed | |
installing app | |
... | |
Installed packages for tooling via npm. | |
Installed browser packages via Bower. | |
real 1m26.122s | |
user 1m4.024s | |
sys 0m19.880s | |
<<<<<< | |
>>>>>> | |
$ time ember new after-npmpc-cache-primed-take2 | |
installing app | |
... | |
Installed packages for tooling via npm. | |
Installed browser packages via Bower. | |
real 1m15.241s | |
user 0m59.940s | |
sys 0m15.992s | |
<<<<<< |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment