heroku / heroku-buildpack-multi-procfile

Everyone gets a Procfile!
2 stars 1 forks source link

Usage example #3

Closed saniko closed 5 years ago

saniko commented 6 years ago

Hello, Could you please explain the following step: "For each app, set PROCFILE=relative/path/to/Procfile/in/your/codebase, and of course: heroku buildpacks:add -a https://github.com/heroku/heroku-buildpack-multi-procfile"

I have 2 procfiles, one is in the root and another is under the backend folder. procfile1 = web: npm run build procfile2 = api: node backend/server

What exactly does in mean "For each app, set PROCFILE=relative/path/to/Procfile/in/your/codebase" What needs to be done here?

Thanks

apghero commented 6 years ago

Hi @saniko,

The idea here is that you have a single git repository, but multiple Heroku apps. So, for each app you need this buildpack, and for each app, you need to set a config variable named PROCFILE to the location where the procfile is for that app. As an example:

$ heroku create -a example-1
$ heroku create -a example-2
$ heroku buildpacks:add -a example-1 https://github.com/heroku/heroku-buildpack-multi-procfile
$ heroku buildpacks:add -a example-2 https://github.com/heroku/heroku-buildpack-multi-procfile
$ heroku config:set -a example-1 PROCFILE=Procfile
$ heroku config:set -a example-2 PROCFILE=backend/Procfile
$ git push https://git.heroku.com/example-1 HEAD:master
$ git push https://git.heroku.com/example-2 HEAD:master

When example-1 builds, it'll copy Procfile into /app/Procfile, and when example-2 builds, it'll copy backend/Procfile to /app/Procfile. For example-2, the process types available for you to scale up will be the ones referenced (originally) in backend/Procfile, or, based on your example api: node backend/server.

