Skip to content
This repository was archived by the owner on Oct 16, 2024. It is now read-only.
This repository was archived by the owner on Oct 16, 2024. It is now read-only.

Conditionally make assets... #4

Open

Description

@jmervine

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

Activity

  1. jmervine commented on Aug 18, 2015

    @jmervine
    Author

    That's pretty hacky though.

  2. hone commented on Aug 26, 2015

    @hone
    Member

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

  3. jmervine commented on Aug 26, 2015

    @jmervine
    Author

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

  4. gwmoura commented on Sep 30, 2015

    @gwmoura

    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

  5. jmervine commented on Sep 30, 2015

    @jmervine
    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
    
  6. gwmoura commented on Sep 30, 2015

    @gwmoura

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

  7. jmervine commented on Sep 30, 2015

    @jmervine
    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)
    
  8. gwmoura commented on Oct 1, 2015

    @gwmoura

    @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
  9. 3den commented on Apr 20, 2016

    @3den

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

  10. 3den commented on Apr 20, 2016

    @3den

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

  11. jmervine commented on Apr 20, 2016

    @jmervine
    Author

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

  12. 3den commented on Apr 20, 2016

    @3den

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

  13. jmervine commented on Apr 20, 2016

    @jmervine
    Author

    @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 join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions