stve/capistrano-local-precompile

clean_expired deletes all assets

sashazykov opened this issue · 17 comments

I also needed to disable deploy:assets:clean_expired

namespace :deploy do
  namespace :assets do
    task :clean_expired do ; end
  end
end
stve commented

I think I see the problem, the manifest file isn't being copied up. Working on a fix.

Is there a fix available? Can I help?

stve commented

I just pushed a manifest branch that encompasses some changes to copy the manifest. I've seen this in a few forks as well.

I haven't had time to test this (or write tests 😭). I'm a bit swamped at the moment so any help you can offer would be much appreciated.

It works now! Thank you.

or not( I need to test more

No, it doesn't work. At least in staging environment:

  * 2014-03-05 18:50:20 executing `deploy:assets:prepare'
    executing locally: "RAILS_ENV=staging RAILS_GROUPS=assets bundle exec rake assets:precompile"
    command finished in 121973ms
    executing locally: "rsync -av ./public/assets/ apps@dev.myapp.com:/home/apps/myapp/releases/20140305114937/public/assets/"
    command finished in 8778ms
    executing locally: "rsync -av ./assets_manifest.* apps@dev.myapp.com:/home/apps/myapp/releases/20140305114937/"
rsync: link_stat "/Users/sashazykov/Dropbox/Projects/myapp/./assets_manifest.*" failed: No such file or directory (2)
rsync error: some files could not be transferred (code 23) at /SourceCache/rsync/rsync-42/rsync/main.c(992) [sender=2.6.9]
*** [whenever:update_crontab] rolling back
  * executing "ls -x /home/apps/myapp/releases"
    servers: ["dev.myapp.com"]
    [dev.myapp.com] executing command
    command finished in 1509ms
  * executing "cd /home/apps/myapp/releases/20140305112638 && bundle exec whenever --update-crontab myapp --set environment=staging --roles app"
    servers: ["dev.myapp.com"]
    [dev.myapp.com] executing command
 ** [out :: dev.myapp.com] [write] crontab file updated
    command finished in 2735ms
*** [deploy:update_code] rolling back
  * executing "rm -rf /home/apps/myapp/releases/20140305114937; true"
    servers: ["dev.myapp.com"]
    [dev.myapp.com] executing command
    command finished in 1653ms
Command rsync -av ./assets_manifest.* apps@dev.myapp.com:/home/apps/myapp/releases/20140305114937/ returned status code pid 69835 exit 23
stve commented

After doing some more digging, I realized that assets_manifest.yml is actually created by capistrano and is basically a copy of the manifest.yml. In the last commit, I assumed this was a rake assets:precompile output. I've changed this to rsync the generated manifest.yml which should be the right approach. Do you mind trying again?

Now I get another error:

  * executing "ls public/assets/manifest*"
failed: "rvm_path=$HOME/.rvm $HOME/.rvm/bin/rvm-shell '2.0.0' -c 'ls public/assets/manifest*'" on dev.myapp.com
stve commented

Ah, it was looking on the server, not locally. Mind trying once more, thanks for being willing to test this stuff. I really need to be writing tests.

Success!

hey, just came back.
It seems to be working.

Also, I have a feature request. Currently when it precompiles, it uses the default(development) environment, shouldn't the environment be learnt from rails_env variable

stve commented

@nikhilvij I actually tried to address that in a recent commit 40c3de2 Sounds like you are seeing otherwise?

I also need to review #5 as the gem only works currently if you have config.assets.initialize_on_precompile = false set in application.rb.

Let me check again. I must be missing something then

stve commented

I just released 0.0.3 with these changes, feel free to re-open if you notice anything with the rails_env stuff. Thanks.

Hi, I was getting some error when I upgraded to 0.0.4 from 0.0.2
The run_locally function doesnt work well when you are setting environment in the command.
https://github.com/spagalloco/capistrano-local-precompile/blob/master/lib/capistrano/local_precompile.rb#L37
This should actually be

with_env("RAILS_ENV", "#{rails_env.to_s.shellescape}") { run_locally("#fetch(:precompile_cmd)}") }

and precompile command should be

set(:precompile_cmd)   { "RAILS_ENV=#{rails_env.to_s.shellescape} #{asset_env} #{rake} assets:precompile" }
stve commented

@nikhilvij can you submit a pull request with the changes?