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=$PORTThe 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.
Go Google Cloud App Engine, and create a new project.
Open Cloud Shell by clicking the Activate Cloud Shell button in the navigation bar in the upper-right corner of the console.
In Cloud Shell, enter the following:
git clone https://github.com/wang0618/pywebio-in-cloud.gitTo deploy your app enter the following:
cd pywebio-in-cloud
gcloud app deploy app.yaml --project pywebio-demoTo view your application in the web browser run:
gcloud app browseThen you will get a link to your app.
NOTE:
- The standard environment of GAE doesn't support websocket, so you need to use
pywebio.platform.tornado_http.start_server()orpywebio.platform.flask.start_server()orpywebio.platform.django.start_server()to start server which communicates with the browser using HTTP protocol. The flexible environment does support websocket, but it has no free quota. For more info, see https://cloud.google.com/appengine/docs/the-appengine-environments - If you just want to use the free quota of GAE and don't want to be charged, go to the Billing page to disable billing
- To delete the project, see https://cloud.google.com/resource-manager/docs/creating-managing-projects#shutting_down_projects
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=$PORTThe 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.
https://dashboard.heroku.com/new-app
https://devcenter.heroku.com/articles/github-integration#automatic-deploys