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.
1 |
gcloud projects describe $GOOGLE_CLOUD_PROJECT |
if not, do this to switch:
1 |
gcloud config set project $GOOGLE_CLOUD_PROJECT |
Next, create an app engine app in the Cloud:
1 |
gcloud app create |
Now create and source the virtual environment.
1 2 3 4 5 |
virtualenv --python $(which python) venv source venv/bin/activate # you can double check with this which python |
Now install packages
1 |
make install |
Now, run flask locally.
1 |
python main.py |
Finally deploy it
1 |
gcloud app deploy |
To automate deployment, create the cloudbuild.yaml file and push it to main:
1 2 3 4 |
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:
1 2 |
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.