App Engine vs. Cloud Run: Part 2 - How To Deploy And Host Your Apps On The Cloud

App Engine vs. Cloud Run: Part 2 - How To Deploy And Host Your Apps On The Cloud

In our last blog post, I introduced and discussed App Engine and Cloud Run. In this blog post, which is Part 2 of the three-part blog series, I will explain how to deploy and host your apps on the Google Cloud Platform, i.e., App Engine and Cloud Run, and how to overcome the challenges in the process.

Table of contents

Challenges and solutions for deploying and hosting apps

To understand the challenges of deploying and hosting apps and how to overcome them, I created and deployed a new project. I resolved all the challenges that I faced (which you may face too) when I used Google Cloud Platform (GCP) for the first time. So read on further, follow along, type the commands, and perform the operations as I have illustrated.
I deployed and hosted the project using the Google Cloud Command Line Interface. If you don’t have it in your system, you can download it using this link: gcloud CLI
Launch the installer, follow the prompts, and complete the installation with the default configurations. After successful installation, the Google Cloud CLI shell will open up.

Google Cloud Platform-App Engine-Cloud Run
Now, if you have chosen all the default options during installation, you will be asked to login to your Google Cloud Platform account. Enter ‘Y’ to login using your Gmail account and start a project. If you are not prompted to login, enter the command:

text
gcloud init

Google Cloud Platform-App Engine-Cloud Run
Whenever there is an error in creating a project, you can restart the whole process using the “gcloud init” command.
After logging in, messages will be displayed asking you if you want to create a project. Type ‘Y’ and you will be asked to enter a project ID. Create a project using the following command:

text
gcloud projects create <PROJECT_ID>

Challenge 1: Proper name of the project

If you don’t follow the naming conventions and don’t write a proper project ID, you may see the following errors:

  1. If you write a project ID with spaces or underscores, like “app engine and cloud run” or “appengineandcloudrun”, it will show the error:
text
(gcloud.projects.create) argument PROJECT_ID: Bad value [app]: Project IDs are immutable and can be set only during project creation. They must start with a lowercase letter and can have lowercase ASCII letters, digits or hyphens. Project IDs must be between 6 and 30 characters.
Google Cloud Platform-App Engine-Cloud Run
  1. If you enter a name like “app-engine-and-cloud-run”, you will get the error message:
text
(gcloud.projects.create) INVALID_ARGUMENT: field [project_id] has issue [project_id contains prohibited words]  
- '@type': type.googleapis.comgoogle.rpc.BadRequest  
  fieldViolations:  
  - description: project_id contains prohibited words  
    field: project_id
Google Cloud Platform-App Engine-Cloud Run
  1. By chance, if you write a project ID that is already used for some other project in the cloud, then you will again get an error.
text
Command:

C:\Users\Bugsmirror\AppData\Local\Google\Cloud SDK> gcloud projects create test-project-123

Error:  
(gcloud.projects.create) Project creation failed. The project ID you specified is already in use by another project. Please try an alternative ID.
Google Cloud Platform-App Engine-Cloud Run

Solution:

Do this to overcome all the challenges in naming a project-

  1. Strictly follow the project naming convention: Project IDs must be 6 to 30 characters (lowercase ASCII, digits, or hyphens) in length and start with a lowercase letter.
  2. Also keep in mind that the project ID should be unique.
    Google Cloud Platform-App Engine-Cloud Run
    Create a project with a proper ID using the command:
text
gcloud projects create <PROPER_PROJECT_ID>

Challenge 2: Terms of service

When you proceed further, you will encounter an error asking you to accept ‘Terms of Service’ of the Google Cloud Platform:

text
(gcloud.projects.create) Operation [cp.6426358016269875409] failed: 9: Callers must accept Terms of Service
Google Cloud Platform-App Engine-Cloud Run

Solution:

Go to this link to accept ‘Terms of Service’ and then you can proceed further: https://console.cloud.google.com/terms/universal

Google Cloud Platform-App Engine-Cloud Run
After accepting the Terms of Service, once again write the command for creating the project and this time it will be created. To verify that the project is created, enter the command:
gcloud projects list It will show the list of projects created by you.
Google Cloud Platform-App Engine-Cloud Run
Then, set the project using the command:

text
gcloud config set project <PROJECT_ID>

Google Cloud Platform-App Engine-Cloud Run
Now that you have completed the above steps, let us separately understand how to deploy a project on App Engine and Google Run by deploying parts of sample projects taken from GitHub in our project.

APP ENGINE

You can find a few sample projects in the link below that you can deploy on the Google Cloud Platform: Sample Applications | App Engine standard environment for Python 2 | Google Cloud I took a sample project created in the Python language. Write the following command to deploy the project:

text
gcloud app deploy <PATH_OF_YAML_FILE>

Select the region (prompted only if it is not set) where you want your App Engine to be located as per your requirement, by entering the number corresponding to it.

Google Cloud Platform-App Engine-Cloud Run
Then the App Engine application will be created in the project.
Google Cloud Platform-App Engine-Cloud Run
Press ‘Y’ to continue.

Challenge 3: Billing account

As you proceed further, you will get a warning message and an error in deploying the project:

text
(gcloud.app.deploy) Error Response: [7] Access Not Configured. Cloud Build has not been used in project mydemotes-project17 before or it is disabled. Enable it by visiting https:console.developers.google.comapisapicloudbuild.googleapis.comoverview?project=projectname then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.

Google Cloud Platform-App Engine-Cloud Run
Google Cloud Platform-App Engine-Cloud Run
The warning and error are generated as your billing account for Google Cloud is not set up yet. You will find the solution of this error towards the end of the blog. Keep reading!
Assuming you have resolved the error, you can use the following command to see the list of installed components:

text
gcloud components list

Google Cloud Platform-App Engine-Cloud Run
Depending on the project’s tech stack, install the required component. For example, for a project created in Go language, use the following command:

text
gcloud components instalapp-engine-go 

Then rewrite the command to deploy the project, as mentioned earlier.

Challenge 4: Bugs in the project source code

When you try to deploy your project, the code is first compiled and you might see errors in your GCP console. These errors are bugs in the code of the project.

Solution:

Fix the bugs in the project code and re-run the deploy command. Congrats! Your project is deployed on App Engine. A link to view the deployed project will be generated. Further, you can monitor your project using the App Engine Console.

CLOUD RUN

You can take a sample project to deploy on the Cloud Run from this link: Sample projects I took a sample project created in the Go language. Go to the source code directory and deploy the project using the command:

text
gcloud beta run deploy —-project <PROJECT-ID> —-use-http2 —-source .

Challenge 5: Billing account

As you proceed further, you will face the following error in deploying the project:

text
(gcloud.beta.run.deploy) FAILED_PRECONDITION: Billing account for project ‘326878803069’ is not found. Billing must be enabled for activation of service(s) ‘run.googleapis.com,containerregistry.googleapis.com’ to proceed.

Google Cloud Platform-App Engine-Cloud Run
This error is generated as your billing account for Google Cloud is not set up yet. You will find the solution of this error towards the end of the blog. Keep reading! (Again assuming that you have resolved the error, let us move further!)

Challenge 6: Bugs in the project source code

When you try to deploy your project, the code is first compiled and you may see errors in your GCP console. These errors are bugs in the code of the project.

Solution:

Fix the bugs in the project code and re-run the deploy command. Congrats! Your project is deployed on Cloud Run. A link to view the deployed project will be generated. Further, you can monitor your project using the Cloud Run Console.

$300 in credit is free for you from Google Cloud!

So, now it's time to resolve the billing issue! To overcome the billing account challenge, visit this link and configure your billing details: https://console.cloud.google.com/apis/library/cloudbuild.googleapis.com?project=<PROJECT_ID>

Google Cloud Platform-App Engine-Cloud Run
Google provides 300$ credit for free to new users for deploying their apps, websites, etc., on their cloud platforms like App Engine and Cloud Run. You can use the credit within 90 days of the free triaperiod. And after that, you won’t be charged unless you upgrade your account for automatic billing. App Engine and Cloud Run platforms also provide resources for free usage up to a certain limit.
Set up your billing account by following these steps:

  1. Click ‘ENABLE’.
  2. Click ‘ENABLE BILLING’.
    Google Cloud Platform-App Engine-Cloud Run
  3. Click ‘CREATE BILLING ACCOUNT’.
    Google Cloud Platform-App Engine-Cloud Run
  4. Enter the required details, check the ‘Terms of Service’ and click ‘CONTINUE’.
    Google Cloud Platform-App Engine-Cloud Run
  5. Change the ‘Account Type’ to ‘Individual’.
    Google Cloud Platform-App Engine-Cloud Run
  6. Enter Mastercard or VISA card details (you won't be charged unless you turn on automatic billing.) Then enter your address details.
    • Under ‘Tax information’ select ‘Unregistered individual’.
    • Click on ‘START MY FREE TRIAL’.
      Google Cloud Platform-App Engine-Cloud Run
  7. To verify your card, enter the required details and click ‘Continue’. To complete the transaction, click ‘Continue’ again.
    Google Cloud Platform-App Engine-Cloud Run
  8. You will be redirected to a new window and will be charged INR 2 from your card. But you don’t need to worry at all, as the amount will be refunded from Google. This deduction is made to check if you have entered a valid card number.
    Google Cloud Platform-App Engine-Cloud Run
  9. Further, click ‘Proceed to verification’ and enter the required information to verify your payment details.
  10. Finally, you will be redirected to the GCP page. Answer the questions asked and you are done. You can go back to the URL (https://console.cloud.google.com/apis/library/cloudbuild.googleapis.com?project=<PROJECT_ID>) to enable the Cloud Build API.

To learn about the common deployment errors in App Engine and Cloud Run, you can read the links below (you must have already read about other errors and issues described above in this blog post):

Bugsmirror team has successfully hosted the company’s website on the App Engine. Some of Bugsmirror’s other projects have been hosted on Cloud Run. By following the process explained in this blog post, you can deploy any app or project developed in various programming languages on App Engine as well as Cloud Run.
I hope that developers find this blog post useful. In the third and final part of this blog series, I will describe the challenges you may face after deploying the app on App Engine and Cloud Run in detail and provide solutions to overcome those challenges. Bugsmirror team will keep publishing more such blog posts to help the developer community and also provide curious readers with informative articles to read.

Share this article

Help others discover this content

Don’t give fraud a way in. Secure every layer of your mobile app.

100M+

Users Protected

100+

Apps Secured

1000+

Apps Hardened

Emulator detected
Session blocked