3
Rack applications subordinate [Juju Charm](http://jujucharms.com/). Works only when related to appropriate web-server.
7
You can use any of available web servers, which provides rack container. Currently available:
9
- [apache2-passenger](http://jujucharms.com/charms/precise/apache2-passenger)
10
- [nginx-passenger](http://jujucharms.com/charms/precise/nginx-passenger)
12
All examples will use **apache2-passenger**, but you can choose any.
18
juju deploy apache2-passenger
20
2. Deploy Rack application (see configuration section below)
22
juju deploy rack --config myapp.yml
26
juju add-relation rack apache2-passenger
28
4. Deploy and relate database
31
juju add-relation mysql rack
33
5. Open the stack up to the outside world.
35
juju expose apache2-passenger
37
6. Find the apache2-passenger instance's public URL from
3
Rack provides a minimal, modular and adaptable interface for developing web applications in Ruby. This Charm will deploy Ruby on Rails, Sinatra or any other Rack application and connect it to supported services.
7
To deploy this charm you will need at a minimum: a cloud environment, working Juju installation and a successful bootstrap. Once bootstrapped, deploy Rack charm and all required services.
9
## Ruby on Rails example
11
Configure your application, for example:
16
repo: https://github.com/pavelpachkovskij/sample-rails
18
Deploy Rack application:
20
juju deploy rack sample-rails --config sample-rails.yml
22
Deploy and relate database
45
24
juju deploy postgresql
46
juju add-relation postgresql:db rack
50
If you use Mongodb with Mongoid then on a step 4 you should run
25
juju add-relation postgresql:db sample-rails
27
Now you can run migrations:
29
juju ssh sample-rails/0 run rake db:migrate
33
juju ssh sample-rails/0 run rake db:seed
35
And finally expose the Rack service:
39
Find the Rack instance's public URL from
46
juju add-relation mysql rack
50
Configure your application, for example html2haml
55
repo: https://github.com/twilson63/html2haml.git
57
Deploy your Rack service
59
juju deploy rack html2haml --config html2haml.yml
65
## Source code updates
67
juju set <service_name> revision=<revision>
71
juju ssh <unit_name> run <command>
73
## Restart application
75
juju ssh <unit_name> sudo restart rack
77
## Foreman integration
79
You can add Procfile to your application and Rack to start additional processes or replace default application server:
83
web: bundle exec unicorn -p $PORT
84
watcher: bundle exec rake watch
86
## Specifying a Ruby Version
88
You can use the ruby keyword of your app's Gemfile to specify a particular version of Ruby.
90
source "https://rubygems.org"
95
Juju makes it easy to scale your Rack application. You can simply deploy any supported load balancer, add relation and launch any number of application instances.
99
juju deploy rack rack --config rack.yml
101
juju add-relation haproxy rack
103
juju add-unit rack -n 2
107
Apache2 is harder to start with, but it provides more flexibility with configuration options.
108
Here is a quick example of using Apache2 as a load balancer with your rack application:
110
Deploy Rack application
112
juju deploy rack --config rack.yml
114
You have to enable mod_proxy_balancer and mod_proxy_http modules in your Apache2 config:
116
**apache2.yml** example
119
enable_modules: proxy_balancer proxy_http
123
juju deploy apache2 --config apache2.yml
125
Create balancer relation between Apache2 and Rack application
127
juju add-relation apache2:balancer rack
129
Apache2 charm expects a template to be passed in. Example of vhost that will balance all traffic over your application instances:
135
ProxyPass / balancer://rack/ lbmethod=byrequests stickysession=BALANCEID
136
ProxyPassReverse / balancer://rack/
139
Update Apache2 service config with this template
141
juju set apache2 "vhost_http_template=$(base64 < vhost.tmpl)"
143
Expose Apache2 service
147
# Logging with Logstash
149
You can add logstash service to collect information from application's logs and Kibana application to visualize this data.
152
juju deploy logstash-indexer
153
juju add-relation kibana logstash-indexer:rest
155
juju deploy logstash-agent
156
juju add-relation logstash-agent logstash-indexer
157
juju add-relation logstash-agent rack
158
juju set logstash-agent CustomLogFile="['/var/www/rack/current/log/*.log']" CustomLogType="rack"
161
# Monitoring with Nagios and NRPE
163
You can can perform HTTP checks with Nagios. To do this deploy Nagios and relate it to your Rack application:
166
juju add-relation rack nagios
168
Additionally you can perform disk, mem, and swap checks with NRPE extension:
171
juju add-relation rack nrpe
172
juju add-relation nrpe nagios
176
Deploy MonogDB service and relate it to Rack application:
52
178
juju deploy mongodb
53
179
juju add-relation mongodb rack
63
juju deploy apache2-passenger
65
2. Configure your application, for example html2haml
70
repo_url: https://github.com/twilson63/html2haml.git
73
3. Deploy your application with Rack Charm
75
juju deploy rack html2haml --config html2haml.yml
77
4. Relate it to web-server
79
juju add-relation html2haml apache2-passenger
81
5. Open the stack up to the outside world.
83
juju expose apache2-passenger
87
Here is an example configuration for Rails 3 installation from svn trunk. Additionally it will install imagemagick package.
91
repo_url: https://github.com/pavelpachkovskij/sample-rails
93
app_name: sample-rails
94
install_root: /var/www
95
extra_packages: imagemagick
97
migrate_database: true
101
If you don't have or don't need to migrate database, seed database or compile assets, disable them in your config. They are enabled by default.
105
- installs all dependencies and extra packages
106
- install node.js from ppa:chris-lea/node.js
107
- fetch an application from configured repository
181
Rack charm will set environment variables which you can use to configure your Mongodb adapter.
183
MONGODB_URL => mongodb://host:port/database
187
Your mongoid.yml should look like:
190
uri: <%= ENV['MONGODB_URL'] %>
194
Your mongoid.yml should look like:
199
uri: <%= ENV['MONGODB_URL'] %>
201
In both cases you can set additional options specified by Mongoid.
205
Deploy Memcached service and relate it to Rack application:
207
juju deploy memcached
208
juju add-relation memcached rack
210
Rack charm will set environment variables which you can use to configure your Memcache adapter. [Dalli](https://github.com/mperham/dalli) use those variables by default.
212
MEMCACHE_PASSWORD => xxxxxxxxxxxx
213
MEMCACHE_SERVERS => instance.hostname.net
214
MEMCACHE_USERNAME => xxxxxxxxxxxx
218
Deploy Redis service and relate it to Rack application:
220
juju deploy redis-master
221
juju add-relation redis-master:redis-master rack
223
Rack charm will set environment variables which you can use to configure your Redis adapter.
225
REDIS_URL => redis://username:password@my.host:6389
227
For example you can configure Redis adapter in config/initializers/redis.rb
229
uri = URI.parse(ENV["REDIS_URL"])
230
REDIS = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)
234
## Rack application didn't start because assets were not compiled
236
To be able to compile assets before you've joined database relation you have to disable initialize_on_precompile option in application.rb:
238
config.assets.initialize_on_precompile = false
240
If you can't do this you still can join database and compile assets manually:
242
juju ssh rack/0 run rake assets:precompile
244
Then restart Rack service (while you have to replace 'rack/0' with your application name, e.g. 'sample-rails/0', 'sudo restart rack' is a valid command to restart any deployed application):
246
juju ssh rack/0 sudo restart rack
255
repo: <repository_url>
256
revision: <revision_number>
258
To deploy from private repo via SSH add 'deploy_key' option:
260
deploy_key: <private_key>
268
repo: <repository_url>
269
revision: <revision_number>
270
svn_username: <username>
271
svn_password: <password>
273
## Install extra packages
275
Specify list of packages separated by spaces:
277
extra_packages: 'libsqlite3++-dev libmagick++-dev'
281
You can set ENV variables, which will be available within all processes defined in a Procfile:
283
env: 'AWS_ACCESS_KEY_ID=aws_access_key_id AWS_SECRET_ACCESS_KEY=aws_secret_access_key'
b'\\ No newline at end of file'