Deploy to EC2 Via RightScale Using GIT_SSH

While RightScale’s built-in scripts make it simple to deploy code to an EC2 instance, they often need some tweaking to work correctly (i.e. the current version of app::do_update_code simply pulls down code, it doesn’t restart Apache or recompress assets).

The following is an example RightScript that utilizes a temporary SSH key, GIT_SSH and a sync script to automate the deployment process.

#!/bin/bash -e
# switch to the attachment directory
# move the sync script
mv /home/rightscale/.ssh/
# make script executable
chmod u+x /home/rightscale/.ssh/
# create temporary SSH key
cat > "/home/rightscale/.ssh/id_rsa" << EOF
# chmod to 600
chmod 600 /home/rightscale/.ssh/id_rsa
# set GIT_SSH
export GIT_SSH=/home/rightscale/.ssh/
# clone the repo
git clone –depth 1 /home/rightscale/$APPLICATION
# recompress assets
python /home/webapps/$APPLICATION/ collectstatic –noinput -i css -i js
python /home/webapps/$APPLICATION/ compress
# stop apache
service apache2 stop
# remove the current app directory
rm -rf /home/webapps/$APPLICATION
# move the new app directory into place
mv /home/rightscale/$APPLICATION /home/webapps/$APPLICATION
# restart apache
service apache2 start
# remove temporary SSH key
rm /home/rightscale/.ssh/id_rsa
rm /home/rightscale/.ssh/

view raw

hosted with ❤ by GitHub (attached to above RightScript)

#!/bin/bash -e
/usr/bin/env ssh -q -2 -o "StrictHostKeyChecking=no" -i "/home/rightscale/.ssh/id_rsa" $1 $2

view raw

hosted with ❤ by GitHub

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s