Heroku wrongly detecting my Node app as a Ruby app - ruby

I have a Node project that is using Bundler and Guard to handle my pre-compilations steps.
This means that I have a Gemfile in the root of my project along with the package.json file.
My problem is that Heroku believes that my project is a Ruby app, just because the Gemfile exists. And complains that I have not committed the Gemfile.lock, which I don't want to commit.
-----> Heroku receiving push
-----> Ruby app detected
!
! Gemfile.lock is required. Please run "bundle install" locally
! and commit your Gemfile.lock.
!
! Heroku push rejected, failed to compile Ruby app
Is there a way to tell Heroku that the app is a Node app and not a Ruby app?

The solution to this, with a lot of help from Heroku Support is: use a build pack!
Override the Heroku default buildpacks by specifying a custom buildpack in the BUILDPACK_URL config var
$ heroku config:add BUILDPACK_URL=https://github.com/heroku/heroku-buildpack-nodejs
You can also specify a buildpack during app creation
$ heroku create -s cedar --buildpack https://github.com/heroku/heroku-buildpack-nodejs
Simple when you know it. Some more documentation can be found at Heroku Dev Center

It seems there's a new way to do this as BUILDPACK_URL is now deprecated, explained here, but essentially the command is:
$ heroku buildpacks:set heroku/nodejs
You may also specify a buildpack during app creation:
$ heroku create myapp --buildpack heroku/nodejs

Related

Minimal `Gemfile/Gemfile.lock` for Heroku environment

I’m updating the environment on Heroku and one of the buildpack we use is based on Ruby, which is no longer available by default in the new heroku-22 environment/stack (nor required by our PHP app).
From the docs:
[...] end users should add the Ruby buildpack prior to the buildpack in question (they will also need to ensure minimal Gemfile / Gemfile.lock files exist, so that the Ruby buildpack passes detection).
However I have no clue what those files should include as I have zero experience with Ruby. What would be a valid set of minimal Gemfiles to trigger Ruby installation on Heroku?
I suggest you don't use that buildpack at all. It's ancient, and third-party buildpacks are always a bit questionable, even if it's just because they often stop getting updated.
Here's what it claims to do:
This is a Heroku buildpack for vendoring just the mysql binary from the mysql-client-core deb package.
If you just need a mysql binary, you can use the apt buildpack to install it without worrying about Ruby or anything like that.
Add it as your first buildpack:
heroku buildpacks:add --index 1 heroku-community/apt
Create an Aptfile in the root directory of your project that lists the Ubuntu packages you wish to install, e.g.
mysql-client-core-8.0
Note that the buildpack does not do dependency resolution. If any packages you list have their own dependencies you may have to list them explicitly.
Commit, and redeploy.
You should see the Ubuntu packages you listed get installed before your main buildpack runs.
In any case, if you really want to make your application compatible with the Ruby buildpack you should be able to simply include an empty Gemfile in the root of your project:
The Heroku Ruby Support will be applied to applications only when the application has a Gemfile in the root directory. Even if an application has no gem dependencies it should include an empty Gemfile to document that your app has no gem dependencies.
A Gemfile.lock is not required.
Note that you'll need to manually add the buildpacks you require. I believe you'll want Ruby first, then the MySQL buildpack in your question, then whatever language your application is written in, which appears to be PHP:
heroku buildpacks:set heroku/php # Main buildpack; we insert others before it below
heroku buildpacks:add --index 1 heroku/ruby
heroku buildpacks:add --index 2 https://github.com/thoughtbot/heroku-buildpack-mysql.git
heroku buildpacks
# => Should print the buildpacks in the expected order
Edited
It turns out an empty Gemfile is not enough and a Gemfile.lock is actually required as well.
-----> Building on the Heroku-22 stack
-----> Using buildpacks:
1. heroku/python
2. heroku/ruby
3. https://github.com/thoughtbot/heroku-buildpack-mysql
4. heroku/php
5. heroku/nodejs
-----> Python app detected
-----> Using Python version specified in runtime.txt
-----> Stack has changed from heroku-20 to heroku-22, clearing cache
-----> No change in requirements detected, installing from cache
-----> Installing python-3.10.8
-----> Installing pip 22.2.2, setuptools 63.4.3 and wheel 0.37.1
-----> Installing SQLite3
-----> Installing requirements with pip
Collecting supervisor
Downloading supervisor-4.2.4-py2.py3-none-any.whl (749 kB)
Installing collected packages: supervisor
Successfully installed supervisor-4.2.4
-----> Ruby app detected
grep: /tmp/build_bebc9aa2/Gemfile.lock: No such file or directory
-----> Compiling Ruby/NoLockfile
!
! Gemfile.lock required. Please check it in.
!
! Push rejected, failed to compile Ruby app.
! Push failed
An empty Gemfile will trigger the Ruby installation, however the heroku/ruby package itself does require a lock file.
The buildpack will detect your app as Ruby if it has a Gemfile and Gemfile.lock files in the root directory.
After some trial and error I figure out the following files work:
# Gemfile
source 'https://rubygems.org'
# Gemfile.lock
GEM
remote: https://rubygems.org/
specs:
PLATFORMS
ruby
DEPENDENCIES
BUNDLED WITH
1.17.3

