The deployment script is public and is available here. It is also embedded below for a quick reference!

{% gist vaibhav-kaushal/bb5976b15d486345fe52a38ce5a5f5f4 %}

Remember that variables declared in the file (near the top) have dummy value and will cause errors if you run the script without setting them. Replace them according to your requirement. Please read the deployment process if you are unsure about what they do. {: .notice—danger}

How to use the script

The script is to be placed on the server. I normally place it in ~/scripts directory. If you save the script as deploy.sh, then it would be placed with the full path being: /home/ubuntu/scripts/deploy.sh. Of course you would have to make it executable. To do that, (assuming the path being the same as mentioned above) run this:

chmod u+x /home/ubuntu/scripts/deploy.sh

To run the script, you would have to login to the server and run:

/home/ubuntu/scripts/deploy.sh

Running it from your machine

Logging into the server every time you need to do deployment can be bit of a pain. Wouldn’t it be great if you could just deploy it from your development machine? The good news is - it’s very much possible!

Given you have setup your machine to access the server without requiring the password, you can edit your ~/.bash_profile to contain an aliased command which can do that. Replace the <your_server_address> (and ubuntu with the username you login to the server as, if it’s something different) in the following command with your server’s actual IP address (or domain/sub-domain name) and run it.

echo "alias ror_deploy=\"ssh ubuntu@<your_server_address> -tt /home/ubuntu/scripts/deploy.sh\"" >> ~/.bash_profile

Once that’s done, you can just push your code to the remote and type ror_deploy on your development machine to SSH to your server and run the script. Once the script is done, the SSH session will end and you will be back at your local machine’s terminal prompt.

Isn’t that neat!?