Affichage des articles dont le libellé est RubyGems. Afficher tous les articles
Affichage des articles dont le libellé est RubyGems. Afficher tous les articles

mardi 24 février 2015

Installing Cloud Foundry v2 locally on Vagrant

Cloud Foundry (CF)

CloundFoundry (CF) is one of the many PaaS available out there that aims to empower developers to build their applications (e.g. web) without caring about infrastructure details. The PaaS handles the deployment, scaling and management of the apps in the cloud data center, thus boosting the developer productivity.
CF has many advantages over other PaaS solutions as it is open source, it has a fast growing community and many big cloud actors are involved in the development and spreading it adoption. It also can be run anywhere even on a laptop and this what this post is about. So keep reading..

Terminology

- Bosh is an open-source platform that helps deploying/managing systems on cloud infrastructures (AWS, OpenStack/CloudStack, vSphere, vCloud, ect).
- Bosh Lite is a lightweight version of Bosh that can be used to deploy systems locally by using Vagrant instead of cloud infrastructure (e.g. AWS) and Linux Containers (Warden project) for to run your system instead of VMs.
- Stemcell is a template VM that will be used by Bosh to create VMs and deploy them to the cloud. I contains essentially an OS (e.g. CentOS) and a Bosh Agent in order to be controlled.

1. Install Git
sudo apt-get install git

2. Install VirtualBox
$ sudo echo "deb http://download.virtualbox.org/virtualbox/debian precise contrib" >> /etc/apt/sources.list
or create a new .list file as described in this thread.
$ wget -q http://download.virtualbox.org/virtualbox/debian/oracle_vbox.asc -O- | sudo apt-key add -
$ sudo apt-get update
$ sudo apt-get install virtualbox-4.3
$ sudo apt-get install dkms
$ VBoxManage --version
4.3.10_Ubuntur93012

3. Install Vagrant (the known version to work with bosh-lite is 1.6.3 - link)
$ wget https://dl.bintray.com/mitchellh/vagrant/vagrant_1.6.3_x86_64.deb
$ sudo dpkg -i vagrant_1.6.3_x86_64.deb
$ vagrant --version
Vagrant 1.6.3

Check if vagrant is correctly working with the installed virtual box
vagrant init hashicorp/precise32
$ vagrant up

4. Install Ruby(using RVM) + RubyGems + Bundler
4.1. Install rvm
curl -sSL https://rvm.io/mpapis.asc | gpg --import -
$ curl -sSL https://get.rvm.io | bash -s stable
$ source /home/{username}/.rvm/scripts/rvm
$ rvm --version

4.2. Install latest ruby version
rvm install 1.9.3-p551
$ ruby -v
ruby 1.9.3p551 (2014-11-13 revision 48407) [x86_64-linux]

5. Install Bosh CLI (check the prerequisites for the target OS here)
- Note that Bosh CLI is not suppored on windows - github issue
$ sudo apt-get install build-essential libxml2-dev libsqlite3-dev libxslt1-dev libpq-dev libmysqlclient-dev
gem install bosh_cli

6. Install Bosh-Lite
git clone https://github.com/cloudfoundry/bosh-lite
$ cd bosh-lite
$ vagrant up --provider=virtualbox

In case the following message is seen The guest machine entered an invalid state while waiting for it to boot, then:
  • check if virtualisation (Intel VT-x / AMD-V for 32bits or Intel EPT / AMD RVI for 64bits) is enabled on target system here. If not then enable it from the BIOS, for ESXi check link1 and link2 and add vhv.enable = "TRUE" to the vm configuration file (i.e. vmx) and make sure the VM is of version 9. 
  • You may also have to check if USB 2.0 controller is enabled, if it is then disable it.
Target the BOSH Director
$ cd ..
$ bosh target 192.168.50.4 lite
$ bosh login
Your username: admin
Enter password: *****

Logged in as `admin'

Setup a route between the laptop and the VMs running inside Bosh Lite
$ cd bosh-lite
$ ./bin/add-route

7. Deploy Cloud Foundry
Install spiff
$ brew tap xoebus/homebrew-cloudfoundry

$ brew install spiff

$ spiff
To install spiff on linux systems check this issue.

Upload latest stemcell
wget http://bosh-jenkins-artifacts.s3.amazonaws.com/bosh-stemcell/warden/latest-bosh-stemcell-warden.tgz
$ bosh upload stemcell latest-bosh-stemcell-warden.tgz
Check the stemcells
$ bosh stemcells

Upload latest CF release
git clone https://github.com/cloudfoundry/cf-release
$ export CF_RELEASE_DIR=$PWD/cf-release/
bosh upload release cf-release/releases/cf-XXX.yml

Deploy CF releases
$ cd bosh-lite/
$ ./bin/provision_cf
$ bosh target check the target director
$ bosh vms    check the installed VMs on the cloud

Manually (to be continued)
Generate a configuration file manifests/cf-manifest.yml
$ mkdir -p go
$ export GOPATH=~/go
$ cd bosh-lite
./bin/make_manifest_spiff

Deploy release
$ bosh deploy

Install CF CLI

Play with CF
$ cf api --skip-ssl-validation https://api.10.244.0.34.xip.io
$ cf login
$ cf create-org ORG_NAME
$ cf orgs
$ cf target -o ORG_NAME
cf create-space SPACE_NAME
$ cf target -o ORG_NAME -s SPACE_NAME

To access the VM from the LAN (i.e. another machine):
  1. Install an HTTP Proxy (e.g. squid3),
  2. Configure CF HTTP_PROXY environment variable, and 
  3. Configure the proxy:
       $ sudo nano /etc/squid3/squid.conf 
       acl local_network src 192.168.2.0/24
       http_access allow local_network

Stopping CF
Shooting down bosh-lite VM can be surprisingly tricky. May better stop the VM with:

  • vagrant suspend to save current state for next start up, or
  • vagrant halt, then next time to start CF use vagrant up followed by bosh cck (documentation).


Troubleshooting
$ bosh ssh then choose the job to access (password: admin)
bosh_something@something:~$ sudo /var/vcap/bosh/bin/monit summary
Find the Bosh Lite IP address
$ cd bosh-lite/
$ vagrant ssh
vagrant@agent-id-bosh-0:~$ ifconfig
vagrant@agent-id-bosh-0:~$ exit

Complete installation script can be found here.

Resources
  • Installing latest versions for virtualbox and vagrant - link
  • Installing ruby with rvm - link.
  • DIY PaaS (CF v1) running DEA link1, stagging applications link2.
  • Deploying CF Playground (a kind of web admin interface) - link
  • Installing CF on vagrant - link video
  • Installing BOSH lite - github repotutorial
  • Deploying CF using BOSH lite - github repo, demo
  • http://altoros.github.io/2013/using-bosh-lite/
  • Installing a new hard drive - link
  • xip.io a free internet service providing DNS wildcard - link
  • Troubleshooting with Bosh CLI - official doc, app healthmonit summary
  • Remotely debug a CF application - link
  • CloudFoundry manifest.yml generator - link


dimanche 3 juin 2012

Configuring Ruby on Rails (RoR)

Here are the steps you need to configure your environment to start building Rails web applications:
      • Installing Git
      • Installing Ruby
      • Installing RubyGems
      • Installing Rails

Here are the steps you need to configure your environment to start building Rails web applications.

Installing Git

Rails ecosystem depends tremendously on Git a very powerful version control system. Git must be installed at first as you will see it every time you google any Rails package.
on a Debian-based distribution like Ubuntu, you have to type following instruction to install Git:

$ apt-get install git-core

You may find detailed installation instructions for your platform at the Installing Git section of the book Pro Git.

Installing Ruby

Next thing to do is to install Ruby, for this you need first to install Ruby Version Manager (RVM). RVM primary goal is helping you to install and manage multiple versions of Ruby on the same machine. Following are the steps for installing RVM on Linux, more details can be found in RVM Installation.

You need curl, if you don't have you can installed on Ubuntu by typing:
$ apt-get install curl
Then download RVM
$ curl -L get.rvm.io | bash -s stable
Load RVM
$ source ~/.rvm/scripts/rvm
Check requirements for installing RVM and follow the instructions:
$ rvm requirements
Finally, now you can install Ruby (1.9.3 is latest version)
$ rvm install 1.9.3

For Windows (using Cygwin) check this tutorial.

rbenv is another ruby sandboxing tool lighter and faster than rvm, you can use both in similar way.

Installing RubyGems

RubyGems is a useful package manager for Ruby projects that may save you a lot of time as there are many useful libraries (including Rails) available as Ruby packages, or gems. RubyGems should be automatically installed if you had successfully installed RVM easy once you install Ruby. You may use following command to check its availability:
$ which gem
/Users/mhartl/.rvm/rubies/ruby-1.9.3-p0/bin/gem

Installing Rails

Finally, we are ready for installing Rails framework and star building great web applications. Rails can installed as follows:

$ gem install rails -v 3.2.3

To check Rails installation, run following command to see version number:
$ rails -v
Rails 3.2.3

If you’re running Linux, you might have to install a couple of other packages at this point:

$ sudo apt-get install libxslt-dev libxml2-dev libsqlite3-dev # Linux only


You want to configure Ruby on Rails on a virtual machine based on Bodhi Linux 1.4.0 Stable which is a light distro based on Ubuntu 10.04 LTS. I may be useful to use configure_image.sh which is  configuration file that will install most of the things described earlier and other useful gems.
These are the instruction for configuring your vm and testing a sample web applications:

  1. Create a new VM with 256 MB RAM and 4GB HD (VirtualBox > New)
  2. Mount bodhi_1.4.0.iso as a live CD (VirtualBox > Settings > Storage)
  3. Install Bodhi Linux (VirtualBox > *your_VM* > Start)
  4. sudo apt-get update, sudo apt-get upgrade
  5. sudo apt-get install git-core (there's no git on Bodhi preinstalled)
  6. mkdir -p Documents (there's no Documents directory/folder by default)
  7. wget -O configure_image.sh http://pastebin.com/download.php?i=WTXF7g7F
  8. chmod +x configure_image.sh
  9. ./configure_image.sh (setups the necessary development environment ~ 2h!)
  10. cd Documents
  11. mkdir -p hw2_rottenpotatoes_2012 (for my fork of the official repo)*
  12. git clone git://github.com/saasbook/hw2_rottenpotatoes.git
  13. cp -r hw2_rottenpotatoes hw2_rottenpotatoes_2012
  14. cd hw2_rottenpotatoes_2012
  15. bundle install --without production
  16. bundle exec rake db:migrate
  17. rails server
  18. http://0.0.0.0:3000/movies 

Resources

You may have to look for other useful resources: