CI/CD Pipeline for Automated Deployments in Google Cloud

CI/CD is the combined practices of continuous integration (CI) and either continuous and continuous deployment (CD). CI/CD is designed to bridge the gap between development and operation activities and teams by enforcing automation in building, testing and deployment of applications. Modern day DevOps practices involve continuous development, continuous testing, continuous integration, continuous deployment and continuous monitoring of software applications throughout its development life cycle. The CI/CD pipeline forms the backbone of modern day DevOps operations.

The main goal of this automation pipeline within your business is to be able to deploy your application into different environments such as Dev/QA/Production without manual intervention. This automation reduces the risk of errors during deploying, reduces the number of hours for deploying code changes in multiple environments, and helps to deploy the changes more frequently in development and QA environments as soon as possible after changes are made. The methods a CI/CD pipline allows you to apply are:

  • Version control of source code.
  • Automatic building, testing, and deployment of apps.
  • Environment isolation and separation from production.
  • Replicable procedures for environment setup.

Creating a CI/CD Pipeline on Google Cloud

Let’s look at how you can set up a continuous integration/continuous deployment (CI/CD) pipeline for processing data by implementing CI/CD methods with managed products on Google Cloud. The Google Cloud tools we will to build the pipeline is Google Cloud Build. A typical CI/CD setup will look like:

First, the developer checks in the source code into GitHub (any Version Control System is ok). Next, GitHub triggers a post-commit hook to a Cloud Build. The Cloud Build then builds the container imager and pushes it to the Container Registry. Cloud Run is then notified to redeploy and Cloud Run pulls the latest image from Container Registry and runs it.

To build a simple pipeline in Google Cloud using Cloud Run, we will go through the high level steps.

  1. Create a Dockerfile with the necessary steps to build your container image, such as line that might install Tomcat: “RUN wget” and pulls the source code for the application from your git repo.
  2. Create a gcpbuild.YAML file that will build the docker image in GCP, push the container image into the Google Cloud Registry and then Deploy the image to Google Cloud Run.
  3. Go to Cloud Build and connect your Git Repository first.
  4. Now, create a Trigger
  5. Ensure Cloud Build has access to deploy to Cloud Run. For that go to settings and Enable the service account permission for Cloud Run.

Test Your CI / CD Pipeline

Now you are ready to test. Make a small change to your code and push it to your repository. This should trigger the cloud build:

After a little while, you’ll see your new container listed in Cloud Build:

And you should finally be able to see your new service deployed in Google Cloud Run:

That’s it! You have setup a simple CI/CD Pipeline for automation in Google Cloud!

Leave a Comment