Skip to content

Instantly share code, notes, and snippets.

@Xhamps
Last active August 29, 2015 14:14
Show Gist options
  • Save Xhamps/04d064d8a37bc12bee87 to your computer and use it in GitHub Desktop.
Save Xhamps/04d064d8a37bc12bee87 to your computer and use it in GitHub Desktop.
PM2 + Git + Proxy reverso como método de deploy
//Tutorial https://www.youtube.com/watch?v=h39l3th5Gkg&list=WL&index=2
//Updata machine and install dependeces
sudo apt-get update
sudo apt-get install nodejs
sudo apt-get install nodejs-legacy
sudo apt-get install npm
sudo apt-get install git
sudo apt-get install htop
//Fix the locales error
sudo locale-gen pt_BR.UTF-8
sudo dpkg-reconfigure locales
//Install pm2
npm install -g pm2
pm2 startup ubuntu
// Create a new user
useradd web
userdel web
adduser web
// Create repository
cd ~
mkdir teste.git
cd teste.git
git init --bare
mkdir teste
cd teste
git init
git remote add origin /home/wen/teste.git
//Config hooks
cd ~/teste.git/hooks
mv post-update.sample post-update
vim post-update
//
// Start template
//
#!/bin/sh
unset $(git rev-parse --local -env-vars) // Setar todas variaves de ambiente
cs ~/{{teste}}
git pull origin master
npm install --production
pm2 delete {{teste}} // Deletar o processo
pm2 start app.js --name {{teste}} -x // Iniciar o processo
//
// Finish template
//
// Config git remote
git remote add deploy web@{{IP MAQUINA}}:~/teste.git
git push deploy master
//Allow to bind the port 80
setcap 'cap net bind service=+ep' /usr/bin/nodejs
//Firewall
ufw
ufw enable
ufw allow 22
ufw allow 80
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment