GC overhead limit exceeded for assets:precompile in Rails - ruby-on-rails-4

When I run rake assets:precompile RAILS_ENV=production , I got the below error
Java::JavaLang::OutOfMemoryError: GC overhead limit exceeded
(in /home/avijit/railswork/tracksynqv2/app/assets/javascripts/application.js)
org.mozilla.javascript.Interpreter.interpretLoop(org/mozilla/javascript/Interpreter.java:1382)
org.mozilla.javascript.Interpreter.interpret(org/mozilla/javascript/Interpreter.java:815)
org.mozilla.javascript.InterpretedFunction.call(org/mozilla/javascript/InterpretedFunction.java:109)
org.mozilla.javascript.ContextFactory.doTopCall(org/mozilla/javascript/ContextFactory.java:393)
org.mozilla.javascript.ScriptRuntime.doTopCall(org/mozilla/javascript/ScriptRuntime.java:3280)
org.mozilla.javascript.InterpretedFunction.call(org/mozilla/javascript/InterpretedFunction.java:107)
java.lang.reflect.Method.invoke(java/lang/reflect/Method.java:498)
RUBY.call(/home/avijit/.rvm/gems/jruby-1.7.16/gems/therubyrhino-2.0.4/lib/rhino/rhino_ext.rb:193)
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)
I update my production.rb file with config.assets.compile = true and config.serve_static_assets = true. I deploy my rails app using passenger and apache2.

assets:precompile comsume a lot of memory when you run it; try check you system monitor when you running it and increase you memory in the server where you execute that task.
By the way config.serve_static_assets = false should be false in production the server software (e.g. NGINX or Apache) used to run the application should serve static assets instead. Also now this property was rename to config.serve_static_files, as I remember.

Related

Rails: How to set up db:schema:load for initial deploy with Capistrano

