Deployment - SissAcademy/SA-backend-dev GitHub Wiki

Deploy backend

Step 1: Create a Digital Ocean droplet

TBD (quite easy actually)

Step 2: Clone the repo and create deploy user

Log inside the new server, you will find the required data inside a mail Digital Ocean sent you when the machine was created.

ssh root@<serverIP>

Now we will create a deployment user.

useradd -s /bin/bash -m -d /home/deploy -c “deploy” deploy
passwd deploy
# if needed
usermod -aG sudo deploy

Logout and login with the new user.

ssh deploy@<serverIP>

Create a key associated with GitHub

To be able to download the code from the server, it is needed a keyfile.

ssh-keygen -t rsa
cat ~/.ssh/id_rsa.pub

Copy the output of the last command as the input for a new Deployment Key in GitHub.

Now we are able to clone the repository in the server to launch it.

git clone [email protected]:SissAcademy/SA-backend-dev.git
cd SA-backend-dev
npm install
npm start

Now the server should be running and accessible from Internet, yay!!!

Step 3: Create the deploy keys

First of all you will need Travis CLI installed in your system.

sudo apt install ruby ruby-dev gcc libffi-dev make
sudo gem install travis

travis login
# travis encrypt-file deploy-key --add

In your local machine, at the repository (the code of the project) root folder, do:

ssh-keygen -t rsa -b 4096 -C '[email protected]' -f deploy_rsa

ssh deploy@<serverIP> mkdir -p .ssh
cat deploy_rsa.pub | ssh deploy@<serverIP> 'cat >> .ssh/authorized_keys'
# for the previous lines you can use ssh-copy-id too

travis encrypt-file deploy_rsa --add

rm -f deploy_rsa deploy_rsa.pub
git add deploy_rsa.enc .travis.yml

Do not add password to the key.

Now we can access the server with deploy user without using the password, only having the key. And Travis has an encrypted version of the key so it can access to the deploy server too.

⚠️ **GitHub.com Fallback** ⚠️