Configurar chave SSH
Criar Droplet
Realizar update e upgrade
Crua usuário adduser deploy
e usermod -aG sudo deploy
Cria pasta .ssh
pro deploy
cp ~/.ssh/authorized_keys /home/deploy/.ssh/authorized_keys
chown -R deploy:deploy .ssh/
chmod 700 .ssh
chmod 600 .ssh/authorized_keys
Testa conexão com usuário deploy
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt install nodejs
Install Yarn
apt install docker.io
sudo usermod -aG docker $USER
Configuração do banco de dados
docker run --name database -e POSTGRES_PASSWORD=E5ag2rSm6Pz7UZC4 -p 5432:5432 --restart always -d postgres
docker exec postgres -it /bin/bash
su -u postgres
e psql
CREATE DATABASE myapp;
CREATE USER rocketseat WITH ENCRYPTED PASSWORD 'uBaPt2H4rJTp8T59';
GRANT ALL PRIVILEGES ON DATABASE myapp TO rocketseat;
Configuração da aplicação
Clone Masterclass SQL
Configurar script "start": "node src/server.js"
Testar aplicação
Configurar dotenv
NODE_ENV=development
PORT=3333
DB_HOST=localhost
DB_NAME=sqlnode
DB_USER=docker
DB_PASS=docker
Adiciona .env
no .gitignore
Cria .env.example
Sobe app no Github
Realiza clone
Cria .env
com credenciais do banco e production
Executa yarn sequelize db:migrate
Executa app e testa no Insomnia
yarn global add pm2
export PATH="$(yarn global bin):$PATH"
no .bashrc
source ~/.bashrc
pm2 start src/server.js --name myapp-server
pm2 startup ubuntu -u deploy
Executa comando retornado
pm2 save
sudo reboot
Configuração do NGINx/domínio/SSL
apt install nginx
(como root)
cp /etc/nginx/sites-available/default /etc/nginx/sites-available/myapp-server
server {
server_name nodedeploy.rocketseat.com.br;
location / {
proxy_pass http://127.0.0.1:4000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_cache_bypass $http_upgrade;
}
}
ln -s /etc/nginx/sites-available/myapp-server /etc/nginx/sites-enabled/
nginx -t
e service nginx restart
Configura DNS e aguarda propagação
Acompanha em https://www.whatsmydns.net/
Executa certbot (https://certbot.eff.org/lets-encrypt/ubuntubionic-nginx )
Configuração de monitoramento e logs