lisawilliams / botpress-test

Other
0 stars 0 forks source link

Deploy bot to Heroku #11

Open lisawilliams opened 6 years ago

lisawilliams commented 6 years ago

Bot is currently running using ngrok, a local webserver that allows incoming connections; but in order to get it into production, we have to host it Out There, so it still works when my laptop is closed ;)

Screencast video showing bot working on localhost with ngrok, connected via Facebook Messenger: https://www.youtube.com/watch?v=H95ptGlmmOI

Start out booting up the ngrok version to make sure it still works, and then attempt to deploy to Heroku using the following directions in the Botpress docs:

https://botpress.io/docs/deploy/heroku.html

lisawilliams commented 6 years ago

I was following the directions to deploy testbot to Heroku, and got to the point where it was time to git push heroku master. Got the following error:

Build failed
remote:  !     Two different lockfiles found: package-lock.json and yarn.lock
Both npm and yarn have created lockfiles for this application,  
but only one can be used to install dependencies. Installing dependencies 
using the wrong package manager can result in missing
packages or subtle bugs in production.
     - To use npm to install your application's dependencies please delete 
the yarn.lock file.
 $ git rm yarn.lock

I removed yarn.lock and ran git push heroku master again and got the same error message. The error message contained the following knowledegebase article:

https://kb.heroku.com/why-is-my-node-js-build-failing-because-of-conflicting-lock-files

It reminded me that Heroku won't push until you've committed all changes, and I hadn't done a commit after removing yarn.lock. Once I did that, I ran git push heroku master, which ran successfully and returned remote: Verifying deploy... done.

lisawilliams commented 6 years ago

Next step in Botpress Heroku docs is to add a Postgres DB to the Heroku app we just spun up. Ran heroku addons:create heroku-postgresql:hobby-dev in the root directory of the project. Ran successfully and returned: Database has been created and is available

lisawilliams commented 6 years ago

Went to next step in Botpress Heroku docs and set up config vars according to instructions here https://botpress.io/docs/deploy/heroku.html.

I now have four config vars that I declared there: BOTPRESS_PASSWORD, DATABASE, DATABASE_URL and MESSENGER_HOST. I still don't really understand if I am supposed to be putting these config vars here in the Heroku dash.

lisawilliams commented 6 years ago

Okay, added the Heroku app web address to Botpress on localhost, but it does not run. Within the Botpress dashboard that I can see at localhost:3000, I get the following error message:

An error occured during communication with Facebook

