Deploy H2O Wave application to Heroku? - heroku

I am relatively new to deploying python web applications but I was trying to deploy my H2O wave app to Heroku but kept running into issues and I couldn't find much help in the documentation.
Everything works fine locally if I start the server using the command (in the SDK for wave):
$ ./waved
2021/01/22 10:26:38 #
2021/01/22 10:26:38 # ┌─────────────────────────┐
2021/01/22 10:26:38 # │ ┌ ┌ ┌──┐ ┌ ┌ ┌──┐ │ H2O Wave
2021/01/22 10:26:38 # │ │ ┌──┘ │──│ │ │ └┐ │ 0.11.0 20210118061246
2021/01/22 10:26:38 # │ └─┘ ┘ ┘ └──┘ └─┘ │ © 2020 H2O.ai, Inc.
2021/01/22 10:26:38 # └─────────────────────────┘
2021/01/22 10:26:38 #
2021/01/22 10:26:38 # {"address":":10101","t":"listen","webroot":"/Users/kenjohnson/Documents/TTT/H2O Wave/wave/www"}
2021/01/22 10:26:39 # {"addr":"127.0.0.1:64065","route":"/tennis-pred","t":"ui_add"}
2021/01/22 10:46:04 # {"host":"http://127.0.0.1:8000","route":"/counter","t":"app_add"}
then in the root directory of the project running:
uvicorn tennis_pred_app:main
For deployment, all I have other than my wave python file is a requirements.txt and a Procfile:
web: uvicorn tennis_pred_app:main --host 0.0.0.0 --port 10101
this is what my foo (tennis_pred_app.py) looks like (simplified):
from h2o_wave import Q, main, app, ui
#app("/tennis-pred")
async def serve(q: Q):
show_form(q)
await q.page.save()
The error I am currently running into is:
2021-01-22T00:28:41.000000+00:00 app[api]: Build started by user x
2021-01-22T00:31:07.040695+00:00 heroku[web.1]: State changed from crashed to starting
2021-01-22T00:31:06.879674+00:00 app[api]: Deploy 1dc65130 by user x
2021-01-22T00:31:06.879674+00:00 app[api]: Release v23 created by user x
2021-01-22T00:31:26.580199+00:00 heroku[web.1]: Starting process with command `uvicorn tennis_pred_app:main --host 0.0.0.0 --port 20819`
2021-01-22T00:31:30.299421+00:00 app[web.1]: INFO: Uvicorn running on http://0.0.0.0:20819 (Press CTRL+C to quit)
2021-01-22T00:31:30.299892+00:00 app[web.1]: INFO: Started parent process [4]
2021-01-22T00:31:46.000000+00:00 app[api]: Build succeeded
2021-01-22T00:32:27.041954+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2021-01-22T00:32:27.093099+00:00 heroku[web.1]: Stopping process with SIGKILL
2021-01-22T00:32:27.199933+00:00 heroku[web.1]: Process exited with status 137
2021-01-22T00:32:27.242769+00:00 heroku[web.1]: State changed from starting to crashed

You don't get to choose your port on Heroku. Instead, Heroku assigns you a port via the PORT environment variable.
Change your Procfile from
web: uvicorn foo:main --host 0.0.0.0 --port 10101
to
web: uvicorn foo:main --host 0.0.0.0 --port $PORT

See this blog post for the exact guide.
More explanation for why the other answer is generally correct but does not apply to H2O Wave:
If you look at architecture, you may notice there are actually 2 servers included. The first is a python (uvicorn) one that is used for your Wave app - this is not exposed to the outside directly but uses a kind of a proxy server - the second server. This second (Golang) server communicates directly with a browser (outside) and thus should be started on the $PORT Heroku assigned to you, e.g. via the H2O_WAVE_LISTEN env variable - see other config options.

Related

pm2 stop id command is not working in jenkins pipeline

When try to run pm2 stop command by id is not working in jenkins pipeline(shell script)
pm2 stop 8
When i have run the same command directly in machine its working fine. Try to run in jenkins pipeline its not working, facing error. Could you suggest solution for this. Id details is fine and also i have tried with app name thats also not working
pm2 stop Testing Webhook
Error details:
> Building on master in workspace
> /Jenkins/workspace/Test-Job [Test-Job] $ /bin/sh
> -xe /tmp/jenkins206901532071257719.sh
> + cd /usr/lib/Webhook
> + pm2 stop 8 [PM2] Spawning PM2 daemon with pm2_home=/var/lib/jenkins/.pm2 [PM2] PM2 Successfully daemonized [PM2]
> Applying action stopProcessId on app [8](ids: 8) [PM2][ERROR] Process
> 8 not found
> ┌──────────┬────┬──────┬─────┬────────┬─────────┬────────┬─────┬─────┬──────────┐
> │ App name │ id │ mode │ pid │ status │ restart │ uptime │ cpu │ mem │
> watching │
> └──────────┴────┴──────┴─────┴────────┴─────────┴────────┴─────┴─────┴──────────┘
> Use `pm2 show <id|name>` to get more details about an app Build step
> 'Execute shell' marked build as failure [BFA] Scanning build for known
> causes...
>
> [BFA] No failure causes found [BFA] Done. 0s Finished: FAILURE

Why is the bot on Heroku Server not responding?

I programmed a simple bot that is connected to Google Sheets API. It asks a few questions to the user and stores it in the Sheet I have. When I use bot.polling it works fine, but I was trying the webhook so I could use Heroku to have my bot running 24/7.
I introduced the code:
#server.route('/' + token, methods=['POST'])
def getMessage():
bot.process_new_updates([telebot.types.Update.de_json(request.stream.read().decode("utf-8"))])
return "!", 200
#server.route("/")
def webhook():
bot.remove_webhook()
bot.set_webhook(url = '<Heroku App Link>' + token)
return "!", 200
if __name__ == "__main__":
server.run(host="0.0.0.0", port = int(os.environ.get('PORT', 5000)))
I have the requirements.txt file and the Procfile that currently is like this:
web: python3 bot.py
I tried a bunch of things in the Procfile but this is the only one that didn't gave an error.
When I saw the log this is what I got:
2019-09-24T10:18:54.369238+00:00 heroku[web.1]: State changed from crashed to starting
2019-09-24T10:19:04.416777+00:00 heroku[web.1]: Starting process with command `python3 bot.py`
2019-09-24T10:19:09.868915+00:00 heroku[web.1]: State changed from starting to up
2019-09-24T10:19:09.790773+00:00 app[web.1]: * Serving Flask app "bot" (lazy loading)
2019-09-24T10:19:09.790800+00:00 app[web.1]: * Environment: production
2019-09-24T10:19:09.790853+00:00 app[web.1]: WARNING: This is a development server. Do not use it in a production deployment.
2019-09-24T10:19:09.790940+00:00 app[web.1]: Use a production WSGI server instead.
2019-09-24T10:19:09.790991+00:00 app[web.1]: * Debug mode: off
2019-09-24T10:19:09.799470+00:00 app[web.1]: * Running on http://0.0.0.0:57826/ (Press CTRL+C to quit)
2019-09-24T10:19:15.000000+00:00 app[api]: Build succeeded
Can anyone help me understand why the bot doesn't answer any commands?

Phoenix on Heroku: error R10

Running into an odd error with Phoenix on Heroku, where it doesn't seem to bind to the port properly.
Running into a situation where phoenix is not binding to $PORT. Heroku's log:
2016-03-25T22:22:54.716907+00:00 heroku[web.1]: State changed from crashed to starting
2016-03-25T22:23:03.156662+00:00 heroku[web.1]: Starting process with command mix phoenix.server
2016-03-25T22:23:07.985368+00:00 app[web.1]: [info] Running AppName.Endpoint with Cowboy using http on port 4000
2016-03-25T22:23:10.027386+00:00 app[web.1]: 25 Mar 22:23:10 - info: compiled 5 files into 2 files, copied 3 in 1.5 sec
2016-03-25T22:24:03.442109+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2016-03-25T22:24:03.442109+00:00 heroku[web.1]: Stopping process with SIGKILL
2016-03-25T22:24:04.195291+00:00 heroku[web.1]: Process exited with status 137
2016-03-25T22:24:04.211713+00:00 heroku[web.1]: State changed from starting to crashed
My prod.exs:
config :appname, AppName.Endpoint,
http: [port: {:system, "PORT"}],
url: [scheme: "https", host: "AppName.herokuapp.com", port: 443],
force_ssl: [rewrite_on: [:x_forwarded_proto]],
cache_static_manifest: "priv/static/manifest.json",
secret_key_base: System.get_env("SECRET_KEY_BASE")
It looks like it's going to port 4000 instead of whatever port Heroku wants, and I'm not sure why.
The fix is twofold:
to use the phoenix buildpack config and export the PORT as well, like so: config_vars_to_export=(DATABASE_URL PORT)
Avoid changing the MIX_ENV without recompiling the app, as that behavior is unsupported, as explained here.

Erlang/Webmachine doesn't start on heroku

