(→Deploying MeeGo QA Reports) |
(Step by step instructions added) |
||
| Line 67: | Line 67: | ||
# <code>cap [staging|production] deploy:rollback</code> | # <code>cap [staging|production] deploy:rollback</code> | ||
# Ta-da! | # 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: <tt>$ sudo aptitude install curl build-essential git-core mysql-server openssh-server zlib1g-dev libssl-dev libreadline5-dev libcurl4-openssl-dev</tt> | ||
| + | # Create a MySQL database user and the database: | ||
| + | ## <tt>mysql -u root -p</tt> | ||
| + | ## <tt>create user 'meego-qa'@'localhost' identified by 'somepasswordofyourchoosing';</tt> | ||
| + | ## <tt>create database qa_reports_production character set 'utf8';</tt> | ||
| + | ## <tt>grant all privileges on qa_reports_production.* to 'meego-qa'@'localhost';</tt> | ||
| + | ## <tt>flush privileges;</tt> | ||
| + | ## <tt>quit;</tt> | ||
| + | # Install RVM: <tt>$ bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )</tt> | ||
| + | ## Set up <tt>.bashrc</tt> as instructed by RVM installer: The whole content into an if section, and after that loading of RVM. | ||
| + | ## Run: <tt>$ source ~/.bashrc</tt> | ||
| + | # Install Ruby Enterprise Edition: <tt>$ rvm install ree</tt> | ||
| + | # Use it as default: <tt>$ rvm --default use ree</tt> | ||
| + | # Install bundler: <tt>$ gem install bundler</tt> | ||
| + | # Install passenger: <tt>$ gem install passenger</tt> | ||
| + | # Install nginx: <tt>$ passenger-install-nginx-module</tt> | ||
| + | ## Notice: the default location is under <tt>/opt</tt>. If you wish to install there, use <tt>rvmsudo</tt>. Notice however, that part of your <tt>~/.rvm</tt> contents will then belong to root and may cause gray hair later. I chose to install under <tt>~/nginx</tt>. | ||
| + | # At this point, jump to [[#Setting Up the Development Environment|Development Environment section]], set it up and deploy QA Reports | ||
| + | # <span id="continuepoint">Once</span> deployed correctly, edit nginx configuration <tt>installation_path/conf/nginx.conf</tt>: | ||
| + | ## Comment out section <tt>location / { ... }</tt> | ||
| + | ## Add lines: | ||
| + | ### <tt>passenger_enabled on;</tt> | ||
| + | ### <tt>root /home/your_prod_env_user/qa-reports.meego.com/current/public;</tt> | ||
| + | # Create file <tt>/home/your_prod_env_user/qa-reports.meego.com/shared/config/registeration_token</tt> and add some string in it. This will be part of the registration url, e.g. <tt>foobar</tt> will make registration to be at url <tt>/users/foobar/register</tt> | ||
| + | # Start nginx: <tt>$ sudo /installation_path/sbin/nginx</tt> | ||
| + | # 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: <tt>$ ssh-keygen</tt> | ||
| + | ## Add your public key to <tt>authorized_keys</tt> file of your production environment user: <br> <tt>$ ssh your.production.user@your.production.host 'mkdir .ssh; echo '`cat ~/.ssh/id_rsa.pub`' >> ~/.ssh/authorized_keys'</tt> | ||
| + | ## Try logging in: <tt>ssh your.production.user@your.production.host</tt> | ||
| + | # Set up development environment as described [[Quality/QA-tools/QAReports/Setting up the development environment|here]] | ||
| + | ## Notice: Just run <tt>$ bundle install</tt> without flags and stop there, no need to set up database or anything | ||
| + | # Edit your settings based on your production environment setup: | ||
| + | ## <tt>config/deploy/production.rb</tt>: set the correct user and host information (mysql, ssh, host) | ||
| + | ## <tt>config/deploy/database.yml.erb</tt>: set up MySQL user and database information | ||
| + | # Deploy: | ||
| + | ## <tt>$ cap production deploy:setup</tt> | ||
| + | ## <tt>$ cap production deploy:migrations</tt> | ||
| + | ## Run again - there's something fishy in the DB setup: <tt>$ cap production deploy:migrations</tt> | ||
| + | # Now head back to [[#continuepoint|Production Environment]] to finalize the setup | ||
Contents |
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
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.
config/database.yml
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.
cap [staging|production] deploy:setup. The command defaults to staging. Setup command creates the folder hierarchy and the symbolic links required by Capistrano.
Once the tool chain and the environment is up and running, the rest is very straight forward.
git pull (In case there's changes in the deployment scripts)
cap [staging|production] deploy:migrations
cap [staging|production] deploy:rollback
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.