<img src=“https://codeclimate.com/github/DiUS/TEDxStartSomething/badges/gpa.svg” /> <img src=“https://codeclimate.com/github/DiUS/TEDxStartSomething/badges/coverage.svg” />
¶ ↑
TEDxStartSomething Care and Feeding Instructions¶ ↑
Setting up Continuous Integration (CI)¶ ↑
Hardware (AWS EC2)-
Create a security group with http, https, ssh, and custom TCP on port 8080.
-
Create an Ubuntu AMI with hardware capacity of t2.medium.
-
Attach the created security group to the Ubuntu AMI.
-
Attach an elastic IP’s to the EC2 instance.
¶ ↑
Setup CI¶ ↑
Install Dependencies-
sudo apt-get install openjdk-7-jdk
-
sudo apt-get install git
-
wget -q -O - jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add -
-
sudo sh -c ‘echo deb pkg.jenkins-ci.org/debian binary/ > /etc/apt/sources.list.d/jenkins.list’
-
sudo apt-get update
-
sudo apt-get install jenkins
-
sudo apt-get install phantomjs
¶ ↑
Install Jenkins-
Install MySQL: sudo apt-get install mysql-server mysql-client libmysqlclient-dev.
-
Install libxml2: sudo apt-get install libxslt-dev libxml2-dev.
-
Install Qt WebKit: sudo apt-get install libqtwebkit-dev.
¶ ↑
Configure Jenkins-
Install Jenkins plugins
* github (also installs git, which is what is really wanted) * green balls * build pipeline
-
Change time zone.
¶ ↑
Configure Build¶ ↑
Tests Job-
Create a Tests Jenkins job.
-
In Source Code Management, Repository URL enter: github.com/DiUS/TEDxStartSomething.git.
-
Poll SCM: */3 * * * *, rather than use Github hooks, which is also good.
-
In Build, Execute Shell:
#!/bin/bash -xl \curl -sSL get.rvm.io | bash -s stable -ruby=1.9.3 source /var/lib/jenkins/.rvm/scripts/rvm source /var/lib/jenkins/.rvm/scripts/rvm rvm use gemset actionman bundle install export DB_USERNAME=actionman export DB_PASSWORD=<db_password> RAILS_ENV=test bundle exec rake db:migrate RAILS_ENV=test bundle exec rake
-
In Post-build Actions, Downstream Project Names enter: QA_Deploy.
¶ ↑
QA_Deploy Job-
Create a QA_Deploy Jenkins job.
-
In Source Code Management, Repository URL enter: github.com/DiUS/TEDxStartSomething.git.
-
In Build, Execute Shell:
#!/bin/bash -xl \curl -sSL get.rvm.io | bash -s stable –ruby=1.9.3 source /var/lib/jenkins/.rvm/scripts/rvm source /var/lib/jenkins/.rvm/scripts/rvm rvm use gemset actionman bundle install bundle exec cap qa deploy
-
In Post-build Actions, Downstream Project Names enter: Production_Deploy.
¶ ↑
Production_Deploy Job-
Create a Production_Deploy Jenkins job.
-
In Source Code Management, Repository URL enter: github.com/DiUS/TEDxStartSomething.git.
-
In Build, Execute Shell:
#!/bin/bash -xl \curl -sSL get.rvm.io | bash -s stable –ruby=1.9.3 source /var/lib/jenkins/.rvm/scripts/rvm source /var/lib/jenkins/.rvm/scripts/rvm rvm use gemset actionman bundle install bundle exec cap production deploy
¶ ↑
Set up Elastic IP-
Allocate a new address.
-
Attach the new address to the CI EC2 instance.
Jenkins is currently accessible via 54.206.91.221:8080/.
¶ ↑
Setting Up Production/Staging Servers¶ ↑
Database Server (AWS RDS)-
Create a security group with http, https, ssh, and custom TCP on port 8080, or re-use security group already created for CI and allocate that to the RDS instance.
-
Create a small RDS instance with 20GB.
¶ ↑
Production/Staging Application Servers (AWS EC2)¶ ↑
Hardware (AWS EC2)-
Create a security group or groups with http, https, ssh, and custom TCP on port 8080, or re-use security group already created for CI and allocate that to the RDS instance.
-
Create two Ubuntu AMI’s with hardware capacity of t2.small.
-
Attach the created security group or groups to the Ubuntu AMI.
-
Attach elastic IP’s to each of the EC2 instances.
¶ ↑
Install Dependencies-
Install ansible
See, http://docs.ansible.com/intro_installation.html: * git clone git://github.com/ansible/ansible.git * cd ./ansible * source ./hacking/env-setup * sudo easy_install pip * sudo pip install paramiko PyYAML jinja2 httplib2
-
ansible-playbook -i inventory/hosts.ini rails_app_server.yml –extra-vars “rds_defalt_password=<RDS_root_password> db_password=<RDS_user_password>”
¶ ↑
Set up Elastic IP’s-
Allocate two new addresses.
-
Attach the new addresses, one each to the staging and production EC2 instances.
¶ ↑
Semi-automating Deployments-
Generate ssh keys on CI server.
-
Copy ssh keys to staging and production servers.
¶ ↑
Deployment-
Click “Run” to start a new pipeline.
-
Deployment to production occurs when the second box is green and the “Run” icon is clicked, (hopefully) causing the third and last box to go green. At this point deployment should be complete.
¶ ↑
EC2 Blackouts-
Install ruby with development headers (the ruby version in apt repository will do the job):
sudo apt-get install ruby sudo aptitude install ruby1.9.1-dev
-
On the production EC2 instance, install ec2-blackout gem:
sudo gem install ec2-blackout
-
Follow ec2-blackout instructions to configure the gem
-
Tag prdoduction instance with “no blackout”
-
Add the following to crontab (assuming system is running in UTC):
0 9 * * * AWS_ACCESS_KEY_ID=<access key> AWS_SECRET_ACCESS_KEY=<secret key> /usr/local/bin/ec2-blackout on --exclude-by-tag no_blackout 0 21 * * * AWS_ACCESS_KEY_ID=<access key> AWS_SECRET_ACCESS_KEY=<secret key> /usr/local/bin/ec2-blackout off
¶ ↑
Setting Up Local Development Environment-
git clone git@github.com:DiUS/TEDxStartSomething.
-
bundle install.
-
rake db:create.
-
rake db:setup.
¶ ↑
Deploy from local machine$ DEPLOY_KEY=<path_to_deployer_pem> AWS_ACCESS_KEY_ID=<key> AWS_SECRET_ACCESS_KEY=<secret> bin/cap canary deploy
¶ ↑
Elasticsearch¶ ↑
Installwget download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-0.20.5.tar.gz tar -xvzf elasticsearch-0.20.5.tar.gz
IMPORTANT: edit elasticsearch-0.20.5/config/elasticsearch.yml to change the cluster.name to a unique name! (otherwise it’ll form a cluster between the development machines)
¶ ↑
Runcd elasticsearch-0.20.5 bin/elasticsearch -f
¶ ↑
Re-seeding dataTo re-seed and re-index:
rake db:seed search:import
Just re-indexing:
rake search:import
NOTE: you may see “Too amny open files” in the elasticsearch logs. This causes indexing to fail sometimes.
Solution for this problem can be found here:
www.elasticsearch.org/tutorials/2011/04/06/too-many-open-files.html
¶ ↑
Performance testing with httperf¶ ↑
SetupNote: To reduce latency deviation I would installing the httperf and running the test from the EC2 instance (i.e. QA),
but not from the production machine itself as the test take a lot of resources.
Clone the httperf that supports big sessions:
git clone git://github.com/Gregg/httperf_big_cookies.git
Build and install httperf:
sudo mv httperf_big_cookies /usr/local/lib cd /usr/local/lib/httperf_big_cookies ./configure make sudo make install
Verify that httperf has installed correctly:
httpferf -h
¶ ↑
Running the testPrepare the path_sequence.txt. The file basically describes the sequence for requests
httperf –wsesslog=40,2,path_sequence.txt –rate=1 –timeout=5 –session-cookie –server=54.79.75.3 –port=80
¶ ↑
ExplanationThe above command will be means the following:
40 session, each starts withing 1 second of each other firing events in path_sequence.txt every two seconds.
¶ ↑
Important MetricsRequest rate: 13.3 req/s (75.4 ms/req) Reply rate [replies/s]: min 1.4 avg 13.6 max 16.8 stddev 4.3 (41 samples)
Thie basically means that fore every 13.3 req on everage 13.6 req came back per second (the second number is bigger in this case due to rump up). Watch the standard deviation stays relatively low.
Reply time [ms]: response 297.6 transfer 173.5 Make sure this stays with acceptable rate (< 500ms??)
It is also good to personally play with the app while the test is executing.