I've been trying to setup a Webmachine app on Heroku, using the buildpack recommended. My Procfile is
# Procfile
web: sh ./rel/app_name/bin/app_name console
Unfortunately this doesn't start the dyno correctly, it fails with
2015-12-08T16:34:55.349362+00:00 heroku[web.1]: Starting process with command `sh ./rel/app_name/bin/app_name console`
2015-12-08T16:34:57.387620+00:00 app[web.1]: Exec: /app/rel/app_name/erts-7.0/bin/erlexec -boot /app/rel/app_name/releases/1/app_name -mode embedded -config /app/rel/app_name/releases/1/sys.config -args_file /app/rel/app_name/releases/1/vm.args -- console
2015-12-08T16:34:57.387630+00:00 app[web.1]: Root: /app/rel/app_name
2015-12-08T16:35:05.396922+00:00 app[web.1]: 16:35:05.396 [info] Application app_name started on node 'app_name#127.0.0.1'
2015-12-08T16:35:05.388846+00:00 app[web.1]: 16:35:05.387 [info] Application lager started on node 'app_name#127.0.0.1'
2015-12-08T16:35:05.399281+00:00 app[web.1]: Eshell V7.0 (abort with ^G)
2015-12-08T16:35:05.399283+00:00 app[web.1]: (app_name#127.0.0.1)1> *** Terminating erlang ('app_name#127.0.0.1')
2015-12-08T16:35:06.448742+00:00 heroku[web.1]: Process exited with status 0
2015-12-08T16:35:06.441993+00:00 heroku[web.1]: State changed from starting to crashed
But when I run the same command via heroku toolbelt, it starts up with the console.
$ heroku run "./rel/app_name/bin/app_name console"
Running ./rel/app_name/bin/app_name console on tp-api... up, run.4201
Exec: /app/rel/app_name/erts-7.0/bin/erlexec -boot /app/rel/app_name/releases/1/app_name -mode embedded -config /app/rel/app_name/releases/1/sys.config -args_file /app/rel/app_name/releases/1/vm.args -- console
Root: /app/rel/app_name
Erlang/OTP 18 [erts-7.0] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false]
16:38:43.194 [info] Application lager started on node 'app_name#127.0.0.1'
16:38:43.196 [info] Application app_name started on node 'app_name#127.0.0.1'
Eshell V7.0 (abort with ^G)
(app_name#127.0.0.1)1>
Is there way to start the node, maybe as a daemon on the dyno(s)?
Note I've tried to use start instead of console, but that did not yield any success.
So after much tinkering, trial and error, figured out what was wrong. Heroku does not like the interactive shell to be there - hence the crash on starting the Erlang app through console fails.
I've adjusted my Procfile, to the following:
# Procfile
web: erl -pa $PWD/ebin $PWD/deps/*/ebin -noshell -boot start_sasl -s reloader -s app_name -config ./rel/app_name/releases/1/sys
Which boots up the application app_name, using the the release's sys.config configuration file. What was crucial here, is to have the -noshell option in the command, that allows heroku to run the process as they expect it.

Deploying Play 2.0 app on Heroku

So I am kind of new to setting up servers. And I have been struggling with various sql issues all night. I think the only thing that sits between me and a successfully running play app is this: error
Starting process with command `target/start -Dhttp.port=80 `
2012-04-04T05:58:52+00:00 app[web.1]: Play server process ID is 1
2012-04-04T05:58:53+00:00 app[web.1]: [info] play - database [default] connected at jdbc:mysql://us-cdbr-east.cleardb.com/heroku_cd914b667dae168
2012-04-04T05:58:56+00:00 app[web.1]: [info] play - Application started (Prod)
2012-04-04T05:58:56+00:00 app[web.1]: Oops, cannot start the server.
2012-04-04T05:58:56+00:00 app[web.1]: org.jboss.netty.channel.ChannelException: Failed to bind to: /0.0.0.0:80
... more errors
Does anyone spot any problems? Do I need any java options arguments?
I tried specifying a user port in the Procfile, and got a different error message:
2012-04-04T07:01:36+00:00 heroku[web.1]: Starting process with command `target/start -Dhttp.port=2000`
2012-04-04T07:01:37+00:00 app[web.1]: Play server process ID is 1
2012-04-04T07:01:40+00:00 app[web.1]: [info] play - database [default] connected at jdbc:mysql://us-cdbr-east.cleardb.com/heroku_cd914b667dae168
2012-04-04T07:01:45+00:00 app[web.1]: [info] play - Application started (Prod)
2012-04-04T07:01:45+00:00 app[web.1]: [info] play - Listening for HTTP on port 2000...
2012-04-04T07:01:46+00:00 heroku[web.1]: Error R11 (Bad bind) -> Process bound to port 2000, should be 47248 (see environment variable PORT)
2012-04-04T07:01:46+00:00 heroku[web.1]: Stopping process with SIGKILL
2012-04-04T07:01:47+00:00 heroku[web.1]: Process exited with status 137
2012-04-04T07:01:47+00:00 heroku[web.1]: State changed from starting to crashed
I have no idea what is happening. How do I change this environment variable? This heroku process model is very confusing to me.
I think the problem is that you're not allowing Heroku to specify the port. Googling your error I find: https://devcenter.heroku.com/articles/error-codes#r11__bad_bind
So instead of doing this:
web: target/start -Dhttp.port=80
Do this
web: target/start -Dhttp.port=$PORT
James has a nice writeup on getting a more advanced Play 2.0 app deployed here.

Resources