Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Optimizing deployment of rails app to multiple servers, using asset pipeline

I am deploying a rails app in a multi-server environment. The app uses the asset pipeline, and assets are being served from s3. If I run assets:precompile on each server I deploy to, everything works fine (the needed assets/manifest.yml gets generated on each box).

The issue is that this feels very inefficient. I tried designating one of the servers as primary, and only running assets:precompile on that box. The issue now is that the other servers do not have a copy of assets/manifest.yml.

I think the solution will involve figuring out the simplest way to share the generated assets/manifest.yml file on all boxes.

How do others handle this situation?

Thanks for your help.

like image 355
sethmcl Avatar asked Oct 15 '13 21:10

sethmcl


1 Answers

Ended up solving this by writing this cap task:

task :assets_precompile, { on_no_matching_servers: :continue, only: { primary: true } } do
  transaction do
    on_rollback do
      notification.exception_deploy
    end

    run "cd #{current_release} && RAILS_ENV=#{stage} rake assets:precompile"

    # sync manifest.yml
    download("#{current_release}/public/assets/manifest.yml", "/tmp/manifest.yml")

    find_servers().each do |current_server|
      run_locally "ssh app@#{current_server.host} 'mkdir -p #{current_release}/public/assets'"
      run_locally "scp /tmp/manifest.yml app@#{current_server.host}:#{current_release}/public/assets/manifest.yml"
    end
  end
end

Seems a bit hacky, but gets the job done. We didn't want to do pre-compilation locally.

like image 161
sethmcl Avatar answered Nov 04 '22 08:11

sethmcl