HOWEVER, in looking at what procfile1 and procfile2 look like from your example above, I'm not sure how you're hoping this will work. The api entry in procfile2 won't receive HTTP requests because it's not called web (See Dev Center. If you have two separate apps, example-1, and example-2, then:

$ cat Procfile
web: npm run build
$ cat backend/Procfile
web: node backend/server

Is probably closer to what you want, I'd think. However, I'm both not familiar with node, and not exactly sure what your intentions are.

Good luck!

saniko commented 6 years ago

Thanks Andrew for helping! I do have 2 different apps in my project, the "backend" and the root project (client).

I have followed instructions and see all 3 apps on Heroku UI, my original app and the 2 new ones..

Do I run the "git push heroku master" after all of the above configurations? Or do I need to do anything else?

What is the sequence of running things? I don't seem to be able to start my server.

Thanks

apghero commented 6 years ago

Hi @saniko,

This isn't an officially supported buildpack, and the comments here aren't the best support forum. I'd urge you to check out Dev Center and see if some of the articles on deploying your app and buildpacks will help you better understand the fundamentals of running apps on Heroku, and resolve your questions.

loganknecht commented 5 years ago

Just chiming in here @apghero.

The comment you made above is what got me going with this buildpack, the README.md left me confused. Is it possible to update the README with that information for the Procfile step?

I really love this buildpack! Thank you for going out of your way and making this! It's really letting me give this monorepo effort a legitimate shot!

apghero commented 5 years ago

@loganknecht Of course it's possible! I'll take a look at doing that right now. Thanks for the suggestion!

loganknecht commented 5 years ago

Hey @apghero! I realize I'm reaching out so soon, but I'm continuing along with the multi-procfile setup, but it doesn't seem to be recognizing that this is a python configuration?

I have a file directory like this:

repository_root
├── README.md
├── deploy_heroku.sh
├── test_api
│   ├── Makefile
│   ├── Procfile
│   ├── api
│   │   ├── ...
│   ├── cd
│   │   └── run_cd.sh
│   ├── db.sqlite3
│   ├── dev-requirements.txt
│   ├── manage.py
│   ├── test_api
│   │   ├── __init__.py
│   │   ├── settings.py
│   │   ├── urls.py
│   │   ├── wsgi.py
│   ├── pytest.ini
│   ├── requirements.txt

In the repository_root I have a script called deploy_heroku.sh.

The script is basically the exact same code that is listed above in this thread.

HEROKU_DYNO_NAME="test-api-production"
GIT_REMOTE_BRANCH_NAME="heroku-test-api-production"

git remote --verbose

git remote rm $GIT_REMOTE_BRANCH_NAME
heroku apps:destroy $HEROKU_DYNO_NAME --confirm=$HEROKU_DYNO_NAME

heroku create $HEROKU_DYNO_NAME --remote $GIT_REMOTE_BRANCH_NAME
heroku buildpacks:add --app $HEROKU_DYNO_NAME https://github.com/heroku/heroku-buildpack-multi-procfile
heroku config:set --app $HEROKU_DYNO_NAME PROCFILE=test_api/Procfile
git push $GIT_REMOTE_BRANCH_NAME master

However, when I run it I get this as output

╰─$ sh deploy_heroku.sh
heroku-test-api-production https://git.heroku.com/test-api-production.git (fetch)
heroku-test-api-production https://git.heroku.com/test-api-production.git (push)
origin  https://gitlab.com/Hugbot/music_gym.git (fetch)
origin  https://gitlab.com/Hugbot/music_gym.git (push)
Destroying ⬢ test-api-production (including all add-ons)... done
Creating ⬢ test-api-production... done
https://test-api-production.herokuapp.com/ | https://git.heroku.com/test-api-production.git
Buildpack added. Next release on test-api-production will use https://github.com/heroku/heroku-buildpack-multi-procfile.
Run git push heroku master to create a new release using this buildpack.
Setting PROCFILE and restarting ⬢ test-api-production... done, v3
PROCFILE: test_api/Procfile
Enumerating objects: 1390, done.
Counting objects: 100% (1390/1390), done.
Delta compression using up to 4 threads
Compressing objects: 100% (484/484), done.
Writing objects: 100% (1390/1390), 362.51 KiB | 19.08 MiB/s, done.
Total 1390 (delta 885), reused 1361 (delta 870)
remote: Compressing source files... done.
remote: Building source:
remote: 
remote: -----> Multi-procfile app detected
remote: cp: cannot stat '/tmp/build_b7ccacedcc5b10397f1c372bf26fd820/test_api/Procfile': No such file or directory
remote:       Copied test_api/Procfile as Procfile successfully
remote: -----> Discovering process types
remote:        Procfile declares types -> (none)
remote: 
remote: -----> Compressing...
remote:        Done: 213.8K
remote: -----> Launching...
remote:        Released v4
remote:        https://test-api-production.herokuapp.com/ deployed to Heroku
remote: 
remote: Verifying deploy... done.
To https://git.heroku.com/test-api-production.git
 * [new branch]      master -> master

The key piece is the part

remote: cp: cannot stat '/tmp/build_b7ccacedcc5b10397f1c372bf26fd820/test_api/Procfile': No such file or directory
remote:       Copied test_api/Procfile as Procfile successfully
remote: -----> Discovering process types
remote:        Procfile declares types -> (none)

This is successfully provisioning a dyno, but in doing so it doesn't seem to recognize the Procfile in my test_api sub-directory?

The contents of the Procfile are very basic. They execute the make command to build dependencies and run gunicorn pointing to my Django app.

web: make run_production

If I run heroku local in the test_api directory I can deploy this successfully.

Am I misunderstanding how the mutli-procfile build pack is supposed to be used?

apghero commented 5 years ago

Where is the .git directory? Is it in the same directory as deploy_heroku.sh, the labeled "repository_root"?

Also, this deploy_heroku.sh script makes me ask a lot of questions about what you're doing, likely unrelated to the issue:

HEROKU_DYNO_NAME="test-api-production"
GIT_REMOTE_BRANCH_NAME="heroku-test-api-production"

You're creating an "app." A "dyno" is an deployment of your app's code that runs a process (e.g. from the Procfile like web)

heroku apps:destroy $HEROKU_DYNO_NAME --confirm=$HEROKU_DYNO_NAME
heroku create $HEROKU_DYNO_NAME --remote $GIT_REMOTE_BRANCH_NAME

There's generally no need to delete and then recreate an app like this. You can "just" git push ${GIT_REMOTE_BRANCH_NAME} master. I think you're setting up a new git remote because you want to push this code somewhere else too, but generally speaking, you'd not set a --remote on the heroku create command and let it default to heroku.

I'm not positive about this, but you may also need to add the heroku/python buildpack for your example here to work. That really shouldn't be the cause of the failed stat that we see in the output of the cp command though.

I'll have to do some more thinking about this...

loganknecht commented 5 years ago

@apghero Thank you for the response! I'm still very new to Heroku, so I think my mental model still needs some support.

I ended up choosing to go down the route of using docker and a heroku.yml file in the root directory in order to provision and deploy my environment. I used this article.

Again, thank you for taking the time to respond. Cheers!

apghero commented 5 years ago

@loganknecht awesome! Glad to have you as a customer!