heroku-buildpack-subdir
heroku-buildpack-subdir copied to clipboard
Issues with missing bundler during multiple buildpack deploy of Rails app from subdir
Hi there,
Thanks for this plugin first of all! I'm running into an issue on startup where it appears that my app can't find bundler. I'm using your buildpack as primary buildpack and then using a .buildpacks
file:
https://github.com/heroku/heroku-buildpack-nodejs.git
clive-api=https://github.com/heroku/heroku-buildpack-ruby.git
along with a Procfile
in the root of my project (not in clive-api directory):
web: cd clive-api && bundle exec bin/rails s -p $PORT -e $RAILS_ENV
console: cd clive-api && bundle exec bin/rails console
It fails on bootup:
2018-02-28T19:31:23.000000+00:00 app[api]: - Build succeeded
2018-02-28T19:32:14.690045+00:00 heroku[web.1]: - Starting process with command `cd clive-api && bundle exec bin/rails s -p 58217 -e production`
2018-02-28T19:32:16.871818+00:00 heroku[web.1]: - State changed from starting to crashed
2018-02-28T19:32:16.815476+00:00 heroku[web.1]: - Process exited with status 1
2018-02-28T19:32:16.754970+00:00 app[web.1]: - /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- bundler (LoadError)
2018-02-28T19:32:16.754989+00:00 app[web.1]: - from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
2018-02-28T19:32:16.754991+00:00 app[web.1]: - from /app/clive-api/bin/spring:8:in `<top (required)>'
2018-02-28T19:32:16.754994+00:00 app[web.1]: - from bin/rails:3:in `<main>'
2018-02-28T19:32:16.754993+00:00 app[web.1]: - from bin/rails:3:in `load'
and looks like it can't find bundler
which is very weird b/c I thought installing/managing bundler was handled by Heroku itself.
I see two issues here:
- Using
/usr/lib/ruby/2.3.0
despite my Gemfile specifying:ruby "2.4.3"
- Missing bundler
I'm realizing this might not be an issue with your buildpack but rather with Heroku itself but figured I'd ask.
Thanks in advance!
Hi @bradical, in the logs for deploying to heroku, are you seeing the part where it installs gems? Given that it properly identifies this as a ruby buildpack, you should be seeing that. If not, we are hopefully closer to figuring out what's wrong 😄
are you seeing the part where it installs gems?
Yep, definitely seeing it install gems. And my understanding was that bundler was managed by Heroku anyway which makes it very weird. Best I can tell it's an issue with the $PATH
being set after it does the Ruby build from within my subdirectory clive-api
. I should note that this is the newer heroku-16 stack too.
hey @bradical I found out that default path for a regular ruby app is /app/vendor/bundle/ruby/2.5.0/bin/bundler
and "nested" buildpack call puts it into
/app/<subdir>/vendor/bundle/ruby/2.5.0/bin/bundler
while PATH is
/app/vendor/bundle/ruby/2.5.0/bin/bundler
and all gems are misplaced.
When I added 3rd Gemfile and put it into root folder and added 2nd buildpack:
heroku buildpacks:add --index 2 https://github.com/heroku/heroku-buildpack-ruby.git
my web dyno started but obviously used another set of gems.
My ultimate goal is to use 2 incompatible Gemfiles so I fixed Procfile as follows:
web: export PATH=/app/app1/bin:/app/app1/vendor/bundle/bin:/app/app1/vendor/bundle/ruby/2.5.0/bin:/usr/local/bin:/usr/bin:/bin HOME=/app/app1 GEM_PATH=/app/app1/vendor/bundle/ruby/2.5.0; cd app1 && bundle exec rackup config.ru -p $PORT
web2: export PATH=/app/app2/bin:/app/app2/vendor/bundle/bin:/app/app2/vendor/bundle/ruby/2.5.0/bin:/usr/local/bin:/usr/bin:/bin HOME=/app/app2 GEM_PATH=/app/app2/vendor/bundle/ruby/2.5.0; cd app2 && bundle exec rackup config.ru
hope this helps!
I'm also running into this issue and think this might be a problem with the $PATH. I have multiple node apps and when I deploy to one, dependencies install, it builds the app, everything seems good. And then it runs web: cd <subdir> && yarn start
bash: yarn: command not found
, same if I use npm (bash: npm: command not found
). I'm really not sure how to fix the path here. I would love some help!
Hi, @negativetwelve, thanks for this buildpack! I'm having the same problem as @bradical, has anyone found a solution for this? Thanks!
The Ruby buildpack would produce following <subdir>/.profile.d/ruby.sh
:
export LANG=${LANG:-en_US.UTF-8}
export GEM_PATH="$HOME/vendor/bundle/ruby/2.7.0:$GEM_PATH"
export PATH="$HOME/vendor/yarn-v1.22.4/bin/:$HOME/bin:$HOME/vendor/bundle/bin:$HOME/vendor/bundle/ruby/2.7.0/bin:$PATH"
export DISABLE_SPRING="1"
export MALLOC_ARENA_MAX=${MALLOC_ARENA_MAX:-2}
export BUNDLE_PATH=${BUNDLE_PATH:-vendor/bundle}
export BUNDLE_WITHOUT=${BUNDLE_WITHOUT:-development:test}
export BUNDLE_BIN=${BUNDLE_BIN:-vendor/bundle/bin}
export BUNDLE_DEPLOYMENT=${BUNDLE_DEPLOYMENT:-1}
export RAILS_ENV=${RAILS_ENV:-production}
export RACK_ENV=${RACK_ENV:-production}
export SECRET_KEY_BASE=${SECRET_KEY_BASE:-redacted}
export RAILS_SERVE_STATIC_FILES=${RAILS_SERVE_STATIC_FILES:-enabled}
export RAILS_LOG_TO_STDOUT=${RAILS_LOG_TO_STDOUT:-enabled}
Pay attention to GEM_PATH
and PATH
:
export GEM_PATH="$HOME/vendor/bundle/ruby/2.7.0:$GEM_PATH"
export PATH="$HOME/vendor/yarn-v1.22.4/bin/:$HOME/bin:$HOME/vendor/bundle/bin:$HOME/vendor/bundle/ruby/2.7.0/bin:$PATH"
That script is later moved from $HOME
:
https://github.com/negativetwelve/heroku-buildpack-subdir/blob/ee6a2e7f94b644cadd0725c21ab02879a25d5c53/bin/compile#L82-L86
The path to the application in sudirectory is actually $HOME/<subdir>
rather than just $HOME
. You need to have this fixed in order to run installed Ruby version (instead of system one), run correct binstubs and to have bundler find its vendored gems.
One way of doing this is here: https://github.com/arkency/heroku-buildpack-ruby-monorepo/blob/7adc4442fba55b1cc8a7b281ab276ea1fc7b3410/lib/copy_profile_d.sh#L3-L17