/pywebio-in-cloud

Deploy PyWebIO applications in cloud platforms.

Primary LanguagePython

Deploy your PyWebIO app to cloud platform

GAE

Config your app

First, configure all dependencies you will need for your web service in your requirements.txt file.

To deploy your web service to App Engine, you need an app.yaml file. This configuration file defines your web service's settings for Google App Engine.

In general, the configuration you need is as follows:

runtime: python39
entrypoint: python3 app.py --port=$PORT

The entrypoint field specifics how to start your app. You need replace app.py with your start script, and your app should listen on the port specified by the PORT environment variable.

Create GAE project

Go Google Cloud App Engine, and create a new project.

Open Cloud Shell

Open Cloud Shell by clicking the Activate Cloud Shell button in the navigation bar in the upper-right corner of the console.

Get app code

In Cloud Shell, enter the following:

git clone https://github.com/wang0618/pywebio-in-cloud.git

Deploying with Cloud Shell

To deploy your app enter the following:

cd pywebio-in-cloud
gcloud app deploy app.yaml --project pywebio-demo

Visit your app

To view your application in the web browser run:

gcloud app browse

Then you will get a link to your app.

NOTE:

Heroku

Config your app

Like GAE, you need configure all dependencies for your web service in your requirements.txt file.

To deploy your web service to Heroku, you need a Procfile file. This configuration file defines your web service's settings for Heroku.

In general, the configuration you need is as follows:

web: python app.py --port=$PORT

The Procfile file specifics how to start your app. You need replace app.py with your start script, and your app should listen on the port specified by the PORT environment variable.

Note: Heroku does support websocket, but it will close idle connections (i.e., if no data is sent in 55 seconds then the connection is terminated). You need to provide websocket_ping_interval parameter in start_server() (e.g., start_server(main, port=8080, websocket_ping_interval=30)) to prevent the connection from idling by sending ping packet periodically over the connection.

Create Heroku project

https://dashboard.heroku.com/new-app

Connect to GitHub and deploy app

https://devcenter.heroku.com/articles/github-integration#automatic-deploys