Setting up the environment
- Install Ruby Enterprise Edition
- Install and configure web server (nginx or Apache recommended)
- Install Phusion Passenger
- Install MySQL MySQL
After installing the software, run a sanity check for the environment by creating a 'hello world' rails project and corresponding virtual host:
jakeskik@staging:~$ rails new hello
jakeskik@staging:~$ cd hello/public && pwd
/home/jakeskik/hello/public
Example nginx virtual host configuration:
server {
listen 80;
server_name hello.qa.leonidasoy.fi;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
root /home/jakeskik/hello/public;
passenger_enabled on;
rails_env production #or staging, if you want to run in staging env
}
Add the new virtual host to /etc/hosts:
178.79.128.101 hello.qa.leonidasoy.fi
After restarting the web server, you should be able to access the 'hello world' project with a browser, e.g. lynx
jakeskik@staging:~$ lynx hello.qa.leonidasoy.fi
Deploying MeeGo QA Reports
QA Reports uses Capistrano to automate the deployments. The main benefit is to eliminate the risks of human errors and to enable easy and repeatable rollbacks. See Capistrano documentation for the details.
Setting up Capistrano on a new server
- Setup development environment on your workstation as described in Setting up a development environment
- Reserve a (sub)domain name for QA Reports and create a corresponding DNS entry
- Setup ruby, Passenger, MySQL, nginx/Apache and virtual host on production server as described above
- Create MySQL account and database on the production server. Make sure they match with
config/database.yml
- Modify
config/deploy/staging.rb and/or config/deploy/production.rb to match your configuration. Capistrano scripts are executed locally on your workstation and can be tested before checking to version control.
- Setup public key authentication so that you can access the deployment account from your workstation
- Run
cap [staging|production] deploy:setup. The command defaults to staging. Setup command creates the folder hierarchy and the symbolic links required by Capistrano.
- Follow the steps in "Updating QA Reports to a new version"
Once the tool chain and the environment is up and running, the rest is very straight forward.
Updating QA Reports to a new version
-
git pull (In case there's changes in the deployment scripts)
-
cap [staging|production] deploy:migrations
- Ta-da!
Rolling back to previous version
-
cap [staging|production] deploy:rollback
- Ta-da!
Step-by-Step Instructions
These instructions are written based on what I had to do to get QA reports up and running. I had a clean Kubuntu 10.04 installation to start with, and as this was for demonstration purposes the same computer was acting as Production Environment and Development Environment, but under different user accounts.
Setting Up the Production Environment
- Install some packages: $ sudo aptitude install curl build-essential git-core mysql-server openssh-server zlib1g-dev libssl-dev libreadline5-dev libcurl4-openssl-dev
- Create a MySQL database user and the database:
- mysql -u root -p
- create user 'meego-qa'@'localhost' identified by 'somepasswordofyourchoosing';
- create database qa_reports_production character set 'utf8';
- grant all privileges on qa_reports_production.* to 'meego-qa'@'localhost';
- flush privileges;
- quit;
- Install RVM: $ bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )
- Set up .bashrc as instructed by RVM installer: The whole content into an if section, and after that loading of RVM.
- Run: $ source ~/.bashrc
- Install Ruby Enterprise Edition: $ rvm install ree
- Use it as default: $ rvm --default use ree
- Install bundler: $ gem install bundler
- Install passenger: $ gem install passenger
- Install nginx: $ passenger-install-nginx-module
- Notice: the default location is under /opt. If you wish to install there, use rvmsudo. Notice however, that part of your ~/.rvm contents will then belong to root and may cause gray hair later. I chose to install under ~/nginx.
- At this point, jump to Development Environment section, set it up and deploy QA Reports
- Once deployed correctly, edit nginx configuration installation_path/conf/nginx.conf:
- Comment out section location / { ... }
- Add lines:
- passenger_enabled on;
- root /home/your_prod_env_user/qa-reports.meego.com/current/public;
- Create file /home/your_prod_env_user/qa-reports.meego.com/shared/config/registeration_token and add some string in it. This will be part of the registration url, e.g. foobar will make registration to be at url /users/foobar/register
- Start nginx: $ sudo /installation_path/sbin/nginx
- Head to the server address with your web browser and hopefully see QA Reports running
Setting Up the Development Environment
- Set up public key authentication:
- Generate yourself as SSH key pair if you don't have one: $ ssh-keygen
- Add your public key to authorized_keys file of your production environment user:
$ ssh your.production.user@your.production.host 'mkdir .ssh; echo '`cat ~/.ssh/id_rsa.pub`' >> ~/.ssh/authorized_keys'
- Try logging in: ssh your.production.user@your.production.host
- Set up development environment as described here
- Notice: Just run $ bundle install without flags and stop there, no need to set up database or anything
- Edit your settings based on your production environment setup:
- config/deploy/production.rb: set the correct user and host information (mysql, ssh, host)
- config/deploy/database.yml.erb: set up MySQL user and database information
- Deploy:
- $ cap production deploy:setup
- $ cap production deploy:migrations
- Run again - there's something fishy in the DB setup: $ cap production deploy:migrations
- Now head back to Production Environment to finalize the setup