[LRUG] Rails 4 & Assets

Murray Steele murray.steele at gmail.com
Thu Jun 27 01:01:39 PDT 2013


Hey group,

Yesterday I was doing some deployment wrangling on my current project.  As
part of this I realised I didn't need to ship the asset gems to production
because we precompile them elsewhere.  As we're not live yet, the thought
struck me that I might want to upgrade the app to Rails 4 sooner rather
than later, and a colleague pointed out that there's no asset group in
Rails 4 anymore.

So I started digging, and have to say I'm a bit confused.  Assuming I want
to keep doing what I'm doing:

1. run tests on jenkins
2. precompile assets on jenkins
3. copy everything to a new place
4. restrict the gems in that new place with a bundle install --deployment
--without development test assets
5. turn that into an rpm and ship it

End result: deployed app has no development or test gems, has precompiled
assets, has no asset compilation gems.

(Note, this isn't necessarily how I'd want to deploy, but it's not my
infrastructure so I can't really change it.  Let's not play *that* game.).

How can I achieve step 4 and thus not ship the asset compilation gems to my
deployment machines?

Rails 4 has no asset group, so I can't just --without assets.  The bundler
line in application.rb is Bunder.require(:default, Rails.env) so I can't
create an assets group for those gems and expect RAILS_ENV=production
bundle exec rake assets:precompile to still work.

I get that this is conceptually simpler and presumably there is less
bullshit magic in the assets:precompile task to make sure that the assets
gem group is available.  But it seems to be closing off what I assume is a
pretty standard deployment process: build assets elsewhere, don't ship a
javascript runtime to the deployment area when you don't need it.

Thoughts:

1. create a new environment "assets" that is a clone of production and make
the assets gems available in that.  Remember to use RAILS_ENV=assets
instead of RAILS_ENV=production when compiling assets.  I worry about this
because rails environments can end up being a bit special - I've been
bitten in the past by trying to run a test suite in an RAILS_ENV not called
"test".

2. create a custom assets:precompile task that does some bullshit magic to
make the assets gems available.  I worry about this because "bullshit
magic".

3. <your better ideas go here>

Anyone?

Muz
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lrug.org/pipermail/chat-lrug.org/attachments/20130627/6d8f1a3c/attachment-0003.html>


More information about the Chat mailing list