Details: An error has been returned by Facebook API. Status: 400 (Bad Request) (#2200) 
Callback verification failed with the following errors: HTTP Status Code = 503; 
HTTP Message = Service Unavailable

Looking at the logs for the app on Heroku, I see the following. Note that it's possible to scroll right to see the entire error message from the log:

2017-09-15T04:00:31.725082+00:00 heroku[web.1]: Starting process with command `npm start`
2017-09-15T04:00:33.914313+00:00 app[web.1]: npm ERR! missing script: start
2017-09-15T04:00:33.918678+00:00 app[web.1]: 
2017-09-15T04:00:33.918993+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2017-09-15T04:00:33.919151+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2017-09-15T04_00_33_915Z-debug.log
2017-09-15T04:00:34.015244+00:00 heroku[web.1]: State changed from starting to crashed
2017-09-15T04:00:33.998919+00:00 heroku[web.1]: Process exited with status 1
2017-09-15T04:00:36.891794+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/api/botpress-messenger/webhook?hub.mode=subscribe&hub.challenge=827594144&hub.verify_token=e530d640-a1ea-4308-9841-9192a5cb51b7" host=test-bot-williams.herokuapp.com request_id=55c12a34-0e11-41d0-9155-f7b4a26a275e fwd="69.63.188.220" dyno= connect= service= status=503 bytes= protocol=https
2017-09-15T04:00:40.920170+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/api/botpress-messenger/webhook?hub.mode=subscribe&hub.challenge=195362188&hub.verify_token=e530d640-a1ea-4308-9841-9192a5cb51b7" host=test-bot-williams.herokuapp.com request_id=03d4cc09-d2af-41b4-a2ee-bc509a7c2299 fwd="69.63.188.218" dyno= connect= service= status=503 bytes= protocol=https
2017-09-15T04:03:02.066628+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=test-bot-williams.herokuapp.com request_id=4ca84db6-58ee-4997-bef0-429d6639a384 fwd="146.115.183.152" dyno= connect= service= status=503 bytes= protocol=https
2017-09-15T04:03:02.988659+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=test-bot-williams.herokuapp.com request_id=db97aa51-fde1-45fa-a54a-34e0e09e2761 fwd="146.115.183.152" dyno= connect= service= status=503 bytes= protocol=https
2017-09-15T04:08:14.281176+00:00 heroku[web.1]: State changed from crashed to starting
2017-09-15T04:08:18.811691+00:00 heroku[web.1]: Starting process with command `npm start`
2017-09-15T04:08:22.202770+00:00 app[web.1]: npm ERR! missing script: start
2017-09-15T04:08:22.224847+00:00 app[web.1]: 
2017-09-15T04:08:22.229198+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2017-09-15T04:08:22.229200+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2017-09-15T04_08_22_204Z-debug.log
2017-09-15T04:08:22.339073+00:00 heroku[web.1]: Process exited with status 1
2017-09-15T04:08:22.353092+00:00 heroku[web.1]: State changed from starting to crashed

Not entirely sure what this means. As I think it through, should I no longer be using the localhost:3000 Botpress dashboard? Should I be running bp start via the Heroku console?

lisawilliams commented 6 years ago

Okay, ran heroku run bp start in the root directory of the project, got the following results:

At the command line:

$ heroku run bp start
Running bp start on ⬢ test-bot-wxxxx... up, run.2086 (Free)
bash: bp: command not found

Viewing the logs on heroku.com:

2017-09-15T04:12:37.985352+00:00 heroku[run.2086]: State changed from starting to up
2017-09-15T04:12:37.956593+00:00 heroku[run.2086]: Awaiting client
2017-09-15T04:12:38.008895+00:00 heroku[run.2086]: Starting process with command `bp start`
2017-09-15T04:12:43.584107+00:00 heroku[run.2086]: State changed from up to complete
2017-09-15T04:12:43.569059+00:00 heroku[run.2086]: Process exited with status 127
lisawilliams commented 6 years ago

Added a config var for MESSENGER_HOST in the Heroku dashboard as detailed here: https://botpress.io/docs/deploy/heroku.html, although at this point i'm not sure where to put it -- does this var belong on Heroku or somewhere else?

lisawilliams commented 6 years ago

bp start does not appear to work on the Heroku console -- it returns bash: bp: command not found.

lisawilliams commented 6 years ago

Note to self that the node version I have does not match those in the botpress deploy docs. I'm a little afraid to change it and break the local version.

lisawilliams commented 6 years ago

Left a help request in the Botpress community Slack channel: https://botpress-community.slack.com/archives/C4DQAFG8N/p1505494324000088

lisawilliams commented 6 years ago

This issue may have a helpful suggestion about environment variables: https://github.com/botpress/botpress-messenger/issues/33.

Okay, I see the config.yaml for botpress-messenger, but I'm confused -- do I set the varables only there, or do I create an .ENV file?

lisawilliams commented 6 years ago

One of the maintainers of the project, reached out to me and pointed out that I was supposed to cd into a new directory outside the Botpress directory and run bp init in that directory. I started a new repo and I am trying it one more time. I've gotten it to the point where it runs on localhost, and now I'm going to try to deploy to Heroku.

New repo: https://github.com/lisawilliams/trollbustersbot

slvn commented 6 years ago

@lisawilliams wrong guy.

lisawilliams commented 6 years ago

Apologies!