Use an automated service to manage the auto deployment of nodeJS systems on Ubuntu based on Express and PM2
Create a new Server on your favorite hosting company (fasthosts.com?)
Generate an SSH Key for deployments on your server (after setting it up and securing it correctly)
ssh-keygen -t rsa -b 4096 -C "[email protected]"
cat ~/.ssh/id_rsa.pub
Install SSH Key to GitHub by opening the link to your repository in Github.com, click on settings and then click on Deploy Keys and add the key from Step 2 to that list, you will have to enter your password to confirm in this step. You do NOT need Write access on this Deployment Key to use this package, this system will only read from Github.
Setup a hostname
echo "mydomain.com" > /etc/hostname
Install Stack and auto deployer on server
apt update
apt -y upgrade
apt -y autoremove
apt install -y git mongodb nodejs npm certbot nginx python3-certbot-nginx
npm i -g pm2 gitselfdeploy
pm2 startup
Install the repository and start it in pm2 Note: Please replace MYUSERNAMEINGITHUB with the Github User and MYREPOSITORYINGITHUB with the repository name
cd /var
rm -rf www/
mkdir www/
cd www/
git clone [email protected]:MYUSERNAMEINGITHUB/MYREPOSITORYINGITHUB .
npm i
pm2 start index.js
pm2 start gitselfdeploy
pm2 save
Setup webhook for updates by opening the repository link in Github.com and click on settings, then click on Webhooks and add "http://mydomain.com:3420/" to the list set to only POST and send the event.
Reboot to lock in the changes and be sure it all automatically starts up!
reboot
Install SSL for the webhook in your repository, if using letsencrypt you are almost done
echo "/etc/letsencrypt/live/mydomain.com" > /var/selfDeploySSLCert
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.