Create a Google App Engine application using GCP Cloud Shell environment and Configure Cloud Build to Deploy Changes on build.
-
Create a new project on GCP
-
Create app engine app in cloud shell:
gcloud app create- Clone the hello world sample app repo, and cd into the repo:
git clone https://github.com/GoogleCloudPlatform/python-docs-samples
cd python-docs-samples/appengine/standard_python37/hello_world- create and source the virtual environment:
virtualenv --python $(which python) venv
source venv/bin/activate- install packages:
pip install -r requirement.txt- run flask locally:
python main.py- update main.py
from flask import Flask
from flask import jsonify
app = Flask(__name__)
@app.route('/')
def hello():
"""Return a friendly HTTP greeting."""
return 'Hello I like to make AI Apps'
@app.route('/name/<value>')
def name(value):
val = {"value": value}
return jsonify(val)
if __name__ == '__main__':
app.run(host='127.0.0.1', port=8080, debug=True)- Deploy the flask app:
gcloud app deployit should look like this:
```bash
Setting traffic split for service [default]...done.
Deployed service [default] to [https://helloml-xxx.appspot.com]
You can stream logs from the command line by running:
$ gcloud app logs tail -s default
$ gcloud app browse
(venv) noah_gift@cloudshell:~/python-docs-samples/appengine/standard_python37/hello_world (helloml-242121)$ gcloud app
logs tail -s default
Waiting for new log entries...
```
-
Create a cloud build yaml file:
steps: - name: "gcr.io/cloud-builders/gcloud" args: ["app", "deploy"]
-
Follow steps in this tutorial:
https://cloud.google.com/cloud-build/docs/automating-builds/create-github-app-triggers