Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to compile Symfony2 assetic:dump and deploy that rather than run it on the server?

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?

like image 861
ed209 Avatar asked Sep 04 '12 10:09

ed209


1 Answers

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
like image 194
Julien Avatar answered Nov 08 '22 07:11

Julien