I'm trying to deploy my Rails 4 app using Capistrano 3. I'm getting error messages in running the db:migrations (i've been sloppy, sorry). Is there a way to have Capistrano deploy the app (at least the first time) using db:schema:load?
An excerpt of my deploy.rb:
namespace :deploy do
%w[start stop restart].each do |command|
desc 'Manage Unicorn'
task command do
on roles(:app), in: :sequence, wait: 1 do
execute "/etc/init.d/unicorn_#{fetch(:application)} #{command}"
end
end
end
I'm not sure how to override Capistrano 3's default behaviour. Can someone tell me how to add this to my script?
For first time deploys, I generally hack around it by logging into the server, cding into the release directory (which will have the deployed code at this point), and then manually running RAILS_ENV=yourenv bundle exec rake db:setup.
In Capistrano 3.10.1 with a Rails 5.1.6 application,
~/Documents/p.rails/perla-uy[staging]$ bundle exec cap staging deploy:updating
gives me enough to shell-in and run the db:structure:load or db:schema:load task manually. In the secure shell session to the host, switch to the newly created release directory and:
dclo#localhost:~/perla-uy/releases/20180412133715$ bundle install --without development test --deployment
dclo#localhost:~/perla-uy/releases/20180412133715$ bundle exec rails db:schema:load
Shelling into a (successful or failed) deploy that has tried deploy:migrate isn't quite the same.
Note: I have RAILS_ENV=production and RAILS_MASTER_KEY=... set-up by the shell login.

Rails 4.2 + Nginx + Unicorn - Missing secret_token and secret_key_base after deployed

I deployed a Rails 4 app ( using .rbenv ) to a remote Ubuntu server running Ngninx + Unicorn using Capistrano ( staging deployment)
E, [2015-08-10T16:53:29.822778 #24117] ERROR -- : app error: Missing `secret_token` and `secret_key_base` for 'staging' environment, set these values in `config/secrets.yml` (RuntimeError)
Using the capistrano/upload-config , I link the secrets.yml file on the remote server in the current release deployed
app/config/
secrets.staging.yml
secrets.yml -> /var/www/rails/delayMessage/shared/config/secrets.yml
and the /var/www/rails/delayMessage/shared/config/secrets.yml file contains
staging:
secret_key_base: 10c7ed6bccc6d3acb71...
Why is the secret_key_base NOT taken into account, and why is this error raised and displayed in the unicorn.stderr.log
UPDATE 1
in unicorn.rb I have the following paths (app and shared ) set ... maybe they are wrong
# Set your full path to application.
app_dir = File.expand_path('../../', FILE)
shared_dir = File.expand_path('../../../shared/', FILE)
I had a similar situation, but, .rbenv was not on my list. My solution was actually, pretty easy.
First I stopped unicorn (not only restart), I mean, really stop it with the following
sudo service unicorn_myapp force-stop
And also stopped the Nginx:
sudo service nginx stop
Then ran the:RAILS_ENV=environment rake secret copied the value into the staging section in /deployed_app/shared/config/secrets.yml and then, restarted all again with
sudo service unicorn_myapp start
sudo service nginx start
And all is back on track again...
Hope it helps

rails 4 deployment - rake stderr: config.eager_load is set to nil .. incorrect error message

during a project staging deployment w Capistrano, with a common db access error to be solved, I noticed the rake stderr line :
rake stderr: config.eager_load is set to nil. Please update your config/environments/*.rb files accordingly..
however , my config/environments/*rb files are correctly set as required..
why this message ? what did I missed ?
my config/environments/development.rb
config.eager_load = false
my config/environments/production.rb
config.eager_load = true
my config/environments/test.rb
config.eager_load = false
here is the extract from the console log
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
SSHKit::Command::Failed: rake exit status: 1
rake stdout: Nothing written
rake stderr: config.eager_load is set to nil. Please update your config/environments/*.rb files accordingly:
* development - set it to false
* test - set it to false (unless you use a tool that preloads your test environment)
* production - set it to true
rake aborted!
Mysql2::Error: Access denied for user 'root'#'localhost' (using password: NO)
I had a similar issue when deploying with
cap staging deploy
The problem was that capistrano was looking for the database myapp_staging, while I needed myapp_production.
I fixed it by adding
set :stage, "production"
in config/deploy/staging.rb.
(Answered in the comments. Converted to a community wiki answer. See Question with no answers, but issue solved in the comments (or extended in chat) )
#amoebe wrote:
I think the main problem here is wrong MySQL credentials.
The OP wrote:
you're right, I had to manage my production/staging deployment credentials via a capistrano task ( setup:upload_yml) to upload the secrets.yml and database.yml into my remote server.... running fine now...

In capistrano 3, is it possible to bundle & asset precompile locally and copy the results to application server?

At present, I have it setup so that capistrano git pulls the latest code on production servers, bundle installs and asset precompiles it individually on each web server.
The problem that I am running into is that occationally it will take a long time and take up a lot of resources that impacts the performance on the production servers.
I am looking for guidelines on how best to do this.
If anyone has experience with this and can share their opinions, I would really appreciate it.
I am looking to see if this is a good/bad idea and what are common pitfalls I should watch out for.
I would also appreciate any link to blog post/tutorial/documentation that could help with this.
Thanks for reading.
Ankit.
Here is my work around. Try adding it in namespace :deploy
namespace :assets do
desc 'Run the precompile task locally and rsync with shared'
task :precompile, :roles => :web, :except => { :no_release => true } do
unless skip_assets
%x{bundle exec rake assets:clean RAILS_ENV=#{rails_env}}
run_local "bundle exec rake assets:precompile RAILS_ENV=#{rails_env}"
servers = find_servers_for_task(current_task)
port_option = port ? "-e 'ssh -p #{port}'" : ''
servers.each do |server|
%x{rsync --recursive --times --rsh=ssh --compress --human-readable --progress #{port_option} public/assets #{user}##{server}:#{shared_path}}
end
%x{bundle exec rake assets:clean RAILS_ENV=#{rails_env}}
end
end
end
def run_local(cmd)
system cmd
if($?.exitstatus != 0) then
puts 'exit code: ' + $?.exitstatus.to_s
exit
end
end

Django Deploy From Github to Server Like Capistrano with Simple Fabric Recipe

I wanted to use Capistrano to deploy on my django app on my webfaction server but due to my purist tendencies, I wanted to do it in Fabric, in a way that Capistrano does. The thing that I liked most about about Capistrano is that automatically retrieves a repo's content and pushes it to a server.
The fabric recipes I have seen so far required me to do things "the git way", manually entering git commands to work with the repo, etc.
Is there a way to deploy a Django app in Fabric (or any other python package) "the Capistrano" way?
Sie Note: In case I really have to work with Capistrano, is there a way to bypass the assets precompile task and the rake db:migrate task?
Ive successfully used the scripts from here to deploy to webfaction.
If you want to bypass the assets compilation, just don't write this line in your recipe :
load 'deploy/assets'
If you don't want to run migration, just never type the migration command
cap deploy:migrate
If you want to remove some other behaviors (symlink, restart, update code to server) write chosen parts from this :
namespace :deploy do
task :start do ; end
task :stop do ; end
task :restart do ; end
task :update_code do ; end #override this task to prevent capistrano to upload on servers
task :symlink do ; end #don't create the current symlink to the last release
end
for anyone who stumbles across this, here is a capistrano recipe that is so basic :
http://ygamretuta.me/2012/07/18/deploy-django-1-4-webfaction-capistrano/