I am suffering from the infamous SQLite3 Vs Heroku error while trying to deploy a simple Rails app.
Initially my Gemfile looked like
gem 'sqlite3'
...
After googling on the topic, I updated it to look like this:
group :development, :test do
gem 'sqlite3'
end
...
and then did a bundle install and surprisingly (at least for me),
$ git status --short
M Gemfile
The Gemfile.lock did NOT change!
Now heroku keeps giving this SQLite error again and again because
the Gemfile.lock is same as before and bundle install keeps failing
on their server!
Where am I going wrong?
Damn! It was a git issue.
I was working on a branch named 'deploy' and trying to push the 'master' branch and hence bundle install failed every time!
$git push heroku deploy:master
This made it work :)
Related
I use a gem, my_gem stored on github in an app, my_app. The Gemfile looks like this:
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.7.4'
gem 'rails', '~> 5.2.6'
...
gem 'my_gem', git: "https://#{ENV['PRIVATE_LIB_TOKEN']}:x-oauth-basic#github.com/obromios/my_gem.git", branch: 'master'
About a year ago, I was able to bundle install the app and push to heroku but this no longer works. I reissued an new private access token from Github, giving it access to the repo, and set it in my .env file as follows
PRIVATE_LIB_TOKEN=<token>
When I type bundle install I get the following error message
remote: Repository not found.
fatal: Authentication failed for 'https://github.com/obromios/my_gem.git/'
Retrying `git clone https://x-oauth-basic#github.com/obromios/my_gem.git /Users/my_name/.rvm/gems/ruby-2.7.4/cache/bundler/git/my_gem-<some_other_token> --bare --no-hardlinks --quiet` at /Users/my_name/xyz/my_app due to error (2/4): Bundler::Source::Git::GitCommandError Git error: command `git clone https://x-oauth-basic#github.com/obromios/my_gem.git /Users/my_name/.rvm/gems/ruby-2.7.4/cache/bundler/git/my_gem-<some_other_token> --bare --no-hardlinks --quiet` in directory my_app has failed.
If this error persists you could try removing the cache directory '/Users/my_name/xyz/my_app'
Looking at /Users/my_name/.rvm/gems/ruby-2.7.4/cache/bundler/git/ there was a directory named my_gem-<yet_another_token>. The tokens are all different but are random hashes of similar length. I removed the my_gem-<yet_another_token> directory and this did not help. I also deleted /Users/xyz/my_app and reinstalled the app, but this did not work.
I note that since last time that this worked, I had set up two factor authentication on Github.
How do I fix this?
This is not an answer to the question, but does provide a workaround as suggested by Sachin Sing. This SO answer points out that accessing the gem using a command like
gem 'my_gem', git: "https://#{ENV['PRIVATE_LIB_TOKEN']}:x-oauth-basic#github.com/obromios/my_gem.git"
causes the token to be written to the Gemfile.lock and so appears in the repository. It is suggested a better way is to put the following in the Gemfile
gem 'my_gem', git: "https://github.com/obromios/my_gem.git", branch: 'master'
and then doing the following
export MY_OAUTH_KEY=<token>
bundle config github.com $MY_OAUTH_KEY
This allowed me to bundle install the Gemfile. In order to deploy to heroku, I needed to set the following config variable
heroku config:set BUNDLE_GITHUB__COM=<token>
Then I can just deploy the app to heroku and the gem is installed properly.
I have been having a problem with assert_template in rails. When running rails t it gives me an error message:
NoMethodError: assert_template has been extracted to a gem. To continue using it, add gem 'rails-controller-testing' to your Gemfile.
After adding gem 'rails-controller-testing' to the Gemfile and running bundle install everything worked great.
However, when using a different computer and using git pull to sync the repository it doesn't work. Instead it just shows the same error as above.
Always remember there's two Gemfile files. There's Gemfile, which you edit, and then there's Gemfile.lock. You add something to the Gemfile manually, you then run bundle install, which will lock the version. You edit the Gemfile directly, but the Gemfile.lock is a system managed file that you don't touch. Make sure you commit and push them both after adding a Gem :D
Sometimes you make a gem that is specific to a project. This helps abstract and pull some of the "responsibility" out of the main Rails app and into a more modular place.
The gem would be located here on you application:
gem 'example_gem', path: './example_gem'
You bundle and everything is OK. Now, you git init the gem and store it in its own repo on github. You try doing this to keep it developer friendly:
group :development, :test do
gem 'example_gem', path: './example_gem'
end
group :production do
gem 'example_gem', github: 'company/example_gem'
end
You pat yourself on the back for increasing your workflow, but after running bundle you get:
Your Gemfile lists the gem example_gem (>= 0) more than once.
You should probably keep only one of them.
While it's not a problem now, it could cause errors if you change the version of just one of them later.
You cannot specify the same gem twice coming from different sources.
You specified that example_gem (>= 0) should come from source at ./example_gem and git://github.com/company/example_gem.git
The workflow here is to be able to edit the gem in development and when you're done, commit those changes and push them to Github. BUT, when on development, you don't want to have to do a git commit, git push, and a bundle update on your main app just to see a small change.
Does anyone know of a better way to solve this issue?
Yes, there is a better way: First, have the gem as a git gem in all environments
gem :example_gem, :git => 'git#github.com:foo/example_gem', :branch => :master #you need to set a branch
Then in your app's folder run
bundle config --local local.example_gem /path/to/gem
This will edit .bundle/config to set this option (make sure this file isn't checked into source control!) and tells bundler to get the gem from that path.
At the point when you are going to push your commits you have to be a little bit careful: if your app depends on not yet committed changes to the gem then clearly things will break. In addition as you commit to the repository for the example gem the rails app's Gemfile.lock will get updated. If you push a Gemfile.lock that references a commit that only exists in your copy of the example_gem repo then other users will be stuck.
this works for me.
foo = "https://github.com/me/my-development-version-gem.git"
group :production do
foo = "https://github.com/me/my-production-version-gem.git"
end
gem "foo", :git => foo
in my case i need different branchs for envs to engine
I have a Gem on my local machine that I declare in my Gem file like this:
group :assets do
gem 'my_gem', path: "/Users/me/path/to/my_gem"
end
This works great locally, but when I push to staging on Heroku, the build fails because the gem isn't available.
Currently I'm having to comment/uncomment this gem between deploys which is a real pain.
I've also tried adding it to my development group, but this doesn't help.
Why is Heroku looking for this gem?
Bundler always needs to resolve all of the gems in your Gemfile. You shouldn't commit a Gemfile that contains a local path.
Instead, push your gem to a git repository that is reachable from Heroku and point to that in your Gemfile.
For development, you can use a local path override: http://bundler.io/v1.3/git.html#local
you can try placing the gem in vendor/gems directory, create it if it doesn't exist.then in your Gemfile do like this:
gem 'rails_multisite', path: 'vendor/gems/rails_multisite'
and make sure you run bundle update so Heroku can Pickup the changes
I have run 'heroku db:push' to download heroku db updates, it show me error:
taps load error: no such file to load --sqlite3
you may need to install or update the taps gem to use db commands.
on most systems this will be: sudo gem install taps
I have installed heroku 2.25.0, taps 0.3.24 and I changed the Gemfile replacing gem sqlite3 with:
group :development, :test do
gem 'sqlite3'
end
group :production do
gem 'pg'
end
I think it's a problem of compatibility database between sqlite e postgresql.
is it possible? Or what can be ?
First, make sure you've got your gems all up to date by running bundle install. It won't hurt if everything's fine so you may as well make sure.
After that, you should be able to use db:pull to pull a copy to your local machine using the snippet that follows:
bundle exec heroku db:pull sqlite://local.db --app my_app
If this doesn't work for some reason, you can just change your Gemfile while pulling the database down -- and then you can change it back if you want to.
group :development, :test do
gem 'sqlite3'
# add this next line and run 'bundle install' until you get db:pull to work
gem 'pg'
end
group :production do
gem 'pg'
end
(I believe this will work, though I personally haven't tried it. Please respond if there's an issue.)
Finally, there are some issues pulling and pushing databases if you're running ruby 1.9.3 on your local machine -- but it's only if you're doing a db:push. If you have problems with that here's a link to the solution.
When you run the heroku command, it runs locally on your development machine. So the development group of your Gemfile is used:
group :development, :test do
gem 'sqlite3'
end
Since it contains sqlite3, you need the sqlite3 gem to be installed on your development machine. Have you run bundle install to install this gem locally? And you may need to run the heroku command within a bundle exec call to make sure the gems are loaded:
bundle exec heroku db:pull.
Finally, if you want to download Heroku DB, you should use db:pull, not db:push.