airavata-courses / TeamCodeRing

0 stars 0 forks source link

Integrating Travis CI to deploy rails application with capistrano #6

Closed Nethracs closed 7 years ago

Nethracs commented 7 years ago

After integrating travis CI to setup the rails application in the travis environment by the help of .travis.yml we faced the problem of deploying to EC2 using capistrano as travis did not have the necessary SSH credentials.

Nethracs commented 7 years ago

Solution steps:

The authentication in EC2 happens with public key of local machine, in order for the travis to connect to EC2 it needs the same public key(local machine's) and the mimic of the private key as well. The method we adopted to do this without compromising the system security is as follows:

  1. We do a " travis encrypt-file deploy_id_rsa --add". where deploy_id_rsa is the private key, this will add a key value pair as ENV to travis.
  2. Then we add this to before install recipe "openssl aes-256-cbc -K $encrypted_2bf021a2570e_key -iv $encrypted_2bf021a2570e_iv -in id_rsa.enc -out config/deploy_id_rsa -d"
  3. We set the SSH options "set :ssh_options, keys: ["config/deploy_id_rsa"] if File.exist?("config/deploy_id_rsa")" in deploy/production.rb file.

Now capistrano will pick this SSH key from travis to connect to EC2. The major problem we faced was there was no standard steps.