On localhost my app works well even when I run it in production:
rails s -e production
However on heroku it crashes. Previously it worked. I can't find the reason because "heroku logs" doesn't show much it info, it basically says "error". What kind of error? Where exactly?
Here's my gemfile:
ruby '2.2.1'
gem 'rails', '4.2.4'
group :assets do
gem 'sass-rails'
gem 'uglifier'
end
We use LogEntries in Heroku.
They have a really good feature called "Live Tail" - allowing you to see how the server runs in real time. This gives you verbose access to all the errors etc (much better than Heroku logs):
It's totally free and allows you to monitor your dyno in "real time"; it shows the actual Rails errors too.
Related
I do bundle install --without development test before my RoR application working in production because I want to remove gems only used in development or test, but the other day, this caused the problem.
I wrote some code and it works in development, but it contained module provided by the gem, which was installed as development gem's dependence. I used unintentionally so I cannot noticed by deployment failed. So I want to detect it. I'm using CI, so maybe I can notice if I do same bundle install as in production and something rails kicked, but if I do so, CI will take a long time so I don't really want to. I'd love to hear what you think.
edit: I think you haven't got my point yet, so let me explain it again.
for example, my Gemfile is like below;
ruby '2.5.7'
gem 'rails', '5.2.2.1'
gem 'pg', '>= 0.18', '< 2.0'
gem 'puma', '~> 3.11'
...
group :development, :test do
gem 'overcommit'
gem 'rails_best_practices'
gem 'rubocop' # <- this gem also install unicode_display_width(which has `Unicode::DisplayWidth`) as dependency
end
group :development do
gem 'brakeman'
gem 'debase'
gem 'rack-mini-profiler', require: false
gem 'ridgepole'
gem 'ruby-debug-ide', '0.6.0'
...
end
group :test do
gem 'simplecov'
...
end
and I used Unicode::DisplayWidth in my application because I totally thought it was the library ruby originally has(like csv). I don't want to do something like this again, but I may do carelessly, so I want to detect it.
It's not really clear what your problem is from your description. But have a look at bundle list to view installed gems https://bundler.io/man/bundle-list.1.html
Also, try bundle config and if you see any without's that you were not expecting, you can run bundle config --delete without to remove them.
I'm going to try and paraphrase what I think you're asking based on your updated question:
You want your CI pipeline to detect if you used a library in your code that wasn't made available via bundler*, but you don't want to slow your CI pipeline down with another bundle install command.
If that's the case, we have 3 separate pipelines/processes that we use:
CI/CD pipeline on Semaphore to run our automated tests. This pipeline won't catch the type of error described above
Separate pipeline using Heroku's review app feature which builds a "live" application using dummy/seed data, but production-like settings (e.g. bundle install --without development text). This may catch the type of error described above; you may have to use the review app to trigger the error and sometimes we don't
We also have a separate staging environment where user testing occurs, which is also production-like. This is where that type of error should definitely be identified (because we have users test features here by using the site)
This has been a common strategy at a number of projects I've worked on for catching this kind of error before it deploys to production.
* Because bundler in production is run bundle --without development test
I am trying to deploy a Rails project on Heroku. My Rails application uses mysql2.
I have tried using the taps gem but its not working. I get the following error when I run the command taps server mysql://root#localhost/heroku_ex tempuser tempass:
Failed to connect to database: Sequel::AdapterNotFound -> LoadError: cannot load such file -- mysql
Is there any way to deploy my application on Heroku? I would prefer to only use free add-ons if possible.
There are a few moving parts here.
First of all, Heroku doesn't support MySQL by default. If you want to use MySQL instead of PostgreSQL you will have to provision an add-on that provides it. There are currently at least two add-ons that provide MySQL or MariaDB¹ support with a free tier².
Next, Heroku doesn't run database servers on localhost. How can you handle different database configurations between your development machine and your Heroku server?
One strategy that is endorsed by Heroku is to store configuration in the environment. Following this model lets you alter your application's configuration by modifying environment variables instead of editing files. Luckily, Rails appears to override config/database.yml with configuration from the DATABASE_URL variable by default, so this approach should be a good fit.
Very often database add-ons will automatically set an environment variable for you. For example, the JawsDB Maria add-on sets JAWSDB_MARIA_URL when it is provisioned. This isn't the variable that Rails looks for, so you'll either have to tell Rails to look for JAWSDB_MARIA_URL instead of DATABASE_URL or manually set DATABASE_URL to contain the same URL that JawsDB provides in JAWSDB_MARIA_URL.
¹MariaDB is a fork of MySQL that aims to be fully-compatible.
²Note that the free tier may be quite limited, e.g. by only providing 5MB of storage. You may have to upgrade to a paid database tier as you continue to develop your application.
I have solved this by adding the pg gem in production and mysql2 in development environment.
group :development, :test do
gem 'mysql2'
end
group :production do
gem 'listen', '~> 3.0.5'
gem 'pg'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
I'm new to Heroku. I tried pushing a simple test Rails 3.1.1 app to Heroku. The only changes that I made to it from the "new" Rails app template was to create a Home controller and point the root to home#index. I also ran
rails g scaffold Mark type:string start_time:datetime end_time:datetime subject:string measure:float special_event:boolean flag:boolean in_progress:boolean
so that I could run a database migration and test to make sure all showed up properly. The final change that I made was to the Gemfile, which now looks like this:
source 'http://rubygems.org'
gem 'rails', '3.1.1'
group :development do
gem 'sqlite3'
end
group :production do
gem 'pg'
end
group :assets do
gem 'sass-rails', '~> 3.1.4'
gem 'coffee-rails', '~> 3.1.1'
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
I followed the Heroku tutorial for this. The push worked, there were no errors reported. I ran heroku rake db:migrate heroku addons:add logging. I also deleted public/index.html from the app. When I run the app locally with rails server, it works fine. I also can manually navigate to the "marks" index, per the scaffold.
When I run heroku open, all I get is the standard We're sorry, but something went wrong. Rails page. heroku logs shows me nothing at all.
What am I doing wrong here? This is about as simple as test cases get, yet I can't get it to work after fiddling with it for hours, creating new apps, deleting this app and trying again, trying to deploy another app, etc.
The problem here is that Rails 3.1 asset pipeline doesn't work 'out of the box' on Bamboo-mri-1.9.2 which is the default when you do heroku create.
The solution is to do heroku create --stack cedar and then push - all will be fine then :)
Try doing this just to see if this works:
rails new stackoverflow
cd stackoverflow/
git init
git add .
git commit -m 'all'
git remote add origin git#github.com:noahc/stackoverflow.git #you'll need to change this
git push origin master
heroku create
git push heroku master
heroku open
If that doesn't work, then it is something to do with your local machine. I just ran through this and it works on my end. See: http://gentle-dawn-1050.heroku.com. If this doesn't fail, I'd try making the changes to the GemFile and see if you can get it to fail that way.
I had the same problem. Looks like you got to the bottom of your issue, but for future problem-havers I want to point out that it could be a discrepancy between the database you use for your local app and the one behind the live app. In my case, my local database was populated, and my Heroku site was empty, since l I didn't properly migrate.
This problem only became apparent when I ran "rake db:reset" in the terminal, (to clear all the data in my local app's database), after which I was able to easily find the bugs in my code.
Conclusion: if the information in your database is negligible, I would suggest clearing it and troubleshooting from there, because it could be that the site you've deployed just doesn't have data yet, and maybe your code doesn't properly handle that kind of exception.......
i'm trying out the OSS catarse and it works fine on my machine after following the tutorial(see the link).
Then i push it to heroku using
git push heroku master
And it works fine, the problem is when i try to migrate the db using
heroku rake db:migrate
I get
(in /app)
rake aborted!
no such file to load -- capybara/rails
And i'm not sure what should i do, i saw a couple of solutions online, but the people that had this same problem never got an answer on the forums they post.
One of the answers was:
I've moved capybara outside the groups and now rake db:migrate works
just fine, tks!!
I must say this person had a terrible english, i'm not sure what he did, buts thats pretty much all he says.
I thought he meant the Gemfile line
group :test, :development do
Found on the original file, i removed it and the problem remains.
Any other ideas? any help would be appreciated, i'm just starting to learn rails and i'm much willing to learn anything i need to solve this issue so feel free to send me rtfm just tell me which :P
I found that what he meant was moving the line above
group :test, :development do
Just for clarification this is how it looked before
33 group :test, :development do
34 gem 'capybara', ">= 0.4.0"
Those are the line numbers btw and this is after
33 gem 'capybara', ">= 0.4.0"
34 group :test, :development do
Now heroku rake db:migrate works as expected, the app still doesnt work but thats for another question maybe.
If anyone care to explain that would be much appreciated.
I'm following Rails Tutorial, creating a micoroposts app and pushing to Heroku. I'm able to get everything working locally, but the push to Heroku, I get no error messages, but the link myurl.heroku.com/micoroposts gives me the message, "The page you were looking for doesn't exist."
I have successfully added the following to my Gemfile (and run bundle install), per the tutorial advice, but no luck:
gem 'rails', '3.0.3'
'sqlite3-ruby', '1.3.2', :group => :development
Any ideas what might be happening?
You need to put the gem requirements on several lines:
gem 'rails', '3.0.3'
gem 'sqlite-ruby', '1.3.2'
And don't worry too much about the group => development, Heroku takes care of db connections for you.
When you did heroku create it would have told you an application name 'some-name-you-typed-in', so your url would be http://some-name-you-typed-in.heroku.com to see if the application starts.