Deploying a sinatra app produced on a mac to Heroku

I have built a simple sinatra web app on my macbook. The deployment to heroku fails with the logs below. The problem is that I've already implemented their suggested fix (bundle lock --add-platform x86_64-linux) and I still get the same error message.
Any suggestions as to next steps would be very welcome. Thanks in advance.
-----> Building on the Heroku-20 stack
-----> Determining which buildpack to use for this app
-----> Ruby app detected
-----> Installing bundler 2.2.33
-----> Removing BUNDLED WITH version in the Gemfile.lock
-----> Compiling Ruby/Rack
-----> Using Ruby version: ruby-2.7.5
-----> Installing dependencies using bundler 2.2.33
Running: BUNDLE_WITHOUT='development:test' BUNDLE_PATH=vendor/bundle BUNDLE_BIN=vendor/bundle/bin BUNDLE_DEPLOYMENT=1 bundle install -j4
Your bundle only supports platforms ["arm64-darwin-20"] but your local platform
is x86_64-linux. Add the current platform to the lockfile with `bundle lock
--add-platform x86_64-linux` and try again.
Bundler Output: Your bundle only supports platforms ["arm64-darwin-20"] but your local platform
is x86_64-linux. Add the current platform to the lockfile with `bundle lock
--add-platform x86_64-linux` and try again.
!
! Failed to install gems via Bundler.
!
! Push rejected, failed to compile Ruby app.
! Push failed
*Update
My local repo, with x86_64-linux in Gemfile.lock, is out of sync with the remote repo on github that I have been trying to deploy from. Other files are out of date too. Concerningly, I have both pushed and pulled recently, as well as deleted the remote repo, created a new one and pushed again. Git is telling me that both the local and the remote repos are up to date with each other, when they are obviously not.
I've tried pushing directly to heroku from the command line but hit the same platform error as above.

Deploying to Heroku without a Gemfile

I'm working with an old Rails app that was initially built before Bundler and Gemfiles. Is it possible to push this app up to Heroku without a Gemfile? The app is in production on the Bamboo Stack and working without one. I'm trying to add a development environment on the Cedar Stack (Bamboo is now closed) and getting an error:
-----> Heroku receiving push
-----> Removing .DS_Store files
! Heroku push rejected, no Cedar-supported app detected
Is it no longer possible to push to Heroku without a Gemfile?
I'll add a Gemfile if that's what it takes.
The official word from Heroku Support:
Hi, yes you need a Gemfile for ruby apps; we don't have any gems
installed on the base system so that's how you specify them. That's
also how we detect it's a ruby app.
Also potentially useful: https://github.com/kch/gemfile-tool

Some heroku commands couldn't find my application

