1

I'm new to GCP, we had chosen sanic framework to make things run smoother. Sanic supports python 3.5+ so we are going with flexible environment on appengine.

Currently I'm trying to deploy "Sanic" Hello world (Get started) application to appengine. and stuck config. problem at

# This looks like a Python app.  If so, please enter the command to run 
the app in production (enter nothing if it's not a python app): :

I had looked into other Google Cloud Platform (Python docs samples) examples which are available on GitHub all were using gunicorn but sanic has builtin http server.

Can someone suggest app.yaml model for sanic on appengine. my current setup follows as

1. app.yaml

    runtime: python
env: flex
threadsafe: true

runtime_config:
  python_version: 3

handlers:
- url: .*  # This regex directs all routes to main.app
  script: main.app

2. main.py

#import logging
from sanic import Sanic
from sanic.response import json

app = Sanic()

@app.route("/")
async def test(request):
    return json({"hello": "world"})

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=8000)

3. requirements.txt

httptools
sanic
ujson
uvloop

UPDATE.

added entrypoint: python main.py to app.yaml fixed my deploy problem but appengine throughs error.

Error: Server Error
The server encountered a temporary error and could not complete your request. Please try again in 30 seconds.

Thanks in advance. and if you cant solve my problem don't down vote.

cutiehulk2329
  • 151
  • 1
  • 8
  • The "temporary error" message usually means that the instances are still deploying. Have you checked in the [Cloud Console](https://console.cloud.google.com/) under "Compute Engine" to see the state of the Flexible Environment host VMs? – Nick Apr 28 '17 at 20:04
  • @Nick I had verified that instances are spinning and up.... Any other suggestions? – cutiehulk2329 May 07 '17 at 17:37
  • Are you exposing port 8000? The default is port 8080, so it's possible that's the only issue. – Nick May 10 '17 at 18:59
  • @cutiehulk2329 Were you able to find the solution to your question? If so it is recommended that you post it as the answer to help the community. If not, you can provide the additional information requested by Nick to further the investigation. – Jordan May 29 '17 at 19:13

3 Answers3

3

To be exact here is the appengine app.yaml entrypoint model:

entrypoint: gunicorn <main:app> --bind 0.0.0.0:8080 --worker-class sanic.worker.GunicornWorker

You need to make sure to install gunicorn pip packages. Currently Appengine supports gunicorn version 19.7.1.

cutiehulk2329
  • 151
  • 1
  • 8
  • Worked for me, but without <>. gunicorn main:app --bind 0.0.0.0:8080 --worker-class sanic.worker.GunicornWorker – enf644 Mar 15 '19 at 14:05
  • "If you do not specify entrypoint for the Python 3 runtime, App Engine configures and starts the Gunicorn webserver." – jonincanada Dec 30 '22 at 12:31
0

I am not sure if the following is helpful.

I had the same problem. Solved by:

  1. adding entrypoint: gunicorn -b :$PORT main:app to my app.yaml file.
  2. adding "gunicorn==19.7.1" to my requirements.txt file.
peterh
  • 4,953
  • 13
  • 30
  • 44
0

Just change the main to be like this:

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=os.environ.get('PORT',8080))

and the app.yaml entrypoint to:

entrypoint: python main.py

It should work.

Update:

For me it works. I just change what I wrote above, and deploy the new version to GAE-Flex.