Commit 02adc8228258d122e6d244b3c07c6e4474f034e7
Merge pull request #54 from adamyonk/patch-1
Updates rails docs for consistency
Showing 1 changed file Inline Diff
docs/rails.md
# Using Boxen with Rails Projects | 1 | 1 | # Using Boxen with Rails Projects | |
2 | 2 | |||
Boxen is designed to work extremely well with Rails. | 3 | 3 | Boxen is designed to work extremely well with Rails. | |
Let's break down some of the basics: | 4 | 4 | Let's break down some of the basics: | |
5 | 5 | |||
## Project Management | 6 | 6 | ## Project Management | |
7 | 7 | |||
We make a few assumptions about how you run Rails in development for ease and consistency: | 8 | 8 | We make a few assumptions about how you run Rails in development for ease and consistency: | |
9 | 9 | |||
* You use a web server that listens on a socket | 10 | 10 | * You use a web server that listens on a socket | |
* You use environment variables and something like [dotenv](https://github.com/bkeepers/dotenv) for managing secrets | 11 | 11 | * You use environment variables and something like [dotenv](https://github.com/bkeepers/dotenv) for managing secrets | |
12 | 12 | |||
A typical Rails app that uses things like MySQL, Resque, and phantomjs | 13 | 13 | A typical Rails app that uses things like MySQL, Resque, and phantomjs | |
might have a [project definition](../modules/projects/README.md) like so: | 14 | 14 | might have a [project definition](../modules/projects/README.md) like so: | |
15 | 15 | |||
``` puppet | 16 | 16 | ``` puppet | |
class projects::rails_app { | 17 | 17 | class projects::rails_app { | |
include phantomjs | 18 | 18 | include phantomjs | |
19 | 19 | |||
boxen::project { 'rails_app': | 20 | 20 | boxen::project { 'rails_app': | |
ruby => '1.9.3', | 21 | 21 | ruby => '1.9.3', | |
mysql => true, | 22 | 22 | mysql => true, | |
redis => true, | 23 | 23 | redis => true, | |
nginx => true, | 24 | 24 | nginx => true, | |
source => 'username/rails_app' | 25 | 25 | source => 'username/rails_app' | |
} | 26 | 26 | } | |
} | 27 | 27 | } | |
``` | 28 | 28 | ``` | |
29 | 29 | |||
This does a few things for you: | 30 | 30 | This does a few things for you: | |
31 | 31 | |||
* Clones `https://github.com/mycompany/rails_app.git` to `~/src/rails_app` | 32 | 32 | * Clones `https://github.com/username/rails_app.git` to `~/src/rails_app` | |
* Ensures the default 1.9.3 version of Ruby is installed | 33 | 33 | * Ensures the default 1.9.3 version of Ruby is installed | |
* Creates `~/src/rails_app/.ruby-version` with `1.9.3` in it | 34 | 34 | * Creates `~/src/rails_app/.ruby-version` with `1.9.3` in it | |
* Ensures mysql is installed and running | 35 | 35 | * Ensures mysql is installed and running | |
* Creates two mysql databases: `rails_app_test` and `rails_app_development` | 36 | 36 | * Creates two mysql databases: `rails_app_test` and `rails_app_development` | |
* Ensures redis is installed and running | 37 | 37 | * Ensures redis is installed and running | |
* Ensures nginx is installed and running | 38 | 38 | * Ensures nginx is installed and running | |
* Copies the [template nginx config](../modules/projects/templates/shared/nginx.conf.erb) into the nginx config dir | 39 | 39 | * Copies the [template nginx config](../modules/projects/templates/shared/nginx.conf.erb) into the nginx config dir | |
40 | 40 | |||
It won't necessarily do all of them in that order, but it will guarantee | 41 | 41 | It won't necessarily do all of them in that order, but it will guarantee | |
that if they run successfully they're all done in a correct order. | 42 | 42 | that if they run successfully they're all done in a correct order. | |
43 | 43 | |||
See the section below for some handy configuration tips on how to configure | 44 | 44 | See the section below for some handy configuration tips on how to configure | |
your app best to work with Boxen. | 45 | 45 | your app best to work with Boxen. | |
46 | 46 | |||
## Configuration | 47 | 47 | ## Configuration | |
48 | 48 | |||
### MySQL | 49 | 49 | ### MySQL | |
50 | 50 | |||
``` yaml | 51 | 51 | ``` yaml | |
# config/database.yml | 52 | 52 | # config/database.yml | |
53 | 53 | |||
<% | 54 | 54 | <% | |
def boxen?; ENV['BOXEN_HOME']; end | 55 | 55 | def boxen?; ENV['BOXEN_HOME']; end | |
56 | 56 | |||
socket = [ | 57 | 57 | socket = [ | |
ENV["BOXEN_MYSQL_SOCKET"], | 58 | 58 | ENV["BOXEN_MYSQL_SOCKET"], | |
"/var/run/mysql5/mysqld.sock", | 59 | 59 | "/var/run/mysql5/mysqld.sock", | |
"/tmp/mysql.sock" | 60 | 60 | "/tmp/mysql.sock" | |
].compact.detect { |f| File.exist? f } | 61 | 61 | ].compact.detect { |f| File.exist? f } | |
62 | 62 | |||
port = ENV["BOXEN_MYSQL_PORT"] || "3306" | 63 | 63 | port = ENV["BOXEN_MYSQL_PORT"] || "3306" | |
%> | 64 | 64 | %> | |
65 | 65 | |||
development: | 66 | 66 | development: | |
adapter: mysql2 | 67 | 67 | adapter: mysql2 | |
database: rails_app_development | 68 | 68 | database: rails_app_development | |
username: root | 69 | 69 | username: root | |
password: | 70 | 70 | password: | |
<% if socket %> | 71 | 71 | <% if socket %> | |
host: localhost | 72 | 72 | host: localhost | |
socket: <%= socket %> | 73 | 73 | socket: <%= socket %> | |
<% else %> | 74 | 74 | <% else %> | |
host: 127.0.0.1 | 75 | 75 | host: 127.0.0.1 | |
port: <%= port %> | 76 | 76 | port: <%= port %> | |
<% end %> | 77 | 77 | <% end %> | |
78 | 78 | |||
test: | 79 | 79 | test: | |
adapter: mysql2 | 80 | 80 | adapter: mysql2 | |
database: rails_app_test | 81 | 81 | database: rails_app_test | |
username: root | 82 | 82 | username: root | |
password: | 83 | 83 | password: | |
<% if socket %> | 84 | 84 | <% if socket %> | |
host: localhost | 85 | 85 | host: localhost | |
socket: <%= socket %> | 86 | 86 | socket: <%= socket %> | |
<% else %> | 87 | 87 | <% else %> | |
host: 127.0.0.1 | 88 | 88 | host: 127.0.0.1 | |
port: <%= port %> | 89 | 89 | port: <%= port %> | |
<% end %> | 90 | 90 | <% end %> | |
``` | 91 | 91 | ``` | |
92 | 92 | |||
### PostgreSQL | 93 | 93 | ### PostgreSQL | |
94 | 94 | |||
``` yaml | 95 | 95 | ``` yaml | |
# config/database.yml | 96 | 96 | # config/database.yml | |
97 | 97 | |||
development: | 98 | 98 | development: | |
adapter: postgresql | 99 | 99 | adapter: postgresql | |
database: rails_app_development | 100 | 100 | database: rails_app_development | |
encoding: unicode | 101 | 101 | encoding: unicode | |
port: <%= ENV["BOXEN_POSTGRESQL_PORT"] || 5432 %> | 102 | 102 | port: <%= ENV["BOXEN_POSTGRESQL_PORT"] || 5432 %> | |
host: localhost | 103 | 103 | host: localhost | |
104 | 104 | |||
test: | 105 | 105 | test: | |
adapter: postgresql | 106 | 106 | adapter: postgresql | |
database: rails_app_test | 107 | 107 | database: rails_app_test | |
encoding: unicode | 108 | 108 | encoding: unicode | |
port: <%= ENV["BOXEN_POSTGRESQL_PORT"] || 5432 %> | 109 | 109 | port: <%= ENV["BOXEN_POSTGRESQL_PORT"] || 5432 %> | |
host: localhost | 110 | 110 | host: localhost | |
``` | 111 | 111 | ``` | |
112 | 112 | |||
### Redis | 113 | 113 | ### Redis | |
114 | 114 | |||
``` ruby | 115 | 115 | ``` ruby | |
# config/initializers/redis.rb | 116 | 116 | # config/initializers/redis.rb | |
117 | 117 | |||
$redis = Redis.new(ENV['BOXEN_REDIS_URL'] || 'redis://localhost:6379/') | 118 | 118 | $redis = Redis.new(ENV['BOXEN_REDIS_URL'] || 'redis://localhost:6379/') | |
``` | 119 | 119 | ``` | |
120 | 120 | |||
### Elasticsearch | 121 | 121 | ### Elasticsearch | |
122 | 122 | |||
``` ruby | 123 | 123 | ``` ruby | |
# config/initializers/elasticsearch.rb | 124 | 124 | # config/initializers/elasticsearch.rb | |
125 | 125 | |||
Tire.configure do | 126 | 126 | Tire.configure do | |
url (ENV['BOXEN_ELASTICSEARCH_URL'] || 'http://localhost:9200/') | 127 | 127 | url (ENV['BOXEN_ELASTICSEARCH_URL'] || 'http://localhost:9200/') | |
end | 128 | 128 | end | |
``` | 129 | 129 | ``` | |
130 | 130 | |||
### MongoDB | 131 | 131 | ### MongoDB | |
132 | 132 | |||
``` yaml | 133 | 133 | ``` yaml | |
# config/mongo.yml | 134 | 134 | # config/mongo.yml | |
135 | 135 | |||
development: | 136 | 136 | development: | |
host: 127.0.0.1 | 137 | 137 | host: 127.0.0.1 | |
port: <%= ENV['BOXEN_MONGODB_PORT'] || 27017 %> | 138 | 138 | port: <%= ENV['BOXEN_MONGODB_PORT'] || 27017 %> | |
database: rails_app_development | 139 | 139 | database: rails_app_development | |
140 | 140 | |||
test: | 141 | 141 | test: | |
host: 127.0.0.1 | 142 | 142 | host: 127.0.0.1 |