negativetwelve / heroku-buildpack-subdir

Deploy apps from subdirectories to Heroku
77 stars 61 forks source link

Problem with Procfile #2

Closed Arrow7000 closed 6 years ago

Arrow7000 commented 7 years ago

Firstly thank you for creating this! I need to deploy an app which is inside a repo's subdirectory (hence this issue).

However I've run into a problem. Even though the stdout of the deploy script seems to say that it has discovered the web process type, the logs then say that there is no web process declared. I don't understand how this is possible.

Deployment stdout

remote: -----> Discovering process types
remote:        Procfile declares types -> web
remote: 

heroku logs --tail

2017-03-29T09:06:27.000000+00:00 app[api]: Build succeeded
2017-03-29T09:08:45.667428+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/" host=autocular.herokuapp.com request_id=ad0e2508-c329-488e-9c33-cfb8100e6db4 f
wd="77.108.147.194" dyno= connect= service= status=503 bytes= protocol=http

Initially I only had a Procfile in the subdirectory, but then the deployment script didn't seem to pick up on it so I created a separate Procfile in the project root, but now it still doesn't seem to work.

Arrow7000 commented 7 years ago

My Procfile in root looks like this:

web: node server/bin/www

And my Procfile in my server/ subfolder I tried both web: node bin/www and web: node server/bin/www. Neither worked. Both had the same error in the logs.

Arrow7000 commented 7 years ago

Silly me :roll_eyes: I must've had the web process dyno turned off, which explains why no web processes were running.

However the app still doesn't run. When I have a Procfile in root I get the error bash: node: command not found. When I remove the Procfile from root and only leave the Procfile in server/, it again doesn't seem to find any web processes.

Where am I supposed to put my Procfiles? And if in my project root, how do I fix the node: command not found error?

negativetwelve commented 7 years ago

Hi @Arrow7000, when you compile your app for deploying, you should be copying the Procfile to the root of the app that you're deploying. If you're deploying from server then your Procfile should exist at server/Procfile so that when you deploy, the Procfile ends up in the root directory.

For starting a node app, it's typical that you have an npm script, then your Procfile will be something like:

web: npm start
negativetwelve commented 7 years ago

let me know if that works for you or not!

Arrow7000 commented 7 years ago

Thanks for replying!

I tried that but now it just says

remote: -----> Discovering process types
remote:        Procfile declares types -> (none)

I think it's looking in the root folder for a Procfile, which is why it's not finding the Procfile in server/. So just to recap:

.buildpacks:

server=https://github.com/heroku/heroku-buildpack-nodejs.git

server/Procfile:

web: npm start
negativetwelve commented 7 years ago

oops, I totally was thinking of a different build system, my bad!

Okay, so to clarify, you should have one Procfile at the root directory that handles running all apps (each in a subdirectory).

Here, you're declaring that server uses node and your Procfile should be set up to run the app from that directory as well. If you have a package.json in the server directory with a script called start, then you would have this in your Procfile:

web: cd server && npm start
negativetwelve commented 7 years ago

Can you provide the contents of the build log? Specifically I'm looking for lines that say:

=====> Downloading Buildpack: 
=====> Detected Framework: 
Arrow7000 commented 7 years ago

It's definitely downloading the right buildpack, it did that from the start:

remote: -----> Multipack app detected
remote: =====> Downloading Buildpack: https://github.com/heroku/heroku-buildpack-nodejs.git, branch: , to tmp dir /tmp/buildpackpjoQ5, against source's subdir: server

I tried putting the Procfile in the root and making it say web: cd server && npm start but that still didn't work. It still can't seem to find node/npm commands:

2017-03-30T08:47:56.665968+00:00 heroku[web.1]: Starting process with command `cd server && npm start`
2017-03-30T08:47:58.612468+00:00 heroku[web.1]: Process exited with status 127
2017-03-30T08:47:58.623075+00:00 heroku[web.1]: State changed from starting to crashed
2017-03-30T08:47:58.624221+00:00 heroku[web.1]: State changed from crashed to starting
2017-03-30T08:47:58.543010+00:00 app[web.1]: bash: npm: command not found
Arrow7000 commented 7 years ago

Let me know if there's anything I can do! If you think this might be a bug I'd be happy to try and create a pull request for it - I'd just need a bit of guidance on where in the source to look.

negativetwelve commented 7 years ago

Hi sorry for the slow response. To be honest, I don't currently use this buildpack :(

All of the code is here: https://github.com/negativetwelve/heroku-buildpack-subdir/blob/master/bin/compile, this is the only file that compiles the app. Let me know what you find!

bpruitt-goddard commented 7 years ago

I am running into the exact same error with a Ruby build and buildpack. Everything is set up the same as your final solution, with the obvious difference being a bash: bundle : command not found instead of not finding npm. To add my findings:

  1. This only occurs when building from a subdirectory. I'm using a boilerplate app that was working fine when at the root of the heroku build. Simply moving it into a subdirectory and updating to this buildpack is causing the error.
  2. However, all of the code in the compile file appears related to building from the buildpacks. The issue doesn't appear to be with the build as I am seeing successful builds - the problem is with the web dyno after the build succeeded. This is seen consistently, even when restarting the web dyno.

I'm not sure what else there is to do here as there is no information about the inner working of the web dynos and nothing here that appears to be the culprit.

Arrow7000 commented 7 years ago

@bpruitt-goddard someone from Heroku opened an issue on the nodejs buildpack repo. It doesn't look like it has been picked up yet though.

Having said that, somebody did comment on it with an ad hoc solution for nodejs projects. I'm not sure what the equivalent of npm --prefix and a package.json is for Ruby projects, but you could potentially find an analogue for Ruby projects using his suggestion.

gablg1 commented 7 years ago

I had the same problem mentioned above so I created the following buildpack based on this one: https://github.com/Pagedraw/heroku-buildpack-select-subdir

It works for us. Let me know if it also works for you!

atomkirk commented 7 years ago

So the problem is that heroku buildpacks install things in .heroku, and then set $PATH to include paths from /app/.heroku. So, if you have a traditional node app, if you heroku run bash and which php, you'll see /app/.heroku/php/bin/php. The other part of the problem is that if I use this buildpack, the same paths dont seem to get added to PATH

The solution is to:

  1. heroku config:set PATH="heroku/php/bin:/app/.heroku/php/sbin:/app/.heroku/php/bin:/app/.heroku/php/sbin:/app/.heroku/php/bin:/app/.heroku/php/sbin:/app/.heroku/php/bin:/usr/local/bin:/usr/bin:/bin:/app/vendor/bin" (or whatever the node buildpack adds to PATH)
  2. in the Procfile, web: ln -sf laravel-api/.heroku && cd laravel-api && vendor/bin/heroku-php-apache2 public/

This adds the paths to your PATH that the normal buildpack would have done, then it symlinks the .heroku directory that got added to your subdirectory to where the PATH is looking for it.

Different 3rd party buildpacks use different stuff. Like I also had to symlink .hex and .platform_tools for my elixir buildpack

works

Photonios commented 6 years ago

@atomkirk It's a bit late, but a recent commit solved this:

https://github.com/negativetwelve/heroku-buildpack-subdir/commit/6313a15ff549265d211896fcd85bed829ef1df0d

@negativetwelve I think this one can be closed now :)