Yarin
Yarin

Reputation: 183519

Getting rid of old compiled assets in Rails 4 / Heroku

Our Heroku-hosted Rails 4 public asset directory (~/public/assets) is polluted with multiple versions of compiled assets, including ones we deleted long ago. I can't figure out how to get rid of them- it's driving me nuts. Tried:

  1. heroku run rake assets:clean
  2. heroku run rake assets:clobber
  3. Running a bash session on Heroku and deleting them individually, or even deleting the entire ~/public/assets/ directory, but as soon as I re-login with another bash session they're still there!

Upvotes: 2

Views: 291

Answers (2)

Tom
Tom

Reputation: 520

Ok, guys. I now understand the problem and just in case it helps someone else:

You can not delete files via heroku run bash the way you would expect. This is by design. Have a look here: https://devcenter.heroku.com/articles/how-heroku-works#dyno-manager

The important thing to notice:

This [heroku run bash] will spin up a new dyno
...
Changes to the filesystem on one dyno are not propagated to other dynos and are not persisted across deploys and dyno restarts.

Ok, that explains it. So, what if you can't get rid of old assets and rake assets:clobber doesn't solve it? Well, maybe something is hiding in cache.

This solved it for me:

  1. Install the Heroku Repo plugin: https://github.com/heroku/heroku-repo
  2. Purge the build cache: heroku repo:purge_cache
  3. Rebuild the app: heroku repo:rebuild

Hope this helps ;)

Upvotes: 2

Zero Fiber
Zero Fiber

Reputation: 4465

Since heroku is precompiling your asset files on production, there is nothing much you can do since heroku has a ephemeral file system.

According to Heroku

Each dyno gets its own ephemeral filesystem, with a fresh copy of the most recently deployed code. During the dyno’s lifetime its running processes can use the filesystem as a temporary scratchpad, but no files that are written are visible to processes in any other dyno and any files written will be discarded the moment the dyno is stopped or restarted.

So every change that you make on heroku's file system gets wiped out.

Upvotes: 0

Related Questions