Deployment - SissAcademy/SA-backend-dev GitHub Wiki
TBD (quite easy actually)
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>
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!!!
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.