2012 Rails Rumble - Full Stack, Deploy Ready - Official

by rumble
477 deployments · 268 still active · last rev. 3 years ago

Rails Rumble 2012 - "Full Stack, Deployment Ready" - StackScript

This StackScript will install Ruby 1.9.3, RubyGems 1.8.24, MySQL, Apache, Passenger, Git, and Memcached. It will also configure SSH deploy keys (that should be added to your GitHub repository's deploy keys area), a deployment location, and a database.yml, for your Rails app.

Important: This StackScript is meant to be used in conjunction with a specific Capistrano deployment recipe, which you can see at: https://gist.github.com/3849380

After booting your server for the first time when using this StackScript as its configuration, you should SSH in as root and `tail -f ~/log.txt` to see the progress of the installation. It will take about 10 minutes to complete and will end with a note saying: "StackScript Finished".

Compatible with: No distros currently supported

source <ssinclude StackScriptID="1">

# <UDF name="db_password" Label="MySQL root Password" />
# <UDF name="db_name" Label="Create Database" default="railsrumble_production" example="Production Database Name" />



export logfile

echo "StackScript Starting" >> $logfile
echo "********************" >> $logfile

echo "System Updated" >> $logfile
echo "" >> $logfile

echo "Configured: postfix_install_loopback_only" >> $logfile
echo "" >> $logfile

mysql_install "$DB_PASSWORD" && mysql_tune 40
echo "Installed: MySQL" >> $logfile
echo "" >> $logfile

mysql_create_database "$DB_PASSWORD" "$DB_NAME"
echo "Configured: MySQL" >> $logfile
echo "" >> $logfile

apache_install && apache_tune 40 && apache_virtualhost_from_rdns && a2enmod rewrite
echo "Installed: apache" >> $logfile
echo "" >> $logfile

echo "Installed: goodstuff" >> $logfile
echo "" >> $logfile

apt-get -y install build-essential
apt-get -y install libssl-dev
apt-get -y install libreadline5-dev
apt-get -y install zlib1g-dev
apt-get -y install libyaml-dev
apt-get -y install libxslt-dev
apt-get -y install git
apt-get -y install git-core
apt-get -y install memcached
apt-get -y install libcurl4-openssl-dev
apt-get -y install apache2-prefork-dev
apt-get -y install libapr1-dev
apt-get -y install libaprutil1-dev
apt-get -y install libreadline-dev
echo "Installed: various libraries" >> $logfile
echo "" >> $logfile

# Install Ruby
echo "Installing: Ruby"
echo "$RUBY_VERSION.tar.gz" >> $logfile
echo "$RUBY_VERSION" >> $logfile

echo "" >> $logfile
echo "Downloading: (from calling wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/$RUBY_VERSION.tar.gz)" >> $logfile
echo "" >> $logfile
wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/$RUBY_VERSION.tar.gz  >> $logfile

echo "" >> $logfile
echo "tar output:" >> $logfile
tar xzf $RUBY_VERSION.tar.gz >> $logfile
rm $RUBY_VERSION.tar.gz

echo "" >> $logfile
echo "Current Directory:" >> $logfile
pwd >> $logfile

echo "" >> $logfile
echo "Ruby configure output: (from calling ./configure --disable-ucontext --enable-pthread)" >> $logfile
echo "" >> $logfile
./configure --disable-ucontext --enable-pthread >> $logfile

echo "" >> $logfile
echo "Ruby make output: (from calling make)" >> $logfile
echo "" >> $logfile
make >> $logfile

echo "" >> $logfile
echo "Ruby make install output: (from calling make install)" >> $logfile
echo "" >> $logfile
make install >> $logfile

echo "" >> $logfile
echo "Downloading Ruby Gems with wget http://production.cf.rubygems.org/rubygems/rubygems-$RUBYGEMS_VERSION.tgz" >> $logfile
echo "" >> $logfile
wget http://production.cf.rubygems.org/rubygems/rubygems-$RUBYGEMS_VERSION.tgz >> $logfile

echo "" >> $logfile
echo "tar output:" >> $logfile
tar xzvf rubygems-$RUBYGEMS_VERSION.tgz  >> $logfile
rm rubygems-$RUBYGEMS_VERSION.tgz

echo "" >> $logfile
echo "Installing: RubyGems" >> $logfile
ruby setup.rb >> $logfile
rm -rf rubygems-$RUBYGEMS_VERSION

echo "" >> $logfile
echo "gem update --system:" >> $logfile
gem update --system >> $logfile

gem install rails --version 3.2.8 --no-ri --no-rdoc >> $logfile
gem install passenger --version 3.0.17 --no-ri --no-rdoc >> $logfile
echo "Installed: rails, passenger gems" >> $logfile

echo "" >> $logfile
echo "Installing: passenger" >> $logfile
passenger-install-apache2-module --auto

wget http://railsrumble.com.s3.amazonaws.com/2012/linode/apache2.conf >> $logfile
wget http://railsrumble.com.s3.amazonaws.com/2012/linode/passenger.conf >> $logfile

mv apache2.conf /etc/apache2/apache2.conf
mv passenger.conf /etc/apache2/passenger.conf

echo "" >> $logfile
echo "Configured: apache, passenger" >> $logfile

echo "" >> $logfile
echo "Deployment Setup:" >> $logfile

mkdir -p /var/www/apps/railsrumble/releases
mkdir -p /var/www/apps/railsrumble/shared/config
mkdir -p /var/www/apps/railsrumble/shared/log
chown www-data:www-data -R /var/www/apps
echo "Setup: Deployment Directory" >> $logfile

touch /var/www/apps/railsrumble/shared/config/database.yml
echo "production:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: $DB_NAME
  pool: 5
  username: root
  password: $DB_PASSWORD
  host: localhost
  socket: /var/run/mysqld/mysqld.sock" >> /var/www/apps/railsrumble/shared/config/database.yml
echo "Configured: database.yml" >> $logfile

ssh -T -oStrictHostKeyChecking=no git@github.com
echo "Configured: github.com as known host" >> $logfile

mkdir -p ~/.ssh

ssh-keygen -N '' -f ~/.ssh/github-deploy-key -t rsa -q
echo "Generated: SSH key for deployment (you need to add ~/.ssh/github-deploy-key.pub to your GitHub repository's deploy keys)" >> $logfile

touch ~/.ssh/config

echo "Host github.com
  IdentityFile ~/.ssh/github-deploy-key" >> ~/.ssh/config

echo "Configured: ~/.ssh/config (this ensures the above deploy key is used for github.com)" >> $logfile

touch ~/.ssh/authorized_keys

curl http://railsrumble.com.s3.amazonaws.com/rumblebot.pub >> ~/.ssh/authorized_keys

chmod 0700 ~/.ssh/
chmod 0644 ~/.ssh/authorized_keys

echo "Configured: ~/.ssh/authorized_keys (do not remove the key for organizers@railsrumble.com, this is necessary for verification)" >> $logfile

echo "********************" >> $logfile
echo "StackScript Finished" >> $logfile