I can find my apps in heroku apps command, and also do some command to read information from app like heroku addons --app appname.
But I couldn't find my apps in some command like heroku addons:add addon_name, heroku pg:reset.
Work commands
heroku apps:
=== My Apps
my_app_1
my_app_2
(Also I can see my apps in heroku web dashboard.)
heroku addons --app my_app_1(not in my_app_1 folder):
=== my_app_1 Configured Add-ons
shared-database:5mb
heroku addons(in my_app_1 folder):
=== my_app_1 Configured Add-ons
shared-database:5mb
Doesn't work commands
heroku addons:add sendgrid(in my_app_1 folder):
! No app specified.
! Run this command from an app folder or specify which app to use with --app
heroku pg:reset DATABASE --confirm my_app_1(in my_app_1 folder):
Resetting SHARED_DATABASE (DATABASE_URL)... failed
! Resource not found
Here is my environment.
Max OS X Lion (10.7.4)
rvm 1.13.8 (stable)
ruby 1.9.3p194
heroku 2.26.5
Adding the heroku's remote configuration to git did the trick for me. Validate if you have it configured with git remote -v on the terminal and you should get something like:
heroku git#heroku.com:your-app.git (fetch)
heroku git#heroku.com:your-app.git (push)
if you don't, add it with
git remote add heroku git#heroku.com:your-app.git
It looks like the latest version fo the Heroku gem (2.26.5) is broken. A workaround is to downgrade to 2.26.3.
gem uninstall heroku -v 2.26.5
gem install heroku -v 2.26.3
It looks like you have a conflict between the Heroku gem, and the Heroku Toolbelt. I'm guessing you have installed the Heroku Toolbelt, but still have the Heroku gem in your gem file.
Remove the Heroku gem from your Gemfile and save.
Run the bundle command to update your Gemfile.lock
In Terminal, run gem uninstall heroku (NOTE: there may be multiple versions of the Heroku gem installed, and you'll need to uninstall all of them.)
In Terminal, run heroku addons
If you get heroku: command not found then you don't have the Heroku Toolbelt installed.
Install the Heroku Toolbelt and run the command again.
NOTE: If you're not in the app's directory, you'll need to add --app myapp1 to the Heroku commands.
Hope this helps.

Can't deploy to Heroku the app with RJB gem

I've set the JAVA_HOME variable
heroku config:add JAVA_HOME=/usr/lib/jvm/java-6-openjdk
checked that heroku config shows this variable with value,
then pushed:
git push heroku master
and still get
JAVA_HOME is not set
error while bundler is installing RJB gem.
I can successfully deploy the same source to another Heroku application, and all environment variables are the same.
What is wrong?
I had the same question, and in case anyone else wants to know, this is what Heroku told me:
By default the config variables aren't made available when the
application is compiled - only at runtime.
You can change this by making sure you have the latest heroku gem
install, then enable the user_env_compile lab flag
$ heroku labs:enable user-env-compile
this will make JAVA_HOME available when the gem installs, hopefully
getting you past this issue.
First find JAVA_HOME PATH by using,
heroku run 'which java |xargs readlink -f | sed "s:bin/java::"'
It will return you,
usr/lib/jvm/java-6-openjdk/jre
Using this now you came know about JAVA_HOME path on heroku. Now set JAVA_HOME path in heroku and in Gemfile
on heroku cli :
heroku config:add JAVA_HOME=/usr/lib/jvm/java-6-openjdk
In Gemfile on top :
java_home = '/usr/lib/jvm/java-6-openjdk'
ENV['JAVA_HOME'] = java_home if Dir.exist?(java_home)
Got Heroku to install gems that depend on $JAVA_HOME by adding the following to my Gemfile:
# set JAVA_HOME so Heroku will install gems that need it
heroku_java_home = '/usr/lib/jvm/java-6-openjdk'
ENV['JAVA_HOME'] = heroku_java_home if Dir.exist?(heroku_java_home)
Have you tried deploying your app to a different stack?
I did a little searching and this seems to fit your explanation.
https://github.com/carlhuda/bundler/issues/1742
probably yours report, isn't it?
I would advice you to contact Heroku and ask them to look into it.
It seems like it's missing dependencies which may, not be available on your current stack.
for migration from heroku cedar-14 to heroku-16 or heroku-18
$ heroku config:unset JAVA_HOME #remove JAVA_HOME env if exists
$ heroku stack:set heroku-18
$ heroku buildpacks:add --index 1 heroku/jvm
$ git push heroku master
To deploy to the heroku-20 stack, make sure you add the following build packs in this order:
heroku buildpacks:add heroku/jvm
heroku buildpacks:add heroku/ruby
You do NOT need to set JAVA_HOME manually with heroku-20. Nor will Heroku set it for you. The variable is already internally available to rjb when it is being installed.
Your final result should look like this:

Resources