Reputation: 97
I am currently trying to use google cloud engine to deploy my flask web app and I am not sure how I need to modify the folder structure and some of the file names to match the requirements.
I have a flask app structured like this:
.
├── app
│ ├── errors.py
│ ├── forms.py
│ ├── __init__.py
│ ├── models.py
│ ├── routes.py
│ ├── static
│ │ └── styles.css
│ └── templates
│ ├── 404.html
│ ├── 500.html
│ ├── archive.html
│ ├── base.html
│ ├── bootstrap.html
│ ├── editor.html
│ ├── index.html
│ ├── login.html
│ ├── _post.html
│ ├── post.html
│ └── tag.html
├── app.db
├── app.yaml
├── blog.py
├── config.py
└── requirements.txt
GCE's requirements look like the file structure on this page and include a main.py
file at the top level.
I have blog.py
at the top level which defines the application instance. Does this need to be the main.py
file?
And would I need to modify the app.yaml
file to represent this different file structure?
EDIT: I renamed blog.py
to main.py
and added the following lines to app/__init__.py
:
if __name__ == '__main__':
app.run(host='127.0.0.1', port=8080, debug=True)
But running python main.py
does not make the app available on localhost.
Upvotes: 0
Views: 226
Reputation: 2368
You are on the right track, the documentation should help you with the next steps, which you may or may not have already:
templates/
folder.static/
folder.main.py
file.requirements.txt
file.app.yaml
file. You will need to modify the handler url to to point to the proper directories based on your project file structure. See the documentation for details.To answer your question, this code:
if __name__ == '__main__':
app.run(host='127.0.0.1', port=8080, debug=True)
is used when running locally only. When deploying to Google App Engine, a webserver process such as Gunicorn will serve the app. This can be configured by adding an entrypoint
to app.yaml
.
As the the documentationpoints out, "App Engine will also automatically add the gunicorn to your requirements.txt
file if you don't specify the entrypoint field."
Finally, you will deploy your application to Google App Engine. You will issue the following command from the root directory of your project, where your app.yaml
file is located:
gcloud app deploy
I found a nice image (credits to this article) that depicts an overview of the process:
Upvotes: 1