bundle exec rake doesn't work - ruby

I am using terminal on a macbook air and any command beginning with bundle exec rake db: does't work. I am trying to remove all the tables from my database (aka start from scratch) and them migrate once. Every time I execute any bundle exec rake db: command it just waits a few seconds then stops. Here is a --trace for bundle exec rake db:rollback as an example.
** Invoke db:rollback (first_time)
** Invoke db:environment (first_time)
** Execute db:environment
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:rollback
** Invoke db:_dump (first_time)
** Execute db:_dump
** Invoke db:schema:dump (first_time)
** Invoke db:environment
** Invoke db:load_config
** Execute db:schema:dump

Related

Troubleshooting rails 6, bootstrap 4, webpacker on heroku

Heroku deploy fails. So I tried doing it locally same issue.
$ NODE_ENV=production RAILS_ENV=production rails assets:precompile --trace
** Invoke assets:precompile (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
** Invoke yarn:install (first_time)
** Execute yarn:install
yarn install v1.13.0
[1/4] 🔍 Resolving packages...
[2/4] 🚚 Fetching packages...
[3/4] 🔗 Linking dependencies...
warning " > webpack-dev-server#3.3.1" has unmet peer dependency "webpack#^4.0.0".
warning "webpack-dev-server > webpack-dev-middleware#3.6.2" has unmet peer dependency "webpack#^4.0.0".
[4/4] 🔨 Building fresh packages...
✨ Done in 7.99s.
** Execute assets:precompile
I, [2019-04-16T12:10:11.016887 #96897] INFO -- : Writing /private/tmp/template-a32b218/public/assets/application-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.css
I, [2019-04-16T12:10:11.017485 #96897] INFO -- : Writing /private/tmp/template-a32b218/public/assets/application-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.css.gz
** Invoke webpacker:compile (first_time)
** Invoke webpacker:verify_install (first_time)
** Invoke webpacker:check_node (first_time)
** Execute webpacker:check_node
** Invoke webpacker:check_yarn (first_time)
** Execute webpacker:check_yarn
** Invoke webpacker:check_binstubs (first_time)
** Execute webpacker:check_binstubs
** Execute webpacker:verify_install
** Invoke environment
** Execute webpacker:compile
Compiling…
Compilation failed:
$ echo $?
1
Webpacker can silently hang if you forgot to do a "yarn add " before actually using a package in your application.
Found the answer to my own question.
In config/webpacker.yml, there's a boolean option to make the output more verbose. And it told me there's was a typo in one of my include statements.

how to run rake db:migrate on irb

I am trying to run a migration script on irb but it returns syntax error.
irb(main):008:0> rake db:migrate:up VERSION=20171006190045
SyntaxError: (irb):8: syntax error, unexpected tLABEL
rake db:migrate:up VERSION=20171006190045
tried rake db:migrate:redo VERSION=20171006190045
Also tried this
irb(main):012:0> require 'db/migrate/20171006190045_update_details.rb'
LoadError: cannot load such file -- db/migrate/20171006190045_update_details.rb
from (irb):12
rake is not meant to be run within IRB. I agree with #spickermann. You can run it in rails console by using system command.
$ rails c
> system("rake db:migrate:up VERSION=20171006190045")
or simply in terminal
$ rake db:migrate:up VERSION=20171006190045
rake is not meant to be run within IRB. It is a command line program like IRB. Just exit IRB and run it in your terminal.
irb does not respond to rake. Exit out of irb like so:
irb(main):008:0> exit
Then simply run your rake command:
rake db:migrate:up VERSION=20171006190045
No, it is not necessary to run it using system command.
Rails.application.load_tasks
Rake::Task['my_task'].invoke

Gem installed, but not found by Ruby?

I have the following Capistrano snippet:
namespace :bundle do
task :install do
run "gem list && bundle -v"
end
end
When I run
cap bundle:install
I get the following output:
** [out :: ....compute-1.amazonaws.com]
** [out :: ....compute-1.amazonaws.com] *** LOCAL GEMS ***
** [out :: ....compute-1.amazonaws.com]
** [out :: ....compute-1.amazonaws.com]
** [out :: ....compute-1.amazonaws.com] bundler (1.3.4)
** [out :: ....compute-1.amazonaws.com] rake (10.0.3)
** [out :: ....compute-1.amazonaws.com] rubygems-bundler (1.1.1)
** [out :: ....compute-1.amazonaws.com] rvm (1.11.3.6)
** [out :: ....compute-1.amazonaws.com]
** [out :: ....compute-1.amazonaws.com] ERROR: Gem bundler is not installed, run `gem install bundler` first.
gem is showing bundler is installed, but when I try to run bundle -v, I get a contradicting error saying it's not? I don't understand why?
The other thing I tried was to login to the server via terminal, when I run bundle -v there, it works fine?
Any ideas what's wrong?
do you use rvm-capistrano gem? It will load RVM for you.
I managed to get my script working by adding some environment variables:
set :default_environment, {
:PATH => "/home/ubuntu/.rvm/gems/ruby-1.9.2-p320#my_gemset/bin:" +
"/home/ubuntu/.rvm/gems/ruby-1.9.2-p320#global/bin:" +
"/home/ubuntu/.rvm/rubies/ruby-1.9.2-p320/bin:" +
"/home/ubuntu/.rvm/bin:" +
"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
:RUBY_VERSION => 'ruby-1.9.2-p320',
:GEM_HOME => '/home/ubuntu/.rvm/gems/ruby-1.9.2-p320#my_gemset',
:GEM_PATH => '/home/ubuntu/.rvm/gems/ruby-1.9.2-p320#my_gemset:/home/ubuntu/.rvm/gems/ruby-1.9.2-p320#global'
}

Why is assets:precompile so slow on Heroku?

My deployment set up is to have Heroku precompile assets. I want them precompiled so I can send them to a CDN (via asset_sync) and I want that done on Heroku so I don't have any compiled assets in my repo. I set that up using Heroku's guide and that had been working great. I added turbo-sprockets-rails3 for a speed boost. It had all been working fine and then stopped; I can't figure out why.
Now when I deploy (without public/assets) the assets:precompile Rake task times out on Heroku. To see how long it's really taking, I went into a shell (heroku run bash):
~ $ time bundle exec rake assets:precompile
AssetSync: YAML file found /app/config/asset_sync.yml settings will be merged into the configuration
AssetSync: Syncing.
Using: Directory Search of /app/public/assets
AssetSync: Done.
real 19m29.575s
user 17m43.690s
sys 0m28.480s
Twenty minutes! But when I run it locally (2011 iMac), it's only only a few minutes:
$ env RAILS_ENV=production time bundle exec rake assets:precompile --trace
** Invoke assets:precompile (first_time)
** Execute assets:precompile
~/.rbenv/versions/1.9.3-p327-perf/bin/ruby ~/.rbenv/versions/1.9.3-p327-perf/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets --trace
** Invoke assets:precompile:all (first_time)
** Invoke assets:cache:clean (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
AssetSync: YAML file found ~/Code/Ruby/myproject-rails/config/asset_sync.yml settings will be merged into the configuration
** Execute assets:cache:clean
** Execute assets:precompile:all
AssetSync: Syncing.
Using: Directory Search of ~/Code/Ruby/myproject-rails/public/assets
Uploading: assets/application-3a6de939348195e9610f1321df27837a.js
Uploading: assets/application-3a6de939348195e9610f1321df27837a.js.gz
Uploading: assets/jquery.min-959a5819c76e1508f5a8655c289c0de8.map
Uploading: assets/jquery.min.map
Uploading: assets/rails_admin/rails_admin-76cfbf31a605916a55eee29464ca3e6d.js
Uploading: assets/rails_admin/rails_admin-76cfbf31a605916a55eee29464ca3e6d.js.gz
AssetSync: Done.
179.92 real 19.29 user 3.98 sys
I wrote Heroku support over a week ago and after some days they said they'd escalate it to their Ruby buildback team, but I still haven't heard anything. Do any of the smart people on Stack Overflow have possible solutions?
The solution was to use tell Heroku to use Ruby 1.9.3, like my local machine. Apparently 1.9.3 is much faster at assets compilation than 1.9.2 which Heroku defaults to.
To fix it, make sure your Gemfile starts:
source "https://rubygems.org"
ruby "1.9.3"
# ...
More at Heroku docs on Ruby versions.

How can I run rake with --trace within capistrano?

I want capistrano to invoke rake with --trace so I can figure out why it's failing. How do I do this? set :rake 'rake --trace' doesn't work.
The best way I found is:
set :rake, "#{rake} --trace"
This way you don't overwrite the rake variable.
For example if you use bundler this is set before to:
"bundle exec rake"
and after to:
"bundle exec rake --trace"
The chances are your custom tasks aren't using the rake variables, but instead hard-coding rake, here's an example:
run("rake sass:compile")
This is hard-coded, and won't care about your setting set :rake, 'rake --trace', here's the correct way:
run("#{fetch(:rake)} sass:compile")
Or, shorthand:
run("#{rake} sass:compile")
You can see this in practice in the Capistrano source code, in the one place that the default recipes actually invoke rake, in the migrations task: https://github.com/capistrano/capistrano/blob/master/lib/capistrano/recipes/deploy.rb#L387

Resources