I have a Node.js server (managed using PM2) hosted on an EC2 instance running Ubuntu 16.04. To access my application server and update the code, I need to SSH to the jump server, then SSH into the application server, pull the latest code from GitLab and then restart the server via PM2.
The process looks like this:
$ ssh -i access_jump_server.pem ubuntu@11.11.111.111
$ ssh -i /home/ubuntu/access_application_server.pem ubuntu@222.22.22.22
$ cd app-server
$ git pull origin master
$ pm2 restart ../ecosystem.config.js
The application server (222.22.22.22) can be accessed only from the jump server and nowhere else due to security restrictions in place.
How can I automate these tasks using a bash script so I can enable continuous deployment via GitLab CI?