5

How I automated my CI/CD pipeline with Google Cloud Run, Cloud Build and GitHub.

 3 years ago
source link: https://myvirtualcloud.net/how-i-automated-my-ci-cd-pipeline-with-google-cloud-run-cloud-build-and-github/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

How I automated my CI/CD pipeline with Google Cloud Run, Cloud Build and GitHub.

  • 01/19/2021

In case you are not aware, I develop and host a free widely used tool for sizing VDI deployments and also a few other tools. I have been developing for many years. Still, recently after migrating to Google Cloud, GoLang, and Docker containers, I have achieved what I consider to be a very automated and streamlined CI/CD pipeline that is extremely simple for anyone to implement for their projects.

For this example, I use:

  • GitHub
  • Google Cloud Build
  • Google Cloud Run (This is a fully encapsulated service built on Knative that allows me to write code (Go, Python, Java, Ruby, Node.js, and more) while the service abstract away all infrastructure management)
  • Go Language

It starts with a Dockerfile containing all the commands to assemble a new Docker image and a GitHub account that can be public or private. All you have to do is to check-in all your code along with the Dockerfile into your GitHub repository.

.Dockerfile

Then in Google Cloud Build, you will connect your GCP account to your GitHub repository under the Trigger option and then create a trigger Creating a Trigger is simple, and in my case, I let Google Cloud build a new container every time I push new code to the ‘master’ branch, but you can also select tags as an option, such as ‘latest.’

I use a an in-line build configuration because I need to configure a few environmental parameters, but you can select ‘autodetect,’ and Google Cloud Build will use the Dockerfile from the repository.

Now, when a new commit is pushed to the GitHub repository Google Cloud Build will automatically detect and a new container image is created and instantiated in Cloud Run (make sure you create a service in Cloud Run first by selecting it on the Google Cloud Platform dashboard). Google Cloud Run will keep all container revisions, and you can roll back to any point in time if something is not working correctly.

If you are familiar with Kubernetes, you won’t need to touch YAML files anymore unless you need a very specific configuration, but for the most part, Google Cloud Run will handle it.

Finally, Google Cloud Run will also provide you with all service statistics and automatically log errors and faults related to the container and your code.

To summarize, in approximately 5 minutes after checking in my code, I have a new docker image based on my Dockerfile configuration and a new container instance up and running on Google Cloud without having to touch any Kubernetes or Anthos infrastructure. You can even provide advanced configuration with a little work, but even automated container scalability is baked into Cloud Run.

There you go, I have not touched the infrastructure in months, and I can focus on my code.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK