9

I have a problem on my production server where assetic:dump is timing out on a Capifony deploy (but not always).

Running assetic:dump locally is fine. Also deploying to a different staging (much less powerful) server is fine.

To fix this (and speed up deploy), I was wondering whether it's possible to run assetic:dump before a deployment and just send those complied assets along with the rest of the deployment?

ed209
  • 11,075
  • 19
  • 66
  • 82
  • Have you tried my solution ? I believe it's my best contribution to S.O., so I'd be glad to have it accepted if it worked :-) – Julien Jan 08 '13 at 17:44

3 Answers3

7

That's a bit tricky, I'm also trying to do this (java is not working properly on my server, so deployment fails).

The problem is that Capifony deploys from a source control repository, and usually dumped assets are not on the repository (and they shouldn't).

So I guess the only way to do this is to create a Capistrano task (Capifony is based on Capistrano) that will dump the assets and rsync them on the server.

Edit : Here's my attempt Edit : It does work, I've been using it since I answered the question.

I'm sure there are plenty of possible improvements, I'm not a ruby guy, I'm not a shell script guy either.

In your deploy.rb you can add two tasks :

before "deploy:update_code", "deploy:dump_assetic_locally"
after "deploy:update_code", "deploy:rsync_local_assets_to_server"

And the code associated to those tasks (in the same file) :

namespace :deploy do
  task :dump_assetic_locally, :roles => :web do
    run_locally "php app/console assetic:dump --env=prod"
  end

  task :rsync_local_assets_to_server, :roles => :web do
    finder_options = {:except => { :no_release => true }}
    find_servers(finder_options).each {|s| run_locally "rsync -az --delete --rsh='ssh -p #{ssh_port(s)}' #{local_web_path}/js/ #{rsync_host(s)}:#{release_path}/web/js/" }
    find_servers(finder_options).each {|s| run_locally "rsync -az --delete --rsh='ssh -p #{ssh_port(s)}' #{local_web_path}/css/ #{rsync_host(s)}:#{release_path}/web/css/" }
  end

  def local_web_path
    File.expand_path("web")
  end

  def rsync_host(server)
    :user ? "#{user}@#{server.host}" : server.host
  end

  def ssh_port(server)
    server.port || ssh_options[:port] || 22
  end

end
Julien
  • 9,312
  • 10
  • 63
  • 86
0

The command assetic:dump takes the assets from all the bundles avaiable in the current environment and places them in web/bundles (or where you tell it to). There should be no problem in doing this locally and then just moving the files.

You should run the command with the env=prod option to ensure all bundles which are needed in production are getting generated. You migh also want to clean the web/bundles before running the command so the assets for bundles which are only used in development (e.g. profiler) are not present.

I would simply do a test by running the command locally, download the assets from production and compare them. I cannot think of anything right now as css and js gets served to the client and should not be different when generated on different machines, but I might be wrong.

Sgoettschkes
  • 13,141
  • 5
  • 60
  • 78
-1

Is very simple add to your deploy.rb

set :dump_assetic_assets, true
liuggio
  • 384
  • 3
  • 3