I cloned one of my own apps using Rails 3.1.3, created an app on Heroku on stack cedar, pushed the to Heroku, and then tried to run
heroku run rake db:migrate and got this error message
No Rakefile found (looking for: rakefile, Rakefile, rakefile.rb, Rakefile.rb)
/usr/local/lib/ruby/1.9.1/rake.rb:2367:in `raw_load_rakefile'
/usr/local/lib/ruby/1.9.1/rake.rb:2007:in `block in load_rakefile'
/usr/local/lib/ruby/1.9.1/rake.rb:2058:in `standard_exception_handling'
/usr/local/lib/ruby/1.9.1/rake.rb:2006:in `load_rakefile'
/usr/local/lib/ruby/1.9.1/rake.rb:1991:in `run'
/usr/local/bin/rake:31:in `<main>
I am in the root of the app when I run rake db:migrate. The app works on localhost.
Any ideas what I might be doing wrong?
The only thing I note that seems odd is that, in the error message, it's referring to ruby/1.9.1/
However, I created the app using rvm with ruby 1.9.2 and when I do ruby -v
ruby -v
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin10.8.0]
My Gemfile
source 'http://rubygems.org'
gem 'rails', '3.1.3'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
group :development, :test do
gem 'sqlite3'
end
group :production do
gem 'pg'
end
group :production do
gem 'thin'
end
gem "heroku"
gem 'omniauth-facebook'
gem 'omniauth'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.1.5'
gem 'coffee-rails', '~> 3.1.1'
gem 'uglifier', '>= 1.0.3'
end
gem "rmagick"
gem "carrierwave"
gem 'fog'
gem 'simple_form'
gem 'devise'
gem 'jquery-rails'
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
# Use unicorn as the web server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'
group :test do
# Pretty printed test output
gem 'turn', '0.8.2', :require => false
end
my gitignore file
# See http://help.github.com/ignore-files/ for more about ignoring files.
#
# If you find yourself ignoring temporary files generated by your text editor
# or operating system, you probably want to add a global ignore instead:
# git config --global core.excludesfile ~/.gitignore_global
# Ignore bundler config
/.bundle
# Ignore the default SQLite database.
/db/*.sqlite3
# Ignore all logfiles and tempfiles.
/log/*.log
/tmp
You have to push to the master branch. From looking at the comments above it looks like you are not doing this.
Therefore, assuming you're developing your application in the master branch, you can deploy with a simple:
git push heroku master
If you're not developing on master deploy with:
git push heroku your_branch_name:master
replacing your_branch_name with the name of the branch you're using.
So i had my staging branch already clone and ready for deployment
I added a remote for heroku app
heroku git:remote -a heroku-webapp-name-here
Then i was trying to do something like this: (and wasnt working)
git push heroku staging
Finally running this worked liked a charm:
git push heroku staging:master
The problem is that if you look in the heroku dashboard you will see that the heroku app is not ruby
Actually your master branch or whicher branch you're pushing did not get pushed to heroku, that's why it says no Rakefile.
Most likely... I think when you created your heroku app with heroku CLI in your terminal and you probably did not indicate which stack of heroku you want to use. See they have several stacks. I think cedar-14, heroku-16, heroku-18 and heroku-20.
So depending on your ruby version. You should find out if the ruby version of your rails app is found in the above heroku stacks. You will need change the stack by doing this in your terminal.
Say for example your ruby version is present in cedar-14. You don't need to delete your app and recreate a new one. You can just change the stack from the heroku cli like this.
heroku stack:set cedar-14
for future apps better specify the heroku stack. For example, like this:
heroku create --stack cedar-14
Then rename your app
heroku rename myapp
Again if Heroku can't find your rakefile is because nothing was pushed to heroku.
Related
I have a rails app that is running on a stand alone server and is using mysql. I would like to create a staging server that is running pg. Currently my Gemfile looks like...
gem 'rails', '3.2.13'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'mysql2'
group :staging do
gem 'therubyracer'
end
group :development, :test do
gem 'sqlite3'
gem 'pg'
end
I'd like to just drop gem 'pg' into the staging group, but how do I designate heroku as staging. So when I push to heroku it knows to grab the pg file from the staging group and not the root of the Gemfile?
The more important thing is your config/database.yml file. You should be able to have both gems installed (unless they have non-compatible dependencies), but specify the postgres adapter and connection settings under the staging environment.
If you only want one of the two gems installed in a given environment then put the mysql2 gem inside a production group, and the pg gem in a staging group.
Having the following issue, BRAND NEW TO RoR, first time ever trying to upload an app to go live, first had hosting issues, then decided if i could fix them with heroku i would just use a custom domain with heroku...... No this isnt a test app "learning rails" thing, actual app i want to deploy for use within the business I own, any help would be great, I have searched and havent seen a solution to this problem.
Make sure 'gem install sqlite3 -v 1.3.7' succeeds before bundling.
Failed to install gems via Bundler
Heroku push rejected, failed to compile Ruby/rails app
To git#heroku.com:peaceful-chamber-6371.git
[remote rejected] master -> master <pre-receive hook declined>
error: failed to push some refs to 'git#heroku.com:peaceful-chamber-6371.git
Gem File
source 'https://rubygems.org'
gem 'rails', '3.2.12'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
group :development, :test do
gem 'sqlite3'
end
group :production do
gem 'pg'
end
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '>= 1.0.3'
gem 'twitter-bootstrap-rails'
end
gem 'jquery-rails'
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
# To use Jbuilder templates for JSON
# gem 'jbuilder'
# Use unicorn as the app server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'debugger'
try this,
remove Gemfile.lock file and do bundle install , then git add, git commit and git push .
Look though the all of the output that Heroku writes to the console -- your error is likely to be there somewhere. I ran into this and found that the precompile step had failed. That can be run locally as well:
rake assets:precompile
Although the question has an accepted answer, the answer did not help me,
I had the same problem. The following worked for me, hence contributing. Heroku does not support sqlite 3. In this case, I had sqlite3 gem in my gemfile, which you are supposed to put in development group, and put postgres gem (which heroku supports) in production group.
1) Delete the gemfile.lock file (from your project folder)
2) In the gemfile, remove gem sqlite3 or similar sqlite3 gem
3) Instead of that add following to the end of file:
group :development, :test do
gem 'sqlite3'
end
gem 'pg', group: :production`
Now, run the following commands in terminal:
bundle install
git add .
git commit
git push
git push heroku master
Although it was a silly mistake, It took me time to realize the same. Hope it helps someone.
Heroku's asset plugins no longer work since Rails 4 does not support plugins. You need to use Heroku's asset gems instead. Place this in your Gemfile:
group :production do
gem 'rails_12factor'
end
Answer found here: Heroku does NOT compile files under assets pipelines in Rails 4 worked for me
My issue was that I had my bower directory ignored in .gitignore.
So I either need to do bower install from my packages.json or check in my bower dir.
http://xseignard.github.io/2013/02/18/use-bower-with-heroku/
I chose to check in my bower dir for a quick solution right now.
Heroku does not like sqlite3, change gem 'sqlite3' with gem 'pg'
For M1 users,
bundle lock --add-platform x86_64-linux
to resolve the architecture conflict
Edit: I'm a new ruby on rails student.
Following my Git Push Heroku Master, I am running into issues with Heroku. Here is the latest and greatest, aborting the rake assets:precompile.
-----> Preparing app for Rails asset pipeline
Running: rake assets:precompile
rake aborted!
could not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port 5432?
Tasks: TOP => environment
(See full trace by running task with --trace)
Precompiling assets failed, enabling runtime asset compilation
Injecting rails31_enable_runtime_asset_compilation
Please see this article for troubleshooting help:
http://devcenter.heroku.com/articles/rails31_heroku_cedar#troubleshooting
Included below are the contents of my Gemfile:
gem 'rails', '3.2.8'
gem 'bootstrap-sass', '2.1'
gem 'pg'
group :development, :test do
gem 'rspec-rails'
gem 'guard-rspec'
gem 'guard-spork'
gem 'spork'
gem 'annotate'
gem 'database_cleaner'
end
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
end
platforms :jruby do
gem 'trinidad'
gem 'jruby-openssl'
end
gem 'jquery-rails'
# Use unicorn as the web server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'ruby-debug'
# Bundle the extra gems:
gem 'RedCloth', '~> 4.2.9', :require => 'redcloth'
gem 'ruby-openid', :require => 'openid'
gem 'rack-openid', :require => 'rack/openid'
gem 'aaronh-chronic', :require => 'chronic' # Fixes for 1.9.2
gem 'coderay'
gem 'lesstile'
gem 'formtastic'
gem 'will_paginate', '~> 3.0.2'
gem 'exception_notification', '~> 2.5.2'
gem 'open_id_authentication'
# Bundle gems for the local environment. Make sure to
# put test-only gems in this group so their generators
# and rake tasks are available in development mode:
group :test do
gem 'database_cleaner'
gem 'cucumber-rails', :require => false
gem 'cucumber-websteps', :require => false
gem 'factory_girl'
gem 'rspec'
gem 'nokogiri', '~> 1.5.0'
gem 'webrat'
end
What might be the issue?
Update: I ran the rake command with --trace, and it had alerted me with a failure because the production database did not exist. I created the database, and ran --trace again, and this is what I'm currently being thrown:
Command failed with status (1): [/usr/local/Cellar/ruby/1.9.3-p286/bin/ruby...]
See the Rails 3.1+ Asset Pipeline on Heroku Cedar article. This exact scenario is covered in the Troubleshooting section.
In short, your Heroku application has a strong separation between building (including asset compilation) and running (where your application becomes available). This is consistent with the 12-factor app principles, but it means that your application cannot access any configured resources during the build phase -- including the database -- meaning ActiveRecord is unavailable during asset precompilation.
You can tell Rails not to bootstrap your application during asset compilation in config/application.rb:
config.assets.initialize_on_precompile = false
The troubleshooting section also recommends:
If rake assets:precompile is still not working, you can debug this locally by configuring a nonexistent database in your local config/database.yml and attempting to run rake assets:precompile. Ideally you should be able to run this command without connecting to the database.
I struggled with exactly the same problem, for hours tonight. After adding
config.assets.initialize_on_precompile = false
to application.rb, remember to do a
git commit
right afterwards. I forgot to do this, and Heroku had no idea I'd changed application.rb. They don't have this extra line on their troubleshooting page.
For Rails 4
Enable Heroku Labs feature to fix this problem
heroku labs:enable user-env-compile
I had this issue with Rails 4 and none of the other suggestions helped. I finally figured it out and it was due to the Rollify gem trying to connect to the database. That has been fixed in the Rollify gem, however, you may need to grab the latest source code to get the fix. I just change my gem import for Rollify to:
gem 'rolify', :git => 'git://github.com/EppO/rolify.git'
That seemed to fix the problem and I haven't had to do any of the other suggestions.
Don't forget to bundle install and commit the change to git.
Also, if that doesn't fix your problem either, you might want to start looking closely at the gems you're using and make sure none of them attempt to connect to the database.
I just started the ruby.railstutorial.org book by Michael Hartl and have been working through the first chapter. I am using mac book OS X, Terminal, and Sublime Text. Everything has gone according to plan, up until it was time to test deployment to Heroku. I am able to connect to Heroku and run the $ git push heroku master command. But the deployment fails:
Installing sqlite3 (1.3.5) with native extensions
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/usr/local/bin/ruby extconf.rb
checking for sqlite3.h... no
sqlite3.h is missing. Try 'port install sqlite3 +universal'
or 'yum install sqlite-devel' and check your shared library search path (the
location where your sqlite3 shared library is located).
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
Provided configuration options:
An error occurred while installing sqlite3 (1.3.5), and Bundler cannot continue.
Make sure that `gem install sqlite3 -v '1.3.5'` succeeds before bundling.
!
! Failed to install gems via Bundler.
!
! Detected sqlite3 gem which is not supported on Heroku.
! http://devcenter.heroku.com/articles/how-do-i-use-sqlite3-for-development
!
! Heroku push rejected, failed to compile Ruby/rails app
Here is my Gemfile
source 'https://rubygems.org'
gem 'rails', '3.2.8'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
group :development, :test do
gem 'sqlite3', '1.3.5'
end
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.5'
gem 'coffee-rails', '~> 3.2.2'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '>= 1.2.3'
end
gem 'jquery-rails', '2.0.2'
group :production do
gem 'pg', '0.12.2'
end
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
# To use Jbuilder templates for JSON
# gem 'jbuilder'
# Use unicorn as the app server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'debugger'
I have sqlite3 designated for development and not production, so I thought Heroku would just ignore it all together, but that does not seem to be the case.
Also, when i create the bundle i am using
$ bundle install --without production
I know that some people has suggested to just install PG and use that, but I really want to stick to the tutorial as much as possible, before I venture out and try a different approach.
I am a bit lost at the moment, and not sure how to proceed from here. Any help that you can provide would be most appreciated.
Thanks
Heroku can't install the sqlite3 gem, for whatever reason. But you can tell bundler that it shouldn't be trying to except when developing.
In your Gemfile, replace gem 'sqlite3' with:
group :development, :test do
gem 'sqlite3'
end
group :production do
gem 'pg'
end
Then bundler on heroku, running as production, won't try to install it.
I was finally able to deploy successfully to Heroku. Thanks to evanc3 for pointing me to an article on the Heroku site. It appears that I simply forgot to commit my Gemgile updates before deploying to Heroku. So for all of you just starting out, you need to make sure you commit your changes before deploying to Heroku.
Heroku do not support sqlite3...
Remove sqlite3 from your Gemfile, use pg gem instead. Do following change in gem file
change following in your Gemfile
gem 'sqlite3'
to
gem 'pg' #you will have to install postgresql
Important: Run
git add .
git commit
git push heroku master
Note: If you are planning to deploy for heroku, I suggest it is better to use postgres in your development phase also(install postgresql in your computer), heroku prefer psql.
If you want to use sqllite for development and postgresql for Heroku, use following config.
group :development do
gem 'sqlite3' #gem to use in development environment
end
group :production do
gem 'pg' #gem to use in production environment
end
Heroku will use pg gem since heroku run your application in production enviroment
On Heroku, your app doesn't have access to the filesystem. There's a number of reasons for this - it's basically due to the fact that you can scale your app's performance by adding new instances (i.e. running multiple servers at once), and these instances aren't guaranteed to be on the same physical machine - copying the files across would be extremely slow.
SQLite just stores the database to a file in your db/ folder, which is why it's incompatible with Heroku.
The best option, as suggested in the help link, is to move away from SQLite, because there are sometimes subtle incompatibilities between SQLite and PostgreSQL (Heroku's database of choice) and you want to find this out before you deploy to production!
After you install PostgreSQL (exactly how to do this depends on your OS) and then add gem 'pg' to your Gemfile.
I have a solution for if you don't have sqlite3 directly in your gemfile and you're still getting this error.
Most likely, you have a gem that uses sqlite3 as a dependency and it's including the gem without you knowing.
1) Go to Gemfile.lock and do a search for sqlite.
2) Locate which gem is using sqlite then move the gem into the development or test group.
3) Bundle
In Rails Tutorial they have you using sqlite3 in development & pg in production. One reason heroku deployment may fail is if your production deployment on heroku still references sqlite in your database.yml rather than postgres.
tldr; your config/database.yml should match the one shown here:
https://github.com/mhartl/sample_app_6th_ed/blob/main/config/database.yml
most importantly your production config lines should match this (so that adapter: postgres rather than adapter: sqlite3):
production:
adapter: postgresql
encoding: unicode
# For details on connection pooling, see Rails configuration guide
# https://guides.rubyonrails.org/configuring.html#database-pooling
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
database: sample_app_production
I've deployed my app to a remote machine using Capistrano and Passenger. The project is on GitHub, and I want to work on some bug fixes on my local machine. I've synced up everything, and branched to a new 'dev' branch on my local machine. When I try the simple rails server command I had been using while developing, I get errors relating to the gems bundled in my Gemfile, e.g. `require': no such file to load -- nokogiri/nokogiri (LoadError). But when I run bundle show nokogiri, it's present at /vendor/cache/ruby/1.9.1/gems/nokogiri-1.5.0.
Maybe this is just the wrong workflow entirely, but how do I get to a development mode on my local machine, so I can test changes before pushing them to the deployed app?
My Gemfile:
source 'http://rubygems.org'
gem 'rails', '3.0.10'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'sqlite3'
# Use unicorn as the web server
# gem 'unicorn'
# Deploy with Capistrano
gem 'capistrano'
# To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
# gem 'ruby-debug'
# gem 'ruby-debug19', :require => 'ruby-debug'
# Bundle the extra gems:
gem 'nokogiri'
# gem 'sqlite3-ruby', :require => 'sqlite3'
gem 'nested_scaffold'
gem 'rest-client'
gem 'pony'
gem 'mail'
gem 'logger'
gem 'json'
gem 'gmail'
# Bundle gems for the local environment. Make sure to
# put test-only gems in this group so their generators
# and rake tasks are available in development mode:
# group :development, :test do
# gem 'webrat'
# end
I suggest you delete .bundle directory (consider backing up whatever's inside .bundle/config first) and run your bundle install command again. You can do cat .bundle/config to echo its contents to your terminal (STDOUT).
Make sure you have chosen the correct gemset by doing rvm gemdir and gem list to see all the gems in the current gemset.
Start your server with rails s -e development (s is short for server)