Google Run

Google Run offers a serverless container approach to deploying microservices without the need to use Kubernetes, allowing you to accelerate the publishing of microservices based on the Devprime platform.

Introduction

The Devprime platform accelerates software developer productivity by offering a complete software architecture design, components with intelligent behaviors, accelerators for code deployment, and updates with new features.

In this article, we’ll cover the use of Google Run, a platform for serverless containers based on the Google Cloud stack. Implementing this scenario will use a microservice based on the Devprime platform. This microservice will be linked to an active Google Cloud account, with a project containing a Stream built on Google Pub/Sub, a database on Google Cloud SQL (compatible with MySQL, PostgreSQL, and SQL Server), a repository on Google Artifact Registry, and a new service on Google Run.

During this article, we’ll use a microservice with an order-related business rule, and the PostgreSQL database will be integrated with a queue created in Google Pub/Sub. We’ll walk you through the steps to build the microservice, and then we’ll cover the settings you need to make it available in Google Run.

Google Run

Cheklist and preperation of the initial environment:

  • Open an account on Devprime Platform and purchase a Developer/Enterprise) license.
  • Install an updated version of .NET (Linux, macOS, and Windows)
  • Install and/or update Visual Studio Code and/or Visual Studio 2023 Community / Professional / Enterprise.
  • Install and/or update docker (For Windows, use WSL2).
  • Install Powershell or use Bash on Linux
  • Install and activate the latest version of the Devprime CLI.
  • Create a folder for your projects and set read and write permissions.
  • See the article “Creating the first microservice” to explore getting started with the Devprime platform.

Google Cloud Checklist

Creating a new microservice

  • Building the first microservice
    dp new ms-order --stream googlepubsub --state postgresql
  • Adding a sample business rule
    dp marketplace order
  • Initializing and accelerating microservice deployments
    dp init

At this point, the microservice intended for this example is ready for use in production, and it is possible to run it locally. The next step is to add your Google Cloud credentials to your microservice.

Adding credentials in the microservice
This microservice will use the credentials to access Google PubSub and Google Cloud SQL and must be reported in the configuration file src/App/appsettings.json as defined in the Stream Adapter with Google PubSub and State Adapter with PostgreSQL.

Open in Visual Studio Code
code src/App/appsettings.json

  • Locate the Ed Stream Adapter settings and include the credentials obtained
    in JSON
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
"DevPrime_Stream": [
    {
      "Alias": "Stream1",
      "Enable": "true",
      "Default": "true",
      "StreamType": "GooglePubSub",
      "Project_ID": "",
      "Private_Key_ID": "",
      "Private_Key": "",
      "Client_Email": "",
      "Client_ID": "",
      "Auth_URI": "",
      "Token_URI": "",
      "Auth_Provider_x509_Cert_Url": "",
      "Client_X509_Cert_Url": "",
      "Retry": "3",
      "Fallback": "State1",
      "Threads": "10",
      "Subscribe": []
    }
  ],
  • Locate the State Adapter key and enter the Google Cloud SQL access credentials
    such as the IP address to be entered in the Host, username and password.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
"DevPrime_State": [
    {
      "enable": "true",
      "alias": "State1",
      "dbtype": "postgresql",
      "type" : "db",
      "connection": "Host=localhost;Username=postgres;Password=LltF8Nx*yo;Database=ms-order",
      "timeout": "5",
      "retry": "2",
      "durationofbreak": "45"
    }
  ],

Applying Database Structure
The database in this scenario is PostgreSQL, and before running the microservice, it is critical to run a script to create the tables in the database that are required by the microservice. You can use the Devprime CLI tool to generate the SQL files and apply them manually or apply them directly to the database.

Run the command to apply to the database.
dp state apply state1

Exporting Settings for Publishing to Google Run
The Devprime CLI provides a utility to make it easier to create a script to publish the microservice’s docker image to the private Google Artifact Registry repository and then create a new service in Google Run.

Run the export command
dp export googlerun

After exporting, two files (Powershell or Bash) will be created that contain the script to run the publish to Google Cloud.

Choose your preferred file and edit it using Visual Studio Code, changing the initial settings such as Google Cloud project name, application name, and repository.

Open from Visual Studio Code

  • code .devprime/google/googlerun.ps1
  • code .devprime/google/googlerun.sh

Running the script
Before you run the script, make sure that docker is running in your environment, that you’re logged into it, and that the Google Cloud CLI is installed and active. The script must be run from the root directory of the project.

Run one of the commands:

  • .\.devprime\google\googlerun.ps1 (Windows)
  • .devprime/google/googlerun.sh (MacOS and Linux)

Final Thoughts

In this example, you can see how easy it is to develop a new microservice using the Devprime platform and its accelerators, followed by the process of publishing it to Google Cloud in a matter of seconds.

  • Replace this script with a DevOps process by automating the procedure.
  • In the production environment, implement security measures such as an API Gateway and a vault for secure credential storage.
  • Adopt the procedures by isolating the network to export only the public services.
Last modified April 16, 2024 (2b35fcc8)