Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm deploying a simple Rails app to this small ubuntu precise64 server setup :
* 1 server running nginx
* 2 servers running unicorn
* 1 server running postgresql

My servers are provisionned with Puppet and I'm pushing the app with capistrano.

My Capfile

load 'deploy'
# Uncomment if you are using Rails' asset pipeline
load 'deploy/assets'
load 'config/deploy' # remove this line to skip loading any of the default tasks

The deploy.rb file is super simple

# Execute "bundle install" after deploy, but only when really needed
require "bundler/capistrano"

# Name of the application in scm (GIT)
set :application, "devops-test-app"
set :repository, "https://github.com/geoffroymontel/devops-test-app.git"
set :scm, :git

set :deploy_to, "/var/www/#{application}"

# server there the web server is running (nginx)
role :web, "33.33.13.2"

# server there the db is running
# This is where Rails migrations will run
role :db, "33.33.13.3", :primary => true

# servers there the app servers are running (unicorn)
role :app, "33.33.13.4", "33.33.13.5"

set :rails_env, :production

# user on the server
set :user, "deployer"
set :use_sudo, false

namespace :deploy do 
  task :start, :roles => :app, :except => { :no_release => true } do
    run "service unicorn_#{application} start"
  end

  task :stop, :roles => :app, :except => { :no_release => true } do
    run "service unicorn_#{application} stop"
  end

  task :restart, :roles => :app, :except => { :no_release => true } do
    run "service unicorn_#{application} restart"
  end

  task :copy_in_database_yml do
    run "cp #{shared_path}/config/database.yml #{latest_release}/config/"
  end

  # Precompile assets
  # I have to precompile the assets on the app servers too, and I don't really know why...
  # namespace :assets do
  #   task :precompile, :roles => [:web, :app], :except => { :no_release => true } do
  #     run %Q{cd #{latest_release} && #{rake} RAILS_ENV=#{rails_env} #{asset_env} assets:precompile}
  #   end
  # end
end

before "deploy:assets:precompile", "deploy:copy_in_database_yml"

If I don't precompile assets on the app servers, the application fails.

$ cap ROLES="app" COMMAND="cat /var/www/devops-test-app/current/log/production.log" invoke
  * 2013-05-01 21:43:10 executing `invoke'
  * executing "cat /var/www/devops-test-app/current/log/production.log"
    servers: ["33.33.13.4", "33.33.13.5"]
    [33.33.13.5] executing command
 ** [out :: 33.33.13.5] Connecting to database specified by database.yml
 ** [out :: 33.33.13.5] Connecting to database specified by database.yml
 ** [out :: 33.33.13.5] Started GET "/posts" for 33.33.13.2 at 2013-05-01 19:42:10 +0000
 ** [out :: 33.33.13.5] Processing by PostsController#index as HTML
 ** [out :: 33.33.13.5] Rendered posts/index.html.erb within layouts/application (25.7ms)
 ** [out :: 33.33.13.5] Completed 500 Internal Server Error in 122ms
 ** [out :: 33.33.13.5] 
 ** [out :: 33.33.13.5] ActionView::Template::Error (application.css isn't precompiled):
 ** [out :: 33.33.13.5] 2: <html>
 ** [out :: 33.33.13.5] 3: <head>
 ** [out :: 33.33.13.5] 4:   <title>DevopsTestApp</title>
 ** [out :: 33.33.13.5] 5:   <%= stylesheet_link_tag    "application", :media => "all" %>
 ** [out :: 33.33.13.5] 6:   <%= javascript_include_tag "application" %>
 ** [out :: 33.33.13.5] 7:   <%= csrf_meta_tags %>
 ** [out :: 33.33.13.5] 8: </head>
 ** [out :: 33.33.13.5] app/views/layouts/application.html.erb:5:in `_app_views_layouts_application_html_erb__677166568443748084_17536100'
 ** [out :: 33.33.13.5] app/controllers/posts_controller.rb:7:in `index'

If I uncomment the commented lines in deploy.rb, everything is fine.

But why ?? I thought you would need to compile the assets only on the web server, not on the app server.

Please help me understand why :)

Thanks, best regards

Geoffroy

share|improve this question
1  
I hope you aren't actually using those IP addresses, or the US Department of Defense may become unhappy with you, since they're assigned to the DoD... –  Michael Hampton May 1 '13 at 19:49
    
oooops, didn't know that, this is a local setup (running on vagrant) –  geoffroy May 1 '13 at 20:13
    
There are IP addresses reserved for private networks already. See RFC 1918 for the complete list. –  Michael Hampton May 1 '13 at 20:16
    
thanks ! I just took the trick from the book Deploying Rails, not to interfere with my local network. But I will use 172.16.0.0 addresses from now. Best –  geoffroy May 1 '13 at 20:25
    
That crap actually got into print?! Take your copy and beat the author over the head with it. :) –  Michael Hampton May 1 '13 at 20:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.