1

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?

Daksh
  • 956
  • 6
  • 19

1 Answers1

0

How can I automate these tasks using a bash script so I can enable continuous deployment via GitLab CI?

If you can put those commands in a bash script and make it run successfully on your GitLab agent (where GitLab CI would execute any task you want), then that would be enough to enable that process automation.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I added those commands in the same order to my bash script but only the first command is executed (SSH into the jump server) and then nothing happens. Is there a way to run the second command in this new environment and all subsequent commands in the environment (SSH into the server via jump server) after that? Thanks! – Daksh Dec 29 '18 at 08:57
  • @DakshShah only if the SSH session is an interactive one, which it is not in a GitLab-CI pipeline. The alternative is to execute only one command: a script, which includes all the commands you need. – VonC Dec 29 '18 at 09:10
  • Thanks, but I added these commands to a local bash script on macOS. It still halts after the first command and nothing happens. – Daksh Dec 29 '18 at 09:27
  • @DakshShah by commands, you mean the cd, git pull and pm2? – VonC Dec 29 '18 at 17:47
  • Yes, that's right. Even the second ssh command doesn't run. The cd, git pull and pm2 commands should run in the new environment after the second ssh command. – Daksh Dec 30 '18 at 06:35
  • My point was: the script should not include any SSH command, only the command to run on the remote server – VonC Dec 30 '18 at 06:36
  • Oh, I get it now! But what about the second SSH command that has to run in the environment created after the first SSH? – Daksh Dec 30 '18 at 06:47
  • @DakshShah the first ssh should run a script which executes the second ssh, which should run a script with the cd, git pull and pm2 commands in it. – VonC Dec 30 '18 at 09:18