Does Phusion Passenger automatically precompile assets after restarting? - ruby-on-rails

Via git, I downloaded the latest version of my web-app to our server. I did a touch tmp/restart.txt but this didn't precompile my assets. I did a rake assets:clobber assets:precompile and this refreshed my assets.
Is Passenger supposed to refresh my asset pipeline automatically? If it is, what are some things I ought to look into to troubleshoot this?
Running rails 4.0.0 (unsure of how to check my passenger version)

No, Passenger does not compile assets for you. See http://guides.rubyonrails.org/asset_pipeline.html#in-production - By default Rails in production does "assumes assets have been precompiled and will be served as static assets by your web server".
Do you have a deployment script such as Capistrano ? Most rails deployment scripts should trigger precompilation.

Related

Compiling Assets in Ruby does it need to be done in deployment? Why not before?

So this is just a question I've been wondering about lately, I seem to spend a significant amount of time when deploying waiting for assets to compile.
Why can we not compile the assets on our development machines and submit it in the git repo?
I am currently using ruby 2.5.x and rails 5.2.4.x using the assets pipeline with uglifier.
Is there a way to do this in development and thus disable all asset compilation during deployment?
many thanks,
Simon
The solution was pretty simple
1) disable asset compiling during deployment
I'm using elastic beanstalk so just had to set this in the environment variables
2) Either
Add the /public/assets folder to git
Or for elastic beanstalk create .ebignore file and copy over the .gitignore but remove the /public/assets entry
3) before deploying run
Linux -- RAILS_ENV=development bundle exec rake assets:precompile
Windows -- set RAILS_ENV=development && bundle exec rake assets:precompile
4) deploy code to server as normal
eb deploy
1st: Why can we not compile the assets on our development machines and submit it in the git repo?
The reason why we need to precompile are:
Compressed the assets resources then cached some static content like images, css and so on.
It's help us to generates two files (.css and .js) and compressed all our's css file event it's file from vendors:
<script src="/assets/application-908e25f4bf641868d8683022a5b62f54.js"></script>
<link href="/assets/application-4dd5b109ee3439da54f5bdfd78a80473.css" media="screen"
rel="stylesheet" />
It's very helpful but It's take time and `And the resource it not live reload when you modify some code. You have to re-compile to apply the code.
-> So, That's why you should not compile the assets in DEVELOPMENT evironment.
2nd: Is there a way to do this in development and thus disable all asset compilation during deployment?
You also use precompile on DEVELOPMENT by run this command:
RAILS_ENV=development bundle exec rake assets:precompile
You can precompile assets in development environment by default using
config/development.rb
config.assets.debug = false
Thanks. Hope it's help
In my case, I precompile before deployment, commit, and push it to Github, as you mentioned.
Then, I deploy to production with capistrano gem: https://github.com/capistrano/capistrano
This is the command to precompile:
rails assets:precompile

Rails 4 compiled assets only works after server reboot

I deploy my Rails app using Capistrano 3 and rails 4, and ubuntu VPS, but the compiled assets cannot be found after deployment, it always return route error, I had to reboot my server, then it will work.
restart Nginx and Unicorn doesn't help.
Any idea?
Run
rake assets:precompile
before deployment
I do the following when deploying latest changes:
I pull my latest version from Github.
I run
bundle exec rake assets:precompile
sudo service nginx restart
Now when accessing your website the code will be loaded into the RAM with your assets being served correctly.
You need to disable static assets serving in your config/environments/production.rb
config.serve_static_assets = false
Hope I could help you.

How can one clean old Rails assets when they are being precompiled locally and added to repository?

I use Capistrano for deploying my Rails 4 app. Precompiling assets on the server is very slow so I manually precompile it in development using RAILS_ENV=production bundle exec rake assets:precompile and add it to my git repo.
The problem I am facing is that the assets:precompile task does not remove the old assets. So, I have multiple copies of application-<manifest code>.css and application-<manifest-code>.js in my public assets.
Capistrano has deploy:assets:clean_expired task for this though I am not sure how can I replicate it in my case. I have seen other approaches which use capistrano task to precompile assets and rsync them up. This link - http://keighl.com/post/fast-rails-assets-precompile-capistrano/ - has an approach for Rails 3 using the turbo-sprockets-rails3 gem.
There are similar questions here - Do I have to run rake assets:clean before rake assets:precompile? and Confusion about rake assets:clean / cleanup on the asset pipeline in rails
How can I adapt it for Rails 4?
This is working well for me now - https://gist.github.com/mishrarohit/7802260 It uses git revision history to check if any changes have been made to assets. It will be better if we can use the manifest for this.

rails 3.2.3 rake assets:precompile task takes more than 30 minutes

The problem with this app is that is WIP, so we are not using anything to deploy it to our production server, we just clone it from github and we are doing a git pull every time we have something done, rake assets:precompile task takes more than 30 minutes to finish!, WTF?.
We are doing this:
$ bundle exec rake assets:clean
$ bundle exec rake assets:precompile
Our production server:
ruby 1.9.3p194 (rbenv)
rails 3.2.3
unicorn
nginx
Our rails + unicorn + rbenv + init.d daemon configuration is here: https://gist.github.com/2776085
Now, here's our assets manifests, Gemfile and our production.rb files: http://pastie.org/3958070
So, somebody knows why this takes so long? or there's a way to speed up assets compilation in production?.
Thank you.
UPDATE: Assets compilation times locally: http://pastie.org/3961734
Rails's asset pipeline looks a little bit further than app/assets/{javascripts,stylesheets}.
As mentioned in the guides, there are also other locations where you can put your application's assets:
app/assets
lib/assets
vendor/assets
I suggest you to read the complete guide on Rails's asset pipeline to get more information about all this and also some tips for your production environment, such as nginx rules for caching, speeding up the assets pre-compilation, etc.
Was our fault, we have an extra folder inside app/assets, like app/assets/blah with a lot of folders inside, so the assets pipeline was looking over there, still, we don't know why the assets pipeline isn't just looking inside app/assets/javascripts and app/assets/stylesheets.

Uncompile Development Asset Pipeline

I was compiling my asset pipeline for my production environment and it did for all my environments. How can I uncompile my asset pipeline for my development environment?
I have checked my config/development environment and cannot find a fix.
Thanks in advance for any help...
To remove precompiled assets use:
rake assets:clean
What this basically does is remove the public/assets directory. You may need to include the RAILS_ENV variable if you need to run it for a certain environment.
Try using
rake assets:clobber
worked for me in rails 4
When you run the compile task locally (on your development machine) the assets are compiled in the Rails production environment, but are written to the public folder.
This means that even when you run in development mode it'll use the compiled assets instead of sending requests to the pipeline. This is normal behavor - requests only go to the pipeline if the file does not exists in public/assets.
The compile task should generally only be used when deploying, and on the remote (production) machine.
If you have compiled locally, you can delete all the files in the public/assets folder and development will behave as before. If you checked these files into source control you'll need to remove them.
Once removed things should work fine.
s
One final tip: if this is an upgraded app check your config settings against those in the last section of the Rails asset pipeline guide.
For Rails 5:
$ RAILS_ENV=development bin/rake assets:clobber

Resources