Thanks to visit codestin.com
Credit goes to github.com

Skip to content

yilun306/helloml

Repository files navigation

Continuous Delivery of Flask Application on GCP

Create a Google App Engine application using GCP Cloud Shell environment and Configure Cloud Build to Deploy Changes on build.

Deploy Flask App on GCP

  1. Create a new project on GCP

  2. Create app engine app in cloud shell:

gcloud app create
  1. 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
  1. create and source the virtual environment:
virtualenv --python $(which python) venv
source venv/bin/activate
  1. install packages:
pip install -r requirement.txt
  1. run flask locally:
python main.py
  1. 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)
  1. Deploy the flask app:
gcloud app deploy
it 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...
```

Continuous delivery setup

  1. Create a cloud build yaml file:

    steps:
    - name: "gcr.io/cloud-builders/gcloud"
      args: ["app", "deploy"]
  2. Follow steps in this tutorial:

    https://cloud.google.com/cloud-build/docs/automating-builds/create-github-app-triggers

About

This is step by step demo on how to deploy a Flask Application on Google Cloud Platform

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published