Chapter 85 – Guide to Deploy Web App on Google App Engine

Google Cloud offers many free resources and free quota per month. In this article, I would take Python for the instance and walk through briefly how to deploy web app on Google app engine

Google Cloud offers many free resources and free quota per month. In this article, I would take Python for the instance and walk through briefly how to deploy web app on Google app engine

Table of Contents: Guide to Deploy Web App on Google App Engine

Install Google Cloud CLI in Macbook

First thing first, we need to download the Google Cloud CLI package to the local device, and unzip and save to the web app folder.

Based on your macbook model, please select the appropriate one for the purpose to meet the hardware requirement.

macOS 64-bit (ARM64, Apple M1 silicon)

Subsequently, we need to open macbook terminal and enter this command in the folder you manage the web app files. This command is to install the Google cloud bash and shell in your device.

./google-cloud-sdk/install.sh

Once you complete the installation, you should get the return of a new bash named in /.zshrc. Normally, you use the default shell to implement installation. You can try this command to double check your current bash.

Echo $0

Last but not least, once the Google cloud shell is ready, we need to enter that shell using this command in the web app folder path

Source ~/.zshrc

Structuring and Naming your Web App Files

The flask web app structure and naming are almost same as usual, except for two things.

  • main.py
  • app.yaml

Please be sure to name the main python configuration script as main.py instead of others, like app.py. This is the requirement by Google Cloud app engine.

The other thing is the app.yaml file which aims to tell Google cloud your structure and blueprint of your web app. If you plan to launch SSL of your web app, please add secure as always in the yaml as the sample below:

- url: /.*

script: auto

secure: always

Handling Database

One of the most appealing cutting edge using Google cloud to deploy app allows seamlessly to integrate with Firebase, which can faciliate the database deployment and content personlization. For more details in this section, I would share in another article.

Deploy Web App

First thing first, we need to initiate google cloud in the CLI pannel using this command

gcloud init

Google Cloud would pop up and ask you whether you can authenticate your identity by logging in your Google cloud account. Please enter Y

To continue, you must log in. Would you like to log in (Y/n)? Y

Secondly, we need to select the project in your current Google Cloud. Here is the question from the terminal. Please enter the project ID if you need to specify.

This account has a lot of projects! Listing them all can take a while.

 [1] Enter a project ID

 [2] Create a new project

 [3] List projects

Please enter your numeric choice:

Last but not least, if everything is okay going for after having checked, we can enter this command and all the web app folder and files would be uploaded to Google Cloud.:

gcloud app deploy

When the uploading is done, you can use this command to browse the live version of web app

gcloud app browse

Add Custom Domain

Things are almost done but it’s using the URL given by Google Cloud. We need to connect the app with our custom domain and encript the domain with SSL. luckily Google Cloud provides free SSL.

Go to the Google cloud app engine and setting page. We can select the custom domain section and complete the process by following the instructions. Basically, we need three things to make it done.

  • Google search console to verify the domain ownership. Please be sure to use the same user login credential to login into the search console and verify the domain
  • Configure the domain in DNS using full set of configuration value given by Google cloud
  • Set up secure always in app.yaml as mentioned earlier and codes to redirect the whole site to www. Google App engine doesn’t automatically make it if your DNS doesn’t have this service.

Full Python Script of Deploy Web App on Google App Engine

If you are interested Chapter 85 – Guide to Deploy Web App on Google App Engine, please subscribe to our newsletter by adding the message “Chapter 85”. We will send you the script immediately to your mailbox.

I hope you enjoy reading Chapter 85 – Guide to Deploy Web App on Google App Engine. If you did, please support us by doing one of the things listed below, because it always helps out our channel.