Created
November 30, 2011 12:22
-
-
Save bububa/1408886 to your computer and use it in GitHub Desktop.
Setup Rails 3.1 for Cloud Foundary on Mac OsX Lion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. edit ~/.bash_profile | |
:: | |
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function | |
export PYTHONPATH=/usr/local/lib/python:$PYTHONPATH | |
export PATH=$PATH:/Users/syd/.rvm/gems/ruby-1.9.2-p290/bin/ | |
export GEM_PATH=$GEM_PATH:/Users/syd/.rvm/gems/ruby-1.9.2-p290/ | |
alias mysql="/usr/local/mysql/bin/mysql" | |
alias mysqld="sudo /Library/StartupItems/MySQLCOM/MySQLCOM" | |
export DYLD_LIBRARY_PATH="/usr/local/mysql/lib:$DYLD_LIBRARY_PATH" | |
2. sudo gem install vmc | |
3. vmc target api.cloudfoundary.com | |
4. vmc login | |
5. install gem mysql2 | |
:: | |
sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-dir=/usr/local/mysql --with-mysql-lib=/usr/local/mysql/lib --with-mysql-include=/usr/local/mysql/include --with-mysql-config=/usr/local/mysql/bin/mysql_config | |
sudo env ARCHFLAGS="-arch x86_64" gem install mysql2 -- --with-mysql-dir=/usr/local/mysql --with-mysql-lib=/usr/local/mysql/lib --with-mysql-include=/usr/local/mysql/include --with-mysql-config=/usr/local/mysql/bin/mysql_config | |
6. sudo gem install bson_ext | |
7. rails new app | |
8. edit Gemfile | |
:: | |
source 'http://rubygems.org' | |
gem 'rails', '3.1.1' | |
# Bundle edge Rails instead: | |
# gem 'rails', :git => 'git://github.com/rails/rails.git' | |
gem 'sqlite3' | |
gem 'mongoid', '~> 2.0.2' | |
gem 'mysql2', '~> 0.3.10' | |
# Gems used only for assets and not required | |
# in production environments by default. | |
group :assets do | |
gem 'sass-rails', '~> 3.1.4' | |
gem 'coffee-rails', '~> 3.1.1' | |
gem 'uglifier', '>= 1.0.3' | |
end | |
gem 'jquery-rails' | |
# To use ActiveModel has_secure_password | |
# gem 'bcrypt-ruby', '~> 3.0.0' | |
# Use unicorn as the web server | |
# gem 'unicorn' | |
# Deploy with Capistrano | |
# gem 'capistrano' | |
# To use debugger | |
# gem 'ruby-debug19', :require => 'ruby-debug' | |
group :test do | |
# Pretty printed test output | |
gem 'turn', :require => false | |
end | |
group :production do | |
gem 'therubyracer' | |
end | |
9. bundle package; bundle install | |
10. add config/initializers/mongoid.rb | |
:: | |
require 'json' # explicitly requires json | |
# initialize the environment for CloudFoundry | |
# you will have to remove the mongoid.yml file otherwise Mongoid | |
# will read that file and try to connect, and will error out. | |
if ENV['VCAP_SERVICES'] | |
# get the config from VCAP | |
# http://support.cloudfoundry.com/entries/20018322-alert-mongo-bindings-have-changed | |
def mongo_connection_info | |
services = JSON.parse(ENV['VCAP_SERVICES']) | |
services.each do |service_version, bindings| | |
bindings.each do |binding| | |
if binding['label'] =~ /mongo/i | |
res = binding['credentials'] | |
return res | |
end | |
end | |
end | |
raise "could not find connection info" | |
end | |
conn_info = mongo_connection_info | |
# configure Mongoid to connect to the db using VCAP connection info | |
Mongoid.configure do |config| | |
name = conn_info['db'] || 'app' | |
host = conn_info['hostname'] | |
options = { | |
"database" => conn_info['db'] || 'app', | |
"host" => conn_info['hostname'], | |
"port" => conn_info['port'].to_i, | |
"autocreate_indexes" => false, | |
"allow_dynamic_fields" => true, | |
"include_root_in_json" => false, | |
"parameterize_keys" => true, | |
"persist_in_safe_mode" => false, | |
"raise_not_found_error" => true, | |
"reconnect_time" => 3 | |
} | |
if conn_info['username'] and conn_info['password'] | |
options['username'] = conn_info['username'] | |
options['password'] = conn_info['password'] | |
end | |
config.from_hash(options) | |
end | |
end | |
11. edit config/environments/product.rb | |
:: | |
change 'config.serve_static_assets = false' to 'config.serve_static_assets = true' | |
12. RAILS_ENV=production rake assets:precompile | |
13. vmc push app --runtime ruby19 | |
:: | |
Would you like to deploy from the current directory? [Yn]: y | |
Application Deployed URL: 'xibao.cloudfoundry.com'? y | |
Detected a Rails Application, is this correct? [Yn]: y | |
Memory Reservation [Default:256M] (64M, 128M, 256M, 512M, 1G or 2G) | |
Creating Application: OK | |
Would you like to bind any services to 'xibao'? [yN]: y | |
The following system services are available: | |
1. mongodb | |
2. mysql | |
3. postgresql | |
4. rabbitmq | |
5. redis | |
Please select one you wish to provision: 2 | |
Specify the name of the service [mysql-e8939]: | |
Creating Service: OK | |
Binding Service: OK | |
Uploading Application: | |
Checking for available resources: OK | |
Processing resources: OK | |
Packing application: OK | |
Uploading (194K): OK | |
Push Status: OK | |
Staging Application: OK | |
Starting Application: .. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment