How to Automate a GCP Deploy by GitHub New Tag

Automating deployments can significantly improve the speed and reliability of delivering your applications. In this article, I’ll share how I configured Google Cloud Platform (GCP) to automatically deploy my app whenever a new GitHub tag is pushed. Using regex, we’ll redirect each pattern to the appropriate environment, ensuring a seamless and organized workflow.


Creating an Environment in Google Cloud Run

To set up an environment in Google Cloud Run, follow these steps:

  1. Open the Google Cloud Console and navigate to Cloud Run.
  2. Select Connect repository, then click Set up with Cloud Build. This links your GitHub repository to GCP, enabling automated builds and deployments.


Creating a GCP Trigger

Triggers in GCP allow you to define automated actions based on specific events. Here’s how you create one for new GitHub tags:

  1. Go to Cloud Build Triggers in the Google Cloud Console.
  2. Click Create Trigger and configure the following:Event: Select "Push to a new tag."Regex pattern: Define regex patterns to match your tag names:

For staging (testing environment), use ^\d+\.\d+\.\d+-.*, which matches tags like 0.0.0-20241112-update or 1.1.0-rc.1.

For production, use ^\d+\.\d+\.\d+$, which matches tags like 1.0.0, 1.0.1, or 1.1.0.Build configuration: Set the build steps, such as containerizing the application or deploying it to Cloud Run.

The tagging follows the Semantic Versioning (SemVer) standard, which organizes versions into major, minor, and patch levels (e.g., 1.0.0). The addition of suffixes like -rc.1 or -<date>-update helps manage pre-release versions for staging.


Creating a New Tag

To test your setup, create a new tag in your GitHub repository:

Open your terminal and navigate to the repository:

git tag v1.0.0
git push origin v1.0.0        

For a staging environment, you could create:

git tag 1.1.0-rc.1
git push origin 1.1.0-rc.1        

Once the tag is pushed, the trigger will activate, deploying your app to the corresponding environment based on the regex.


Mauro Marins

Senior .NET Software Engineer | Senior Full Stack Developer | C# | .Net Framework | Azure | React | SQL | Microservices

3 个月

Great content, thanks for sharing!

回复
Pedro Constantino

.NET Software Engineer | Full Stack Developer | C# | Angular | AWS | Blazor

3 个月

Very informative, thanks for sharing!

回复
Alex Solidade

Data Analyst & Insights Specialist | SQL & Database Expert | Power BI Specialist | DBA

3 个月

Very good, congratulations Silvio Ubaldino

回复

Great tips, thanks!!

回复

要查看或添加评论,请登录

Silvio Ubaldino的更多文章

社区洞察

其他会员也浏览了