This application shows how to deploy an application to App Engine and integrate with other products such as Firestore, Redis and Cloud Armor.
-
Create a new project and select it
-
Open Cloud Shell and ensure the var is set. Otherwise set it with
gcloud config set project
command
echo $GOOGLE_CLOUD_PROJECT
- Create a bucket to store your project's Terraform state
gsutil mb gs://$GOOGLE_CLOUD_PROJECT-tf-state
- Enable the necessary APIs
gcloud services enable cloudbuild.googleapis.com \
redis.googleapis.com \
vpcaccess.googleapis.com \
compute.googleapis.com firestore.googleapis.com \
cloudresourcemanager.googleapis.com \
appengine.googleapis.com \
servicenetworking.googleapis.com
-
Go to IAM, then add
Editor
andService Networking Admin
roles to the Cloud Build's service account<PROJECT_NUMBER>@cloudbuild.gserviceaccount.com
. -
Clone this repo into the Cloud Shell, then go to the dir.
git clone https://github.com/sylvioneto/phonebook-appengine.git
cd ./phonebook-appengine
- Execute Terraform using Cloud Build
gcloud builds submit ./terraform --config cloudbuild_infra.yaml
- Create an app
gcloud app create --region=southamerica-east1
-
Go to Create a Cloud Firestore and make sure your database is in
Native
mode and located insouthamerica-east1
. -
Go to IAM, then add
Cloud Datastore User
role to<PROJECT_ID>@appspot.gserviceaccount.com
service account. -
Open the
app.yaml
file and replace<REDIS_IP>
by the Redis's IP and<PROJECT_ID>
by your project's ID. -
Deploy the app using Cloud Build
gcloud builds submit ./app --config cloudbuild_app.yaml
- Access your app using the load balancer's IP. This is for testing purposes, for actual applications it is recommended to use DNS and HTTPS.
You can get the LB IP by running the command below or clicking here:
gcloud compute addresses describe appengine-lb-address --global
Execute Terraform using Cloud Build
gcloud builds submit ./terraform --config cloudbuild_destroy.yaml
You can run it locally:
cd ./app
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
export FLASK_ENV=development FLASK_APP=main.py
python -m flask run
Post test
curl -X POST -d @test.json -H "Content-Type: application/json" http://localhost:5000/api/save