Continuous Delivery with Google App Engine

Create a new Github repo

Create a project in GCP UI

Setup GAE API (just activate), Permissions (go to IAM and add it) and Cloud Build as well

activate cloud-shell and add ssh-keys if not already added to Github: i.e. type ssh-keygen -t rsa than upload key to Github ssh settings

Create an initial project scaffold.
app.yaml, main.py, main_test.py and requirements.txt

Finally, run describe using the gcloud command-line to verify the project is working.

gcloud projects describe $GOOGLE_CLOUD_PROJECT

if not, do this to switch:

gcloud config set project $GOOGLE_CLOUD_PROJECT

Next, create an app engine app in the Cloud:

gcloud app create 

Now create and source the virtual environment.

virtualenv --python $(which python) venv
source venv/bin/activate

# you can double check with this
which python

Now install packages

make install

Now, run flask locally.

python main.py

Finally deploy it

gcloud app deploy

To automate deployment, create the cloudbuild.yaml file and push it to main:

steps:
 -name: "gcr.io/cloud-builders/gcloud"
 args: ["apps", "deploy"]
timeout: "1600s"

The on Google cloud search for ‘cloud build’, enable the following GCP Services in settings:

App Engine
Service Accounts

Then go to triggers, create a new trigger, connect it to the repo and select the ‘push to branch’ event.
Now it will auto deploy on every push, just test it with a commit.

Leave a comment

Your email address will not be published. Required fields are marked *