Skip to content

This project deploys a flask app to Google App Engine(GAE) and configures continuous deployment(CD) with Cloud Build.

Notifications You must be signed in to change notification settings

yueyang0115/flask-app-GCP-deploy

Repository files navigation

flask-app-gcp-deploy

This project deploys a flask app to Google App Engine(GAE) and configures continuous deployment(CD) with Cloud Build.

Reference

Source code: noahgift/gcp-flask-ml-deploy.
Youtube walkthrough: 9min, Continuous Delivery of GCP Google App Engine.
Youtube walkthrough: 27min, Setup Continuous Delivery on GCP Platform with Google App Engine and Cloud Build.
Google documents: Automate App Engine deployments with Cloud Build.

How to use

To deploy this app on GAE and set up continuous deployment, you can follow these steps:

Set up a project

Launch Google Cloud Platform(GCP), create a new project. Change your current project to it and activate Cloud Shell. Create ssh-keys and upload it to Github.

ssh-keygen -t rsa

Create a new repo on github, git clone it to your GCP local and cd into it.
Create all needed files, including app.yaml, Makefile, requirementss.txt, main.py. The app.yaml is part of the IaC (Infrastructure as Code) and configures the PaaS environment for Google App Engine.

Run this app locally

Create a virtual environment and activate it.

python3 -m venv ~/.flask
source ~/.flask/bin/activate

Install the required packages.

make install

Run the application locally.

python main.py

This app will then run locally, and you can preview this app by clicking the preview button on Cloud Shell.

Deploy this app on cloud

(optional) Verfiy the current project is working.

gcloud projects describe $GOOGLE_CLOUD_PROJECT

(optional) Switch your project if it's not what you want.

gcloud config set project $GOOGLE_CLOUD_PROJECT

Create app engine in cloud.

gcloud app create 

When it asks you to choose a region, select one(in my case is 14 us-central).
Type "yes" when it asks whetehr you want to continue.
Deploy this app on cloud.

gcloud app deploy

Then this app will be available on a public url, you can visit the provided url to see it.

Set up continuous deployment

Documents: Automate App Engine deployments with Cloud Build.
Create cloudbuild.yaml file.
Search Cloud Build on GCP console and open it.
Select Trigger and create a new trigger, set repository event to "Push to a branch", connnect your related github repository as the source to watch for events, chosse master branch.
Select "settings", then click on "Cloud Build service account". In the newly open documenation, click on "Open the Cloud Build Settings page". In the new page, enable App Engine and Service accounts.
gcp

Done! See pipeline under Cloud Build

Commit all your changes to github.
And whenever you make a new push, this app will be redeployed automatically. You can see the new build pipeline under Cloud Build.

About

This project deploys a flask app to Google App Engine(GAE) and configures continuous deployment(CD) with Cloud Build.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published