8000 Conditionally make assets... · Issue #4 · heroku/docker-ruby · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Oct 16, 2024. It is now read-only.

Conditionally make assets... #4

Open
jmervine opened this issue Aug 18, 2015 · 13 comments
Open

Conditionally make assets... #4

jmervine opened this issue Aug 18, 2015 · 13 comments

Comments

@jmervine
Copy link

Not 100% sure this will work but I think it's...

# How to conditionally `rake assets:precompile`?
ONBUILD RUN bundle exec rake assets:precompile || true
@jmervine
Copy link
Author

That's pretty hacky though.

@hone
Copy link
Member
hone commented Aug 26, 2015

Yeah, if it fails it should break building if you expect it to run.

@jmervine
Copy link
Author

Right, so you need to grep the output and return true if there's no task and false if there is... Ugly.

@gwmoura
Copy link
gwmoura commented Sep 30, 2015

guys, I test this:

ONBUILD RUN if [ -f /app/user/Rakefile ]; then bundle exec rake assets:precompile; fi

and work for me. I tested using an simple script with Gemfile without rails or sinatra, only ruby

@jmervine
Copy link
Author

@gwmoura I can see quite a few use-cases were an app would have a Rakefile without assets:precompile... how about...

ONBUILD RUN test "$(bundle exec rake -T | grep assets:precompile)" && bundle exec rake assets:precompile

@gwmoura
Copy link
gwmoura commented Sep 30, 2015

@jmervine yes, can be, in my case, I execute a ruby script only, no Rails. Your solution not work for me :(

@jmervine
Copy link
Author

@gwmoura Merging the two, you could do something like (untested):

ONBULD RUN test -f /app/user/Rakefile && (test "$(bundle exec rake -T | grep assets:precompile)" && bundle exec rake assets:precompile)

@gwmoura
Copy link
gwmoura commented Oct 1, 2015

@jmervine I tested your script and this worked fine for me. @hone if you want, you can add on Dockerfile.

I tested locally, but I will add in my image based on heroku/ruby

Look my results:

$ ls
app.rb  docker-compose.yml  Dockerfile  Gemfile  Gemfile.lock  run.sh  vendor

$ test -f Rakefile && (test "$(bundle exec rake -T | grep assets:precompile)" && bundle exec rake assets:precompile)

And in a rails app too not work

$ ls
app  config     db       Gemfile.lock  log     Rakefile     test  vendor
bin  config.ru  Gemfile  lib           public  README.rdoc  tmp

$ test -f Rakefile && (test "$(bundle exec rake -T | grep assets:precompile)" && bundle exec rake assets:precompile)
I, [2015-10-01T18:41:24.746492 #2063]  INFO -- : Writing /home/george/workspace/tests/ruby/railsblocks/myproject/public/assets/application-d4d603d0ff049a3ecfbf019b468bf1a62a50b9fdafe41213c300fa071342b600.js
I, [2015-10-01T18:41:24.749187 #2063]  INFO -- : Writing /home/george/workspace/tests/ruby/railsblocks/myproject/public/assets/application-e80e8f2318043e8af94dddc2adad5a4f09739a8ebb323b3ab31cd71d45fd9113.css

@3den
Copy link
3den commented Apr 20, 2016

why cant we just remove the assets:precompile from this Docker file and have users add it if needed?

@3den
Copy link
3den commented Apr 20, 2016

even with the suggested fix it would not work for my team because we need to run bower install before the assets:precompile.

@jmervine
Copy link
Author

@3den Perhaps add bower install as a pre-req task to assets:precompile?

@3den
Copy link
3den commented Apr 20, 2016

@jmervine thanks for the reply, what is the best way to do that?

@jmervine
Copy link
Author
jmervine commented Apr 20, 2016

@3den My rake-fu is not super strong, but the first section here talks about how to build dependency tasks. You'll have to build a custom task for the bower install part, I found an overly complicated example here, but you should be able to pull out the useful bits.

Because assets:precompile is built in to rails, or so I believe, you might have to do some googling around how to customize that task. It's probably not that difficult though.

Cheers!

Edit: This talks about how to do exactly what we're talking about here. I didn't vet it, but it should be a